Skip to content

Commit

Permalink
Fix linux filesystem cache calculation hyperic#73
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhanyin committed Aug 28, 2024
1 parent e1f85fd commit 7b71b92
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/os/linux/linux_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static SIGAR_INLINE sigar_uint64_t sigar_meminfo(char *buffer,

int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
{
sigar_uint64_t buffers, cached, kern;
sigar_uint64_t kern = 0;
char buffer[BUFSIZ];

int status = sigar_file2str(PROC_MEMINFO,
Expand All @@ -336,10 +336,11 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->free = sigar_meminfo(buffer, MEMINFO_PARAM("MemFree"));
mem->used = mem->total - mem->free;

buffers = sigar_meminfo(buffer, MEMINFO_PARAM("Buffers"));
cached = sigar_meminfo(buffer, MEMINFO_PARAM("Cached"));
/* Filesystem cache; the 'Cached' item includes swap-backed shmem */
kern += sigar_meminfo(buffer, MEMINFO_PARAM("Active(file)"));
kern += sigar_meminfo(buffer, MEMINFO_PARAM("Inactive(file)"));
kern += sigar_meminfo(buffer, MEMINFO_PARAM("SReclaimable"));

kern = buffers + cached;
mem->actual_free = mem->free + kern;
mem->actual_used = mem->used - kern;

Expand Down

0 comments on commit 7b71b92

Please sign in to comment.