Skip to content

Conversation

holocronweaver
Copy link

MemAvailable was recently introduced into the Linux kernel to simplify
estimating the amount of "memory available for starting new
applications, without swapping." This way user applications no longer
have to know how the kernel internally handles memory.

The previous way of calculating available memory produced erroneously large usages on Ubuntu 15.04. Ex, it indicated 42% usage when 36% was correct. (And this was only after I adjusted the code to skip the new MemAvailable entry - otherwise the wrong info is read from meminfo.) Using MemAvailable fixes the problem and agrees roughly with system monitor.

I am not sure which Linux kernel first introduced MemAvailable, but here is the relevant commit.

MemAvailable was recently introduced into the Linux kernel to simplify
estimating the amount of "memory available for starting new
applications, without swapping." This way user applications no longer
have to know how the kernel internally handles memory.
@fossfreedom
Copy link
Owner

thanks for this.

I had a quick check with Ubuntu 14.04 kernel 3.13 (which is the default)

pic

as you can see - running "top" doesnt agree with the value being reported in the indicator.

With the original master branch version it is correct.

Note - I used the following to clear down memory:

  • sudo sysctl -w vm.drop_caches=3

or similar:

  •  sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
    

@holocronweaver
Copy link
Author

What does the top of your /proc/meminfo look like? Is MemAvailable there? This is what it looks like in 15.04:

MemTotal:        8152716 kB
MemFree:         1072200 kB
MemAvailable:    4749332 kB
Buffers:          452056 kB
Cached:          3053028 kB
SwapCached:            0 kB
Active:          4452932 kB
Inactive:        1710028 kB
Active(anon):    2659024 kB
Inactive(anon):    12572 kB
Active(file):    1793908 kB
Inactive(file):  1697456 kB
Unevictable:          64 kB
Mlocked:              64 kB
SwapTotal:             0 kB
SwapFree:              0 kB

@fossfreedom
Copy link
Owner

MemTotal:        2042908 kB
MemFree:           82460 kB
Buffers:           69160 kB
Cached:           886992 kB
SwapCached:            0 kB
Active:          1215932 kB
Inactive:         526216 kB
Active(anon):     786108 kB
Inactive(anon):     3684 kB
Active(file):     429824 kB
Inactive(file):   522532 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty

with the original reporting 54% and yours reporting 94%

@fossfreedom
Copy link
Owner

possibly will need a kernel check in the code - maybe run your check from kernel 3.16 and above ?

@holocronweaver
Copy link
Author

Sounds like a good idea. I guess we could parse uname -r to obtain kernel version, or is there a more robust way?

Edit: I guess platform.release() will work.

@fossfreedom
Copy link
Owner

yep - platform.release() would work. Maybe some like this to extract the float part of the string?

@holocronweaver
Copy link
Author

I think my latest commit should take care of it.

fossfreedom added a commit that referenced this pull request Apr 11, 2015
Use MemAvailable in /proc/meminfo for memory available to user.
@fossfreedom fossfreedom merged commit 5a77463 into fossfreedom:master Apr 11, 2015
@fossfreedom
Copy link
Owner

thanks. I'll upload this into my PPA for 15.04 users later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants