If I've mmap() some PRIVATE and ANONYMOUS pages and then extend them with mremap(), does the new space also get initialized to zeroes?
I've tried reading the code for mremap (mm/mremap.c) in the linux source but it requires some domain-specific knowledge that I don't currently have (vma_### stuff). Not even sure that's the right place to look...
But, from what I've gathered I think that mremap()ed memory would be cleared, is this correct?
Allocation is done like this
list = mmap(NULL, newSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
and then remap is done like this
newList = mremap(list, oldSize, newSize, MREMAP_MAYMOVE)
Ah, and last, it's a Linux specific question, running a recent kernel (>=2.6.28) and libc (>= 2.11.1)
Anonymous pages are copy-on-write mappings of the universal zero page. They always have been (on every system, not just Linux, that offers anonymous mappings) and always will be. When mremap
(or brk
) extends an anonymous mapping, you get new anonymous (zero) pages. There is no need to initialize them yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With