cat /proc/[pid]/maps
를 하면 해당 process 가 메모리를 어떻게 사용하고 있는지 알 수 있습니다.
Test 를 할 일이 있어서
malloc 을 계속해서 할당하는 application 을 구현해서 heap size 를 보았습니다.
# cat maps
00008000-00009000 r-xp 00000000 8a:09 42521 /opt/make_lock_up
00010000-00011000 rwxp 00000000 8a:09 42521 /opt/make_lock_up
00011000-0a8ad000 rwxp 00011000 00:00 0 [heap]
40000000-4001c000 r-xp 00000000 8b:07 2304052 /lib/ld-2.5.so
4001c000-4001f000 rwxp 4001c000 00:00 0
40023000-40025000 rwxp 0001b000 8b:07 2304052 /lib/ld-2.5.so
40038000-4004c000 r-xp 00000000 8b:07 3676088 /lib/libpthread-2.5.so
4004c000-40053000 ---p 00014000 8b:07 3676088 /lib/libpthread-2.5.so
40053000-40054000 r-xp 00013000 8b:07 3676088 /lib/libpthread-2.5.so
40054000-40055000 rwxp 00014000 8b:07 3676088 /lib/libpthread-2.5.so
40055000-40057000 rwxp 40055000 00:00 0
40057000-4016a000 r-xp 00000000 8b:07 2372924 /lib/libc-2.5.so
4016a000-40172000 ---p 00113000 8b:07 2372924 /lib/libc-2.5.so
40172000-40173000 r-xp 00113000 8b:07 2372924 /lib/libc-2.5.so
40173000-40175000 rwxp 00114000 8b:07 2372924 /lib/libc-2.5.so
40175000-40178000 rwxp 40175000 00:00 0
bef5c000-bef71000 rwxp befeb000 00:00 0 [stack]
# cat maps
00008000-00009000 r-xp 00000000 8a:09 42521 /opt/make_lock_up
00010000-00011000 rwxp 00000000 8a:09 42521 /opt/make_lock_up
00011000-0b258000 rwxp 00011000 00:00 0 [heap]
40000000-4001c000 r-xp 00000000 8b:07 2304052 /lib/ld-2.5.so
4001c000-4001f000 rwxp 4001c000 00:00 0
40023000-40025000 rwxp 0001b000 8b:07 2304052 /lib/ld-2.5.so
40038000-4004c000 r-xp 00000000 8b:07 3676088 /lib/libpthread-2.5.so
4004c000-40053000 ---p 00014000 8b:07 3676088 /lib/libpthread-2.5.so
40053000-40054000 r-xp 00013000 8b:07 3676088 /lib/libpthread-2.5.so
40054000-40055000 rwxp 00014000 8b:07 3676088 /lib/libpthread-2.5.so
40055000-40057000 rwxp 40055000 00:00 0
40057000-4016a000 r-xp 00000000 8b:07 2372924 /lib/libc-2.5.so
4016a000-40172000 ---p 00113000 8b:07 2372924 /lib/libc-2.5.so
40172000-40173000 r-xp 00113000 8b:07 2372924 /lib/libc-2.5.so
40173000-40175000 rwxp 00114000 8b:07 2372924 /lib/libc-2.5.so
40175000-40178000 rwxp 40175000 00:00 0
bef5c000-bef71000 rwxp befeb000 00:00 0 [stack]
# cat maps
00008000-00009000 r-xp 00000000 8a:09 42521 /opt/make_lock_up
00010000-00011000 rwxp 00000000 8a:09 42521 /opt/make_lock_up
00011000-0bafb000 rwxp 00011000 00:00 0 [heap]
40000000-4001c000 r-xp 00000000 8b:07 2304052 /lib/ld-2.5.so
4001c000-4001f000 rwxp 4001c000 00:00 0
40023000-40025000 rwxp 0001b000 8b:07 2304052 /lib/ld-2.5.so
40038000-4004c000 r-xp 00000000 8b:07 3676088 /lib/libpthread-2.5.so
4004c000-40053000 ---p 00014000 8b:07 3676088 /lib/libpthread-2.5.so
40053000-40054000 r-xp 00013000 8b:07 3676088 /lib/libpthread-2.5.so
40054000-40055000 rwxp 00014000 8b:07 3676088 /lib/libpthread-2.5.so
40055000-40057000 rwxp 40055000 00:00 0
40057000-4016a000 r-xp 00000000 8b:07 2372924 /lib/libc-2.5.so
4016a000-40172000 ---p 00113000 8b:07 2372924 /lib/libc-2.5.so
40172000-40173000 r-xp 00113000 8b:07 2372924 /lib/libc-2.5.so
40173000-40175000 rwxp 00114000 8b:07 2372924 /lib/libc-2.5.so
40175000-40178000 rwxp 40175000 00:00 0
bef5c000-bef71000 rwxp befeb000 00:00 0 [stack]
00011000-0a8ad000 rwxp 00011000 00:00 0 [heap]
00011000-0b258000 rwxp 00011000 00:00 0 [heap]
00011000-0bafb000 rwxp 00011000 00:00 0 [heap]
예 heap 사이즈가 계속해서 늘어나는 것을 볼 수 있습니다.
하지만 바로 밑에 있는
40000000-4001c000 r-xp 00000000 8b:07 2304052 /lib/ld-2.5.so
까지 무한정으로 늘어나지는 않습니다.
물리적인 Ram 공간에 한계가 있기 때문이죠.
일반적인 linux system 이라면 oom 이 떠서 process 들을 마구마구 KILL 하는
잔인한 장면을 목격하실 수 있습니다. ^^;
'Programming > Linux_Kernel' 카테고리의 다른 글
objdump - 실행파일에서 asm code 확인 (0) | 2010.04.21 |
---|---|
linux mailing list 정리 (0) | 2010.04.19 |
특정 시간 동안 system cpu 사용량 구하기 (linux) (0) | 2010.04.07 |
Platform_get_irq & struct resource (4) | 2010.04.06 |
간단히 system lock up 상황 만들기 (0) | 2010.03.25 |