On Mac my use of munmap results in seeing higher page reclaims.
The return value of my munmap is 0, which indicates that the requested pages where successfully unmapped.
Why do I see higher page reclaims when I test programs using memory I have mapped and unmapped in this way?
Is there a way to debug munmap and see if my calls to that function aren't doing anything to the mapped memory that is passed to it.
I used "/usr/bin/time -l" to see the amount of page reclaims I get from running my program. Whenever I use munmap my page reclaims get higher then when I don't.
int main(void)
{
int i = 0; char *addr;
while (i < 1024)
{
addr = mmap(0, getpagesize(), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
addr[0] = 23;
if (!munmap(addr, getpagesize()))
print("Success\n");
i++;
}
return (NULL);
}
on allocation
when I call munmap:
- I pass it the same pointer it gave me.
- I check the return value and check if it is 0 <-- this is what I get most of the time.
I made a test program where I call mmap 1024 times and munmap that number of times too.
When I don't call munmap the reclaimed pages are within the region of 1478 and the value is the same when I call munmap.
How can I check if my use of that memory is correct?