[kerneltech] Re: [kerneltech] Re: [kerneltech] 关于进程的stack limit

  • From: Li Haifeng <omycle@xxxxxxxxx>
  • To: kerneltech@xxxxxxxxxxxxx
  • Date: Thu, 29 Sep 2011 23:27:55 +0800

在 2011年9月29日 下午10:26,Jiaqiang Xu <xjqhust03@xxxxxxxxx>写道:

> ulimit -s unlimited之后,地址空间就变成traditional memory layout了,这也是有时候设置stack size
> unlimited的作用。   ulimit -s可以设置stack maximum大小。
>
>

Warning:  This routine is obsolete.  Use getrlimit(2), setrlimit(2), and
sysconf(3) instead.  For the shell command
       ulimit(), see bash(1).

       The ulimit() call will get or set some limit for the calling process.
 The cmd argument can have one of the follow?\
       ing values.

       UL_GETFSIZE
              Return the limit on the size of a file, in units of 512 bytes.

       UL_SETFSIZE
              Set the limit on the size of a file.

我回头试试setrlimit,看到底是否可以设置stack.


>
> 2011/9/29 Li Haifeng <omycle@xxxxxxxxx>
>
>> 昨晚上看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
>>
>>
>


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

Other related posts:

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