Pre-populating anonymous pages

By: Jeff S. (, June 5, 2019 7:03 pm
Room: Moderated Discussions
Travis Downs ( on June 5, 2019 4:48 pm wrote:
> On Linux, given a mapped-but-probably-not-populated anonymous region
> of memory, is there any way to ask the kernel to populate it?

> The usual approach is just to write to it, but on x86 you take a fault for every 4k page - and
> thanks to our friends Spectre and Meltdown this hurts a lot more than it used to. I know I'm about
> to write to all this memory, so I'd like to just populate the entire region right now.

> If I were allocating the memory myself with mmap, the solution is just to pass MAP_POPULATE
> to mmap. However, there are scenarios were I'm not allocating the memory, can I can't control
> the caller, but I'd like to populate all the pages after the initial allocation.

> One dirty hack is back-to-back mlock()/munlock() on the region, but this does way more work than
> is necessary (all the munlock() is wasted, and anything mlock() does other than filling the PTEs
> is wasted as well). Moreover, it isn't work for non-privledged processes unless you restrict the
> granularity to RLIMIT_MEMLOCK, and on memory constrained systems you might blow yourself up.

Just MAP_FIXED|MAP_POPULATE over page rages not mincore()? You're at least safe from mlock() ulimits then.
< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
Pre-populating anonymous pagesTravis Downs2019/06/05 03:48 PM
  Pre-populating anonymous pagesJeff S.2019/06/05 07:03 PM
    Pre-populating anonymous pagesTravis Downs2019/06/06 06:11 AM
      Pre-populating anonymous pagesJeff S.2019/06/06 07:40 AM
        Pre-populating anonymous pagesTravis Downs2019/06/06 07:59 AM
          Pre-populating anonymous pagesJeff S.2019/06/06 08:19 AM
  Pre-populating anonymous pagesFoo_2019/06/05 11:30 PM
    Pre-populating anonymous pagesTravis Downs2019/06/06 05:59 AM
      Pre-populating anonymous pagesFoo_2019/06/06 06:56 AM
        Pre-populating anonymous pagesTravis Downs2019/06/06 08:02 AM
  Pre-populating anonymous pagesLinus Torvalds2019/06/06 10:01 AM
    Pre-populating anonymous pagesTravis Downs2019/06/07 01:16 PM
      Pre-populating anonymous pagesBrendan2019/06/08 01:55 AM
        Pre-populating anonymous pagesTravis Downs2019/06/08 07:18 AM
        Pre-populating anonymous pagesLinus Torvalds2019/06/08 10:43 AM
          Pre-populating anonymous pagesBrendan2019/06/09 02:29 AM
            Pre-populating anonymous pagesLinus Torvalds2019/06/10 10:20 AM
          Pre-populating anonymous pagesTravis Downs2019/06/17 08:18 AM
            Pre-populating anonymous pagesLinus Torvalds2019/06/18 03:28 PM
Reply to this Topic
Body: No Text
How do you spell tangerine? 🍊