I'm working on a device that has very tight memory size and virtual address space constraint.
I'm trying to solve this problem by reclaiming memory more frequently while reclaiming virtual address less frequently, e.g. reserving virtual address early but committing memory late, while reclaiming memory early and releasing virtual address late.
Particularly there is a very large allocation that suffers a lot from address space fragmentation and I'm trying to solve it by reserving address space for it up front.
This question solves the first problem: use mmap
with PROT_NONE
to acquire virtual address range, and use mprotect
with PROT_READ|PROT_WRITE
before use, and then pages would be faulted in when used.
However, I couldn't find a way to do the reverse: mprotect
with PROT_NONE
doesn't seem to release the pages, while calling munmap
loses the virtual address range.
Is there to unmap/detach pages while preserving virtual address?