anon memory segments on Linux

[adm-showard@cmhlcarchapp01 ~]$ cat mem.c
#include 
#include 
#include 

int main() {
  struct rusage r_usage;
  void *m = malloc(4194304000L);
  memset(m,0,4194304000L);
  sleep (60);
}
[adm-showard@cmhlcarchapp01 ~]$ gcc -o mem mem.c
[adm-showard@cmhlcarchapp01 ~]$ ./mem &
[1] 25748
[adm-showard@cmhlcarchapp01 ~]$ pmap -d 25748
25748:   ./mem
Address           Kbytes Mode  Offset           Device    Mapping
0000000000400000       4 r-x-- 0000000000000000 000:00018 mem
0000000000600000       4 rw--- 0000000000000000 000:00018 mem
0000003934000000     128 r-x-- 0000000000000000 0fd:00000 ld-2.12.so
0000003934220000       4 r---- 0000000000020000 0fd:00000 ld-2.12.so
0000003934221000       4 rw--- 0000000000021000 0fd:00000 ld-2.12.so
0000003934222000       4 rw--- 0000000000000000 000:00000   [ anon ]
0000003934400000    1576 r-x-- 0000000000000000 0fd:00000 libc-2.12.so
000000393458a000    2048 ----- 000000000018a000 0fd:00000 libc-2.12.so
000000393478a000      16 r---- 000000000018a000 0fd:00000 libc-2.12.so
000000393478e000       8 rw--- 000000000018e000 0fd:00000 libc-2.12.so
0000003934790000      16 rw--- 0000000000000000 000:00000   [ anon ]
00007f2298f8b000 4096016 rw--- 0000000000000000 000:00000   [ anon ]
00007f2392f9c000       4 rw--- 0000000000000000 000:00000   [ anon ]
00007fff37397000      84 rw--- 0000000000000000 000:00000   [ stack ]
00007fff373ec000       4 r-x-- 0000000000000000 000:00000   [ anon ]
ffffffffff600000       4 r-x-- 0000000000000000 000:00000   [ anon ]
mapped: 4099924K    writeable/private: 4096140K    shared: 0K
[adm-showard@cmhlcarchapp01 ~]$ ps aux | grep 25748 | grep -v grep
8084694  25748 15.6 50.8 4099920 4096392 pts/0 S    14:33   0:03 ./mem

If you comment out the memset() call, you won’t see the RSS memory as high…

[adm-showard@cmhlcarchapp01 ~]$ ps aux | grep 10828 | grep -v grep
8084694  10828  0.0  0.0 4099920  388 pts/0    S    15:13   0:00 ./mem

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.