| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_OS_MEM_AVAILABLE_H |
| 4 | #define NETDATA_OS_MEM_AVAILABLE_H |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | |
| 8 | typedef struct { |
| 9 | // ram_total_bytes is the total memory available in the system |
| 10 | // and it includes all the physical RAM the system may have. |
| 11 | // It does not include non-RAM memory (i.e. SWAP in not included). |
| 12 | // ram_total_bytes may be cached between calls to these functions |
| 13 | // (i.e. it may not be as up to date as ram_available_bytes). |
| 14 | uint64_t ram_total_bytes; |
| 15 | |
| 16 | // ram_available_bytes is the total RAM memory available for |
| 17 | // applications, before the system and its applications run |
| 18 | // out-of-memory. This is always provided live by querying the system. |
| 19 | // It does not include non-RAM memory (i.e. SWAP in not included). |
| 20 | uint64_t ram_available_bytes; |
| 21 | } OS_SYSTEM_MEMORY; |
| 22 | |
| 23 | #define OS_SYSTEM_MEMORY_OK(mem) ((mem).ram_total_bytes > 0) |
| 24 | #define OS_SYSTEM_MEMORY_EMPTY (OS_SYSTEM_MEMORY){ 0 } |
| 25 | |
| 26 | // The function to get current system memory: |
| 27 | OS_SYSTEM_MEMORY os_system_memory(bool query_total_ram); |
| 28 | |
| 29 | // Returns the last successfully reported os_system_memory() value. |
| 30 | OS_SYSTEM_MEMORY os_last_reported_system_memory(void); |
| 31 | |
| 32 | double os_system_memory_available_percent(OS_SYSTEM_MEMORY mem); |
| 33 | |
| 34 | #endif //NETDATA_OS_MEM_AVAILABLE_H |