Munmap isn't working

578 views Asked by At

I've a problem with munmap. I'm implementing my own malloc/free. Malloc work fine, but free didn't.

Example (I directly use with a big munmap, because the code of my free is too long to be shown here):

#include "malloc.h"
#include <stdio.h>
int main()
{
    int i;
    char *addr;
    char *t;
    i = 0;
    while (i < 1024)
    {
        addr=(char *)my_malloc(1024);
        addr[0] = 42;
        if (i == 0)
            t = addr;
    //  my_free(addr);
    i++;
    }
    if (munmap(t, 1024*1024) != -1)
        printf("Ok\n");
    return 0;
}

When test it with /usr/bin/time -l ./a.out the number of page reclaimes is still the same, even if i remove the munmap. So, I guess the munmap fail in an other way to unmap the pages.. But I don't understand at all where it could from.

Other example more easy :

# include <string.h>
# include <sys/mman.h>
# include <string.h>
# include <unistd.h>
# include <stdio.h>

int main()
{
    int i;
    char *addr;
    i = 0;

    while (i < 100)
    {
        addr =  (char *)mmap(0, getpagesize()*256, PROT_READ | PROT_WRITE, MAP_ANON
        | MAP_PRIVATE, -1, 0);
        addr[0] = 42;
        munmap(addr, getpagesize()*256);
        i++;
    }
    return 0;
}

Always with /usr/bin/time -l ./a.out

With munmap or not, the number of pages reclaimes still is the same..

Any Idea ?

Thanks!

Edit : Always no Idea, I did some test, the memory is effectively disallocated, but the number of pages reclaimed is still the same. I really don't understand ? Is it a bug from munmap ?

0

There are 0 answers