CodePark/ questions / Memory, stack & heap
START PRACTICINGPRACTICE
Backend question · OS, networking & Linux › Memory, stack & heap

On a 16 GB server, free -h shows the output below. Is the machine short of memory?

               total        used        free      shared  buff/cache   available
Mem:            15Gi       4.1Gi       312Mi       120Mi        10Gi        10Gi
Swap:          2.0Gi          0B       2.0Gi
No. Most memory is page cache that the kernel gives back on demand, and available estimates about 10 GB for new allocations

No. Most of the memory is page cache, and available shows about 10 GB is ready for new allocations. Linux fills RAM that would sit idle with cached file data. When applications need memory, the kernel takes that cache back.

The
free column shows memory that does nothing at all, so a low value is normal. The available column is the kernel's estimate of how much memory programs can allocate without swapping. This is the number to watch.

"Only 312 MB is free, so the next large allocation will trigger the OOM killer" is wrong, because the kernel frees cache before it ever needs the OOM killer.