Difference between revisions of "Memory management"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
Line 58: Line 58:
  
 
136K writable-private, 3568K readonly-private, 0K shared, and 352K referenced
 
136K writable-private, 3568K readonly-private, 0K shared, and 352K referenced
# ldd a.out
 
        linux-vdso.so.1 =>  (0x00007fffc4bee000)
 
        libc.so.6 => /lib64/libc.so.6 (0x00007f2c6cc78000)
 
        /lib64/ld-linux-x86-64.so.2 (0x00007f2c6d013000)
 
 
</pre>
 
</pre>
 +
Ok, it looks like the binary has a lot of shared libraries that it makes use of. Let's see if this is true:
 +
# ldd a.out
 +
        linux-vdso.so.1 =>  (0x00007fffc4bee000)
 +
        libc.so.6 => /lib64/libc.so.6 (0x00007f2c6cc78000)
 +
        /lib64/ld-linux-x86-64.so.2 (0x00007f2c6d013000)

Revision as of 15:06, 6 June 2012

page size

Ok, first I want to find out my system's page size so I write a program:

#include <unistd.h>
#include <stdio.h>
int main()
{
             int sz = getpagesize();
             printf("%d",sz);
}

And compile it:

# gcc main.c

And execute it:

# ./a.out
4096

Ok, so my system's page size is 4K.

Now let's write the next program and check how much memory it consumes. Here is the code:

int main()
{
  while (1);
}

Compile it

# gcc main.c

And execute it in the background:

# ./a.out &
[5] 24058

Ok, it's process ID is 24058. Let's look at its memory consumption:

# pmap 24058
24058: a.out
START               SIZE     RSS     PSS   DIRTY    SWAP PERM MAPPING
0000000000400000      4K      4K      4K      0K      0K r-xp /home/tstaerk/test/a.out
0000000000600000      4K      4K      4K      4K      0K r--p /home/tstaerk/test/a.out
0000000000601000      4K      4K      4K      4K      0K rw-p /home/tstaerk/test/a.out
00007fda6f01e000   1364K    160K      1K      0K      0K r-xp /lib64/libc-2.11.1.so
00007fda6f173000   2044K      0K      0K      0K      0K ---p /lib64/libc-2.11.1.so
00007fda6f372000     16K     16K     16K     16K      0K r--p /lib64/libc-2.11.1.so
00007fda6f376000      4K      4K      4K      4K      0K rw-p /lib64/libc-2.11.1.so
00007fda6f377000     20K     12K     12K     12K      0K rw-p [anon]
00007fda6f37c000    124K    104K      1K      0K      0K r-xp /lib64/ld-2.11.1.so
00007fda6f55a000     12K     12K     12K     12K      0K rw-p [anon]
00007fda6f599000      4K      4K      4K      4K      0K rw-p [anon]
00007fda6f59a000      4K      4K      4K      4K      0K r--p /lib64/ld-2.11.1.so
00007fda6f59b000      4K      4K      4K      4K      0K rw-p /lib64/ld-2.11.1.so
00007fda6f59c000      4K      4K      4K      4K      0K rw-p [anon]
00007fff625e5000     84K     12K     12K     12K      0K rw-p [stack]
00007fff625ff000      4K      4K      0K      0K      0K r-xp [vdso]
ffffffffff600000      4K      0K      0K      0K      0K r-xp [vsyscall]
Total:             3704K    352K     86K     80K      0K

136K writable-private, 3568K readonly-private, 0K shared, and 352K referenced

Ok, it looks like the binary has a lot of shared libraries that it makes use of. Let's see if this is true:

# ldd a.out
        linux-vdso.so.1 =>  (0x00007fffc4bee000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2c6cc78000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2c6d013000)