envirenment:gcc版本4.8.4(Ubuntu 4.8.4-2ubuntu1〜14.04) 3.16.0-30-generic#40〜14.04.1-Ubuntu SMP Thu Jan 15 17:45:15 UTC 2015 i686 i686 i686 GNU爲什麼全局數組(初始化)在C中並沒有完全算作PSS
C code a2.c:有一個40MB全局數組,每個項目都被分配。
int b[10000000];//40M global array
void main() {
int i = 0;
for(i = 0; i<10000000; i++) {b[i]=i;}
while(1);
}
和我建立一個像gcc -o a2 a2.c
當我運行這段代碼,看到了SMAP文件cat /proc/25739/smaps
,內容如下
08048000-08049000 r-xp 00000000 08:11 46930087 /home/jzd/test/a2
Size: 4 kB
Rss: 4 kB
Pss: 4 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 4 kB
Private_Dirty: 0 kB
Referenced: 4 kB
Anonymous: 0 kB
AnonHugePages: 0 kB
Swap: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd ex mr mw me dw
//here I hide some sections
0804b000-0a670000 rw-p 00000000 00:00 0
Size: 39060 kB
Rss: 39060 kB // the RSS is the global array's size
Pss: 2196 kB // the array is only used by the program
// why it's pss is not equal with rss
Shared_Clean: 0 kB // all shared size is 0
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 39060 kB
Referenced: 39060 kB
Anonymous: 39060 kB
AnonHugePages: 36864 kB
Swap: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd wr mr mw me ac
//here I hide other sections
爲什麼會發生呢?
你究竟想做什麼? – Irshad
嗨Irshad,我偶然發現了奇怪的事情,想知道原因。 – ddnionio