Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - limiting processes stack usage with setrlimit() issue: (6 Items)
   
limiting processes stack usage with setrlimit() issue  
hey,

I'm still trying to reduce memory usage in our application load.  I noticed our watchdog process that writes to one area
 of memory every so often is using over 600KB.  The IDE says that thread 1 has 500K of unallocated stack memory.  There 
is only one thread, so I think that a direct setrlimit should work as per the definition of RLIMIT_STACK

I tried using the setrlimit call on RLIMIT_STACK to limit it to 50KB in main, but nothing changes.
Code snippit:
    getrlimit(RLIMIT_STACK, &rlim);
    rlim.rlim_cur=50*1024;
    rlim.rlim_cur_hi=50*1024;
    rlim.rlim_max=50*1024;
    rlim.rlim_max_hi=50*1024;
    int rc = setrlimit(RLIMIT_STACK, &rlim);
rc is zero, so setrlimit worked.. but the stack still has a huge chunk of memory unallocated (and reserved from what I 
understand).

Is this the correct method of limiting large stack allocations for a process that does not need that much?  What am I 
doing wrong?

Any ideas are appreciated.

Thank you,
Liam
RE: limiting processes stack usage with setrlimit() issue  
Don't know if setrlimit support the stack but you can set the max stack size with -N option of qcc.

-----Original Message-----
From: Liam Howlett [mailto:community-noreply@qnx.com] 
Sent: Wednesday, July 22, 2009 11:40 AM
To: ostech-core_os
Subject: limiting processes stack usage with setrlimit() issue

hey,

I'm still trying to reduce memory usage in our application load.  I noticed our watchdog process that writes to one area
 of memory every so often is using over 600KB.  The IDE says that thread 1 has 500K of unallocated stack memory.  There 
is only one thread, so I think that a direct setrlimit should work as per the definition of RLIMIT_STACK

I tried using the setrlimit call on RLIMIT_STACK to limit it to 50KB in main, but nothing changes.
Code snippit:
    getrlimit(RLIMIT_STACK, &rlim);
    rlim.rlim_cur=50*1024;
    rlim.rlim_cur_hi=50*1024;
    rlim.rlim_max=50*1024;
    rlim.rlim_max_hi=50*1024;
    int rc = setrlimit(RLIMIT_STACK, &rlim);
rc is zero, so setrlimit worked.. but the stack still has a huge chunk of memory unallocated (and reserved from what I 
understand).

Is this the correct method of limiting large stack allocations for a process that does not need that much?  What am I 
doing wrong?

Any ideas are appreciated.

Thank you,
Liam



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post34325

Re: RE: limiting processes stack usage with setrlimit() issue  
That would explain why I don't see a change when I add the setrlimit for the stack.

Do you know if -N is a hard limit or just a default allocation?  It works well and I would like to apply it pretty much 
globally in our build environment if I don't have to worry about certain processes hitting the limit and causing issues.

RE: RE: limiting processes stack usage with setrlimit() issue  
It's a hard limit. Note the stack will GROW as needed till it reaches its limit.  The stack is not totally allocated, 
only the virtual pages are reserved, memory will get allocated as needed.  This is documented.

-----Original Message-----
From: Liam Howlett [mailto:community-noreply@qnx.com] 
Sent: Wednesday, July 22, 2009 1:28 PM
To: ostech-core_os
Subject: Re: RE: limiting processes stack usage with setrlimit() issue

That would explain why I don't see a change when I add the setrlimit for the stack.

Do you know if -N is a hard limit or just a default allocation?  It works well and I would like to apply it pretty much 
globally in our build environment if I don't have to worry about certain processes hitting the limit and causing issues.





_______________________________________________

OSTech
http://community.qnx.com/sf/go/post34333

Re: RE: RE: limiting processes stack usage with setrlimit() issue  
Thanks!  Where can I find this in the documentation?

I'd like to read more on it as well as find the differences if any between 6.2.1 to 6.3.2

Cheers,
Liam
RE: RE: RE: limiting processes stack usage with setrlimit() issue  
I just did a quick search with the word stack in the helpviewer, the topic is Stack memory in the "Memory management in 
QNX Neutrino" section

-----Original Message-----
From: Liam Howlett [mailto:community-noreply@qnx.com] 
Sent: Wednesday, July 22, 2009 2:24 PM
To: ostech-core_os
Subject: Re: RE: RE: limiting processes stack usage with setrlimit() issue

Thanks!  Where can I find this in the documentation?

I'd like to read more on it as well as find the differences if any between 6.2.1 to 6.3.2

Cheers,
Liam



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post34340