ablog

不器用で落着きのない技術者のメモ

HugePage は free コマンドで見ると used に計上される(2)

HugePages は free コマンドで見ると used に計上される - ablog の続き。
Huge Page はユーザープロセスから使われる前はOSカーネル内に確保され、used に計上されるが、ユーザプロセスが使用すると cahched に計上されるぽい。

検証結果

# ulimit -l unlimited
# ulimit -l
unlimited
# sysctl -w vm.nr_hugepages=200
vm.nr_hugepages = 200
# sysctl vm.nr_hugepages
vm.nr_hugepages = 200
# gdb hugepage-shm
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/yazekats/Documents/github/yoheia/misc/hugepage_test/hugepage-shm...done.
(gdb) b 89
Breakpoint 1 at 0x40086f: file hugepage-shm.c, line 89.
(gdb) run
Starting program: /home/yazekats/Documents/github/yoheia/misc/hugepage_test/hugepage-shm 
shmid: 0x150025
shmaddr: 0x2aaaaac00000
Starting the writes:
................................................................................................................................................................................................................................................................

Breakpoint 1, main () at hugepage-shm.c:89
89		dprintf("Done.\n");
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64
(gdb) 

System V IPC 共有メモリで 256MB 使われている

# ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
(中略)
0x00000002 1376293    root       600        268435456  1 ★256MB   

共有メモリを作成したプロセスの PID は 4500

# ipcs -p

------ Shared Memory Creator/Last-op --------
shmid      owner      cpid       lpid 
(中略)
1376293    root       4500       4500 ★共有メモリを作成、操作したプロセスの PID は 4500       

PID 4500 のメモリ使用量の内訳を pmap コマンドで確認する

# pmap -x 4500
4500:   /home/yazekats/Documents/github/yoheia/misc/hugepage_test/hugepage-shm
Address           Kbytes     RSS   Dirty Mode   Mapping
0000000000400000       4       4       4 r-x--  hugepage-shm
0000000000600000       4       4       4 rw---  hugepage-shm
0000003ba6200000     128     108      12 r-x--  ld-2.12.so
0000003ba641f000       4       4       4 r----  ld-2.12.so
0000003ba6420000       4       4       4 rw---  ld-2.12.so
0000003ba6421000       4       4       4 rw---    [ anon ]
0000003ba6600000    1580     236       0 r-x--  libc-2.12.so
0000003ba678b000    2044       0       0 -----  libc-2.12.so
0000003ba698a000      16       8       8 r----  libc-2.12.so
0000003ba698e000       4       4       4 rw---  libc-2.12.so
0000003ba698f000      20      12      12 rw---    [ anon ]
00002aaaaac00000  262144       0       0 rw-s-  SYSV00000002 (deleted) ★ここが共有メモリ。RSSが0、本当に物理的に使われていないのか?
00007ffff7fe0000      12      12      12 rw---    [ anon ]
00007ffff7ffc000       8       8       8 rw---    [ anon ]
00007ffff7ffe000       4       4       0 r-x--    [ anon ]
00007ffffffde000     132       8       8 rw---    [ stack ]
ffffffffff600000       4       0       0 r-x--    [ anon ]
----------------  ------  ------  ------
total kB          266116     420      84