Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Dec 2008 19:47:53 +0000 (GMT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        Yuri <yuri@rawbw.com>, 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:  <alpine.BSF.1.10.0812291947100.9438@fledge.watson.org>
In-Reply-To: <20081229154544.GB21654@dan.emsphone.com>
References:  <49585C75.80203@rawbw.com> <20081229154544.GB21654@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@allantgroup.com
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.1.10.0812291947100.9438>