Skip to content

Commit

Permalink
Include buffer/cache memory as free memory on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-decker committed Mar 10, 2022
1 parent 7b4eea6 commit 003e56d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion memory_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package memory
Expand Down Expand Up @@ -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)
}

0 comments on commit 003e56d

Please sign in to comment.