Reputation: 3408
I allocated some memory using memalign, and I set the last page as a guard page using mprotec(adde, size, PROT_NONE)
, so this page is inaccessible.
Does the inaccessible page consume physical memory? In my opinion, the kernel can offline the physical pages safely, right?
I also tried madvise(MADV_SOFT_OFFLINE) to manually offline the physical memory but the function always fails.
Can anybody tell me the internal behavior of kernel with mprotect(PROT_NONE)
, and how to offline the physical memory to save physical memory consumption?
Upvotes: 3
Views: 1572
Reputation: 1
Linux applications are using virtual memory. Only the kernel is managing physical RAM. Application code don't see the physical RAM.
A segment protected with mprotect
& PROT_NONE
won't consume any RAM.
You should allocate your segment with mmap(2) (maybe you want MAP_NORESERVE
). Mixing memalign
with mprotect
may probably break libc invariants.
Read carefully madvise(2) man page. MADV_SOFT_OFFLINE
may require a specially configured kernel.
Upvotes: 2