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

Use MADV_FREE on linux kernel >= 4.5 #387

Closed
rajatgoel opened this issue May 20, 2016 · 5 comments
Closed

Use MADV_FREE on linux kernel >= 4.5 #387

rajatgoel opened this issue May 20, 2016 · 5 comments

Comments

@rajatgoel
Copy link
Contributor

Maybe a new configure option to enable/disable this at compile time for linux?

@jasone jasone added this to the 5.0.0 milestone May 20, 2016
@djwatson
Copy link
Member

Last I tested MADV_FREE doesn't work correctly on swapless systems yet (changes still in review -https://lkml.org/lkml/2015/11/24/753). So probably can't be be the default yet and needs to be an option

@jasone
Copy link
Member

jasone commented Nov 17, 2016

It looks like the current state of affairs is that MADV_FREE is equivalent to MADV_DONTNEED on swapless systems, so I think it's okay to use, even if currently a minor pessimization since we won't recognized the pages as being zeroed upon reuse.

@jasone jasone closed this as completed in a64123c Nov 17, 2016
@jasone jasone modified the milestones: 4.4.0, 5.0.0 Nov 17, 2016
@jasone jasone reopened this Nov 17, 2016
jasone added a commit that referenced this issue Nov 17, 2016
Add feature tests for the MADV_FREE and MADV_DONTNEED flags to
madvise(2), so that MADV_FREE is detected and used for Linux kernel
versions 4.5 and newer.  Refactor pages_purge() so that on systems which
support both flags, MADV_FREE is preferred over MADV_DONTNEED.

This resolves #387.
@jasone jasone closed this as completed Nov 17, 2016
@madscientist
Copy link
Contributor

Maybe it's just me but I'm leery of configure-time checks for things like this. What happens if I build this on a system where it's available but then run it on a system where it isn't? Maybe this is a spurious concern.

@jasone
Copy link
Member

jasone commented Nov 17, 2016

Yeah, cross compiling of any form is in general a dangerous business, and this particular configuration test is a bit more fragile than most because we tend to think of systems with merely different kernel versions as equivalent targets. That said, I want to support MADV_FREE on Linux, but I don't want to saddle us with a compatibility quagmire or explicit configuration control. What we have here is a forward-compatible approach, with an escape hatch (--config autoconf cache file) to enable backward compatibility for people who are actually cross-compiling from newer systems to older ones.

@nh2
Copy link

nh2 commented Dec 2, 2018

It looks like the current state of affairs is that MADV_FREE is equivalent to MADV_DONTNEED on swapless systems

@jasone @djwatson This is no longer the case, see

https://www.spinics.net/lists/linux-mm/msg167333.html

MADV_FREE now always returns memory to the operating systems "lazily" (on memory pressure).

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

No branches or pull requests

5 participants