Date: Mon, 29 Dec 2008 09:45:44 -0600 From: Dan Nelson <dnelson@allantgroup.com> To: Yuri <yuri@rawbw.com> Cc: freebsd-hackers@freebsd.org Subject: Re: How process size is calculated? Is it always based on the current highest available address in memory space? Message-ID: <20081229154544.GB21654@dan.emsphone.com> In-Reply-To: <49585C75.80203@rawbw.com> References: <49585C75.80203@rawbw.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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: $ ./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@allantgroup.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081229154544.GB21654>