Bug 77141 - MemFree can be higher than MemAvailable
Summary: MemFree can be higher than MemAvailable
Status: RESOLVED INVALID
Alias: None
Product: Memory Management
Classification: Unclassified
Component: Other (show other bugs)
Hardware: x86-64 Linux
: P1 normal
Assignee: Andrew Morton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-29 19:43 UTC by sworddragon2
Modified: 2014-06-21 04:15 UTC (History)
1 user (show)

See Also:
Kernel Version: 3.15.0-rc7
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description sworddragon2 2014-05-29 19:43:57 UTC
I have seen the commit about MemAvailable ( https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 ) and have made some tests with it. From the description MemAvailable should be MemFree with adding the parts of the cache, etc. which are claimable which also means that MemAvailable should always be higher than MemFree. Here is how it normally looks:

root@ubuntu:~# cat /proc/meminfo | grep -E 'MemFree|MemAvailable|Buffers|^Cached|file|SReclaimable'
MemFree:        14949536 kB
MemAvailable:   15519900 kB
Buffers:          194092 kB
Cached:           344588 kB
Active(file):     207768 kB
Inactive(file):   328528 kB
SReclaimable:     287484 kB


But in some cases after dropping the cache and checking /proc/meminfo MemAvailable is lower than MemFree which seems to be impossible:

root@ubuntu:~# echo 3 > /proc/sys/vm/drop_caches
root@ubuntu:~# cat /proc/meminfo | grep -E 'MemFree|MemAvailable|Buffers|^Cached|file|SReclaimable'
MemFree:        15660144 kB
MemAvailable:   15643972 kB
Buffers:             876 kB
Cached:           124020 kB
Active(file):      22328 kB
Inactive(file):   100060 kB
SReclaimable:      14208 kB
Comment 1 Rik van Riel 2014-06-21 00:07:13 UTC
Not all free memory is available to userspace allocations. Below a certain threshold only the kernel is allowed to do memory allocations, and allocations below that threshold will drive the system to swapping.

In /proc/zoneinfo you can see the different free watermarks for your system. On my system it looks like this:

Node 0, zone      DMA
  pages free     3970
        min      10
        low      12
        high     15

Node 0, zone    DMA32
  pages free     70301
        min      2443
        low      3053
        high     3664

Node 0, zone    DMA32
  pages free     70301
        min      2443
        low      3053
        high     3664

The MemAvailable number only goes down to the low watermark at most, since allocations below that will cause swapping.

If you add the sum of the low watermarks to MemAvailable, you should get a value larger than MemFree.
Comment 2 Rik van Riel 2014-06-21 00:13:22 UTC
Btw, the numbers in /proc/zoneinfo are in pages, so you need to multiply them by 4 to get kilobytes.
Comment 3 sworddragon2 2014-06-21 00:18:46 UTC
If I'm understanding this correctly that means MemAvailable should be taken literally: It shows how many memory is available but it isn't suitable to calculate how many memory is already in use due to the threshold (basically MemTotal - MemAvailable would be wrong).
Comment 4 Rik van Riel 2014-06-21 02:37:05 UTC
Indeed, MemAvailable is an estimate of how much memory you can allocate without the system going into swap.

It is (free memory - system reserve) + (part of page cache) + (part of buffer cache) + (part of reclaimable slab)
Comment 5 sworddragon2 2014-06-21 04:15:43 UTC
Thanks for the explanation, I'm marking this ticket as invalid then.

Note You need to log in before you can comment on or make changes to this bug.