[kerneltech] 关于进程的stack limit

  • From: Li Haifeng <omycle@xxxxxxxxx>
  • To: kerneltech@xxxxxxxxxxxxx
  • Date: Thu, 29 Sep 2011 10:20:12 +0800

昨晚上看jiaqiang的PPT,看到在2.6.9的内核以后,文件映射区像栈一样,开始从高地址往低地址映射。给stack留的空间是8MB的限制。

早上写了一个简单的程序测试以下,到底这个栈是多少。
[code]

>   1 #include <stdio.h>
>   2 #define STACK_SIZE 0x1ff000
>
  3 int i=0;

  4 void main()
>   5 {
>   6         int stack[STACK_SIZE]={0};
>   7         while(1)
>   8         {
>   9                 stack[i++%STACK_SIZE]=i;
>  10                 i%=STACK_SIZE;
>  11         }
>  12 }

[/code]
下面是进程线性地址映射区的情况:

>
> haifeng   4432 91.0  0.4   9752  8428 pts/1    R+   09:27   0:02
> ./stack_size
> haifeng   4433  0.0  0.0   6316  1204 pts/2    R+   09:27   0:00 ps aux
> haifeng@Tek-life:~/Public$ pmap 4432
> 4432:   ./stack_size
> 0034d000   1384K r-x--  /lib/i386-linux-gnu/libc-2.13.so
> 004a7000      4K -----  /lib/i386-linux-gnu/libc-2.13.so
> 004a8000      8K r----  /lib/i386-linux-gnu/libc-2.13.so
> 004aa000      4K rw---  /lib/i386-linux-gnu/libc-2.13.so
> 004ab000     12K rw---    [ anon ]
> 0072a000      4K r-x--    [ anon ]
> 00b01000    112K r-x--  /lib/i386-linux-gnu/ld-2.13.so
> 00b1d000      4K r----  /lib/i386-linux-gnu/ld-2.13.so
> 00b1e000      4K rw---  /lib/i386-linux-gnu/ld-2.13.so
> 08048000      4K r-x--  /home/haifeng/Public/stack_size
> 08049000      4K r----  /home/haifeng/Public/stack_size
> 0804a000      4K rw---  /home/haifeng/Public/stack_size
> b7722000      4K rw---    [ anon ]
> b7740000      8K rw---    [ anon ]
> *bf083000   8188K rw---    [ stack ]*
>  total     9748K


1.8188 < 8192 ,即有1个页的hole(最大是8188KB了,不能再增大了).这个hole为啥要算到stack头上?
2.这个栈的大小,系统应该可以更改,如何改?我用getrlimit得到的结果竟然是没有限制。



> 我用getrlimit得到的结果是没有限制(The  value  RLIM_INFINITY denotes no limit on a
> resource )。

 11         int ret=getrlimit(RLIMIT_STACK,lim);

 12         printf("%x\n",ret);//ret,即getrlimit的返回值是0x~0


3.既然给stack预留8MB空间挺好,文件映射区和堆可以充分利用从.bss_end ~ top of
stack。那为什么直到2.6.9的内核才更改过来了,这中间有哪些debate?我觉得,这个debate应该很有趣吧。不过在lkml上没有搜到啊,有知道的同学吗。

-- 
Li Haifeng
Laboratory of Service Computing Technology and System
Home page:http://tek-life.org

Other related posts:

  • » [kerneltech] 关于进程的stack limit - Li Haifeng