Ticket #43 (closed bug: fixed)

Opened 3 months ago

Last modified 3 months ago

mmap memory leak

Reported by: carns Assigned to: carns
Priority: major Component: kmod
Version: 2.7.0 Keywords: mmap memory leak
Cc:

Description

mmap() read of files on pvfs results in memory being leaked by the kernel module. Memory is not recovered by restarting pvfs2-client-core. This example output and source code shows what happens when reading a 64M file:

$ dd if=/dev/zero of=/mnt/pvfs2/boom.dat bs=1M count=64

$ free
             total       used       free     shared    buffers     cached
Mem:       2034016    1312120     721896          0      73856     546168
-/+ buffers/cache:     692096    1341920
Swap:      4770320          0    4770320

$ ./foo /mnt/pvfs2/boom.dat

$ free
             total       used       free     shared    buffers     cached
Mem:       2034016    1380216     653800          0      73908     547456
-/+ buffers/cache:     758852    1275164
Swap:      4770320          0    4770320

Source code for foo:

#include <stdio.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    int fd;
    char* addr;
    int i;
    char* tmp;

    fd = open(argv[1], (O_RDWR), (S_IRUSR|S_IWUSR));
    if(fd < 0)
    {
        perror("open");
        return(-1);
    }

    addr = mmap(NULL, (1024*1024*64), PROT_READ, MAP_PRIVATE, fd, 0);
    if(!addr)
    {
        perror("mmap");
        return(-1);
    }

    tmp = malloc(1024*1024*64);
    if(!tmp)
    {
        perror("malloc");
        return(-1);
    }

    for(i=0; i<(1024*1024*64); i++)
    {
        tmp[i] = addr[i];
    }

    close(fd);

    return(0);
}

Change History

04/23/08 15:22:52 changed by carns

  • status changed from new to closed.
  • resolution set to fixed.

Modified ra_pages setting from 1024 to 0 in pvfs2_backing_dev_info struct. This was signaling the kernel to readahead on mmap but I don't think we have the infrastructure to do this, and it is redundant to the mmap_ra_cache at the pvfs2-client-core level.

Initial bug reported by Dan Parsons; he is testing to confirm that it fixes a memory leak that he was seeing from an app that uses mmap(). Closing ticket for now, will reopen if problem persists.