Runbook / runbook

Infrastructure monitoring with automated remediation
https://runbook.io
Apache License 2.0
193 stars 55 forks source link

free memory #415

Open 1337newbee opened 8 years ago

1337newbee commented 8 years ago

Linux Memory Calculation

                free_mem = (memstats['MemFree'] - memstats['Buffers']) + memstats['Cached']

Isn't free memory calculated as below?

free-mem=(memstats['MemFree'] - memstats['Buffers']) - memstats['Cached']

madflojo commented 8 years ago

Actually it's Free + Buffers + Cached not sure what I was thinking of with the - Buffers.

$ free -m
             total       used       free     shared    buffers     cached
Mem:          5962       5174        788          0         62       2370
-/+ buffers/cache:       2740       3222
Swap:        16383       3840      12543

If you look at the above it shows on the second line 3222 which is 788 + 62 + 2370 (giving a little leeway for rounding). Basically the way it works is this, when Linux has memory to spare it uses it for caching filesystem contents and frequently accessed data. When the free (non-cached) memory starts to go below the vm.min_free_kbytes tunable the Kernel will start deallocating the cache and using the freed up memory.

Thanks for calling this out not sure why I put a - there I totally should know better.

1337newbee commented 8 years ago

I agree. It should be free+Buffers+Cached - Check this documentation from Redhat https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/chap-Oracle_9i_and_10g_Tuning_Guide-Memory_Usage_and_Page_Cache.html