Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease memory usage with mlockall(MCL_ONFAULT) #112

Closed
hakavlad opened this issue Feb 11, 2019 · 1 comment
Closed

Decrease memory usage with mlockall(MCL_ONFAULT) #112

hakavlad opened this issue Feb 11, 2019 · 1 comment

Comments

@hakavlad
Copy link
Contributor

MCL_ONFAULT (since Linux 4.4)
    Used together with MCL_CURRENT, MCL_FUTURE, or both. Mark all current (with MCL_CURRENT) or future (with MCL_FUTURE) mappings to lock pages when they are faulted in. When used with MCL_CURRENT, all present pages are locked, but mlockall() will not fault in non-present pages. When used with MCL_FUTURE, all future mappings will be marked to lock pages when they are faulted in, but they will not be populated by the lock when the mapping is created. MCL_ONFAULT must be used with either MCL_CURRENT or MCL_FUTURE or both. 

Earlyoom will use 0.7 MiB RSS instead of 2.0 MiB if you use mlockall(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT).

See also golang/go#28114

Status with MCL_ONFAULT

Name:	earlyoom
...
VmPeak:	    4240 kB
VmSize:	    4232 kB
VmLck:	    4216 kB
VmPin:	       0 kB
VmHWM:	     684 kB
VmRSS:	     684 kB
RssAnon:	      68 kB
RssFile:	     592 kB
RssShmem:	      24 kB

Code:

    if (mlockall(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT) != 0)
        if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) // for old kernels
            perror("Could not lock memory - continuing anyway");
rfjakob added a commit that referenced this issue Feb 11, 2019
Nice saving:

Before: VmRSS:	    2196 kB
After:  VmRSS:	     696 kB

Thanks to @hakavlad for the suggestion at
#112 !
@rfjakob
Copy link
Owner

rfjakob commented Feb 11, 2019

Very nice. Added in commit 319e959, thanks!

@rfjakob rfjakob closed this as completed Feb 11, 2019
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

No branches or pull requests

2 participants