From 003e56da73e33f88ba53802c88fe124498f9a39c Mon Sep 17 00:00:00 2001 From: Dustin Decker Date: Thu, 10 Mar 2022 10:05:06 -0800 Subject: [PATCH] Include buffer/cache memory as free memory on linux --- memory_linux.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/memory_linux.go b/memory_linux.go index 3d07711..136353e 100644 --- a/memory_linux.go +++ b/memory_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package memory @@ -25,5 +26,9 @@ func sysFreeMemory() uint64 { // If this is a 32-bit system, then these fields are // uint32 instead of uint64. // So we always convert to uint64 to match signature. - return uint64(in.Freeram) * uint64(in.Unit) + // Buffer/cache ram is included on linux since the kernel + // will free this memory for applications if needed, and tends + // to use almost all free memory for itself when it can. + // https://pkg.go.dev/syscall#Sysinfo_t + return (uint64(in.Freeram) + uint64(in.Bufferram)) * uint64(in.Unit) }