Re: How process size is calculated? Is it always based on the current highest available address in memory space?



On Mon, 29 Dec 2008, Dan Nelson wrote:

In the last episode (Dec 28), Yuri said:
malloc(3) can be controlled by MALLOC_OPTIONS to use mmap-based allocation as opposed to sbrk-based allocation. But allocations/deallocations with mmaps can eventually lead to non-continuously mmapped memory (having some non-mmapped gaps).

Are these gaps excluded from the process size or size is always linked to the current highest available address in memory space?

It looks like only mapped memory is counted in process size. The test program below shows that the reported size goes down, even if a memory range inbetween two others is unmapped:

You can use procstat(8), or on older versions of FreeBSD procfs, to explore the layout of process memory, which may also lend some insight to what's going on.

Robert N M Watson
Computer Laboratory
University of Cambridge


$ ./mmap
Before mmap:
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
1000 48058 62165 0 8 0 1928 824 wait S+ ph 0:00.01 ./mmap
mmap 64MB A=0x28280000
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
1000 48058 62165 0 8 0 67464 824 wait S+ ph 0:00.01 ./mmap
mmap 64MB B=0x2c280000
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
1000 48058 62165 0 8 0 133000 824 wait S+ ph 0:00.01 ./mmap
mmap 64MB C=0x30280000
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
1000 48058 62165 0 8 0 198536 824 wait S+ ph 0:00.01 ./mmap
munmap B
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
1000 48058 62165 0 8 0 133000 824 wait S+ ph 0:00.01 ./mmap


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

int main(void)
{
char *cmd;
void *a, *b, *c;
asprintf(&cmd, "ps axlp %d", getpid());
printf("Before mmap:\n");
system(cmd);
a = mmap(NULL, 64 * 1024 * 1024, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
printf("mmap 64MB A=%p\n", a);
system(cmd);
b = mmap(NULL, 64 * 1024 * 1024, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
printf("mmap 64MB B=%p\n", b);
system(cmd);
c = mmap(NULL, 64 * 1024 * 1024, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
printf("mmap 64MB C=%p\n", c);
system(cmd);
printf("munmap B\n");
munmap(b, 64 * 1024 * 1024);
system(cmd);
return 0;
}


--
Dan Nelson
dnelson@xxxxxxxxxxxxxxx
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"

_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: How process size is calculated? Is it always based on the current highest available address in m
    ... non-continuously mmapped memory. ... Before mmap: ... UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND ...
    (freebsd-hackers)
  • Re: FAQ 5.29 How can I read in an entire file all at once?
    ... PS> Are you sure you want to read the entire file and store it in memory? ... PS> you mmap the file, you can virtually load the entire file into a string ... entities and are best loaded into a scalar. ... mmap always needs virtual ram allocated ...
    (comp.lang.perl.misc)
  • Re: [PATCH 1/2]: Fix BUG in cancel_dirty_pages on XFS
    ... will see _none_ of the write because the mmap write occurred during ... inode in the buffered I/O *writeback* path, we have to stop pages being ... filesystems in both locking and the way it treats the page cache. ... No, but the data _in memory_ will, and now when the direct read ...
    (Linux-Kernel)
  • Re: mmap failing with EINVAL inside valgrind
    ... POST++ tries to start the debugger... ... Why don't they just let the application load the file where mmap ... Moi, you might be right with the memory range, that's what I ... BTW can you find any REASON for the code to use a fixed map-adress? ...
    (comp.unix.programmer)
  • Re: How mmap spends memory
    ... I'm actually interested how does mmap() - munmap() works. ... When you mmapyou are assigning a segment of your process's virtual ... memory segment so that it can be used for other purposes. ...
    (comp.unix.programmer)