1

Assuming the Linux kernel doesn't swap out my process's memory pages, can I assume their physical location in RAM will not be changed, or is it possible the kernel will move them around?

The reason I'm asking is that I'm considering writing my own memtester from scratch, and I was wondering if it's possible a newly allocated page would be in the same physical location in the RAM that the process has already tested before.

1 Answer 1

3

I’m aware of two cases where an allocated page’s physical address can change, and thus where a subsequent allocation can re-use a previously-used physical page:

  • swap-out (as you mention)
  • compaction

The former can be prevented in all cases by locking memory with mlock() or mlockall(). For the latter, the vm.compact_unevictable_allowed sysctl also needs to be set to 0 (it’s enabled by default if compaction is enabled).

Transparent huge page defragmentation uses both swap-out and compaction, but it adds a number of sysctl entries of its own; I don’t know whether they would be needed on top of disabling compaction globally and locking the memory being tested.

1
  • Some brick-based machines (such as the Altix range) will move memory pages to reduce interconnect traffic if a process is scheduled onto a different brick. Obviously this only applies to single system image multi-brick designs and not to clusters.
    – user516667
    Commented Mar 25, 2022 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .