LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-01-2008, 05:31 AM   #1
Micky_123
LQ Newbie
 
Registered: Dec 2007
Posts: 17

Rep: Reputation: 0
How to restrict memory utilization in a process


Hi,
My process is consuming a lot of memory. How can I bring it down?
I used ulimit but then it affects the other processes as well. I tried restricting the stack size of the thread but then also I am seeing (via top utility ) that it uses a lot of memory.
Any pointers to understand / fix this will be highly apprecited.

cheers,
Micky
 
Old 08-01-2008, 05:56 AM   #2
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
You tried restricting the stack size or heap size? Using the *malloc family of calls assigns memory to the heap and not the stack. If it's your code, can't you restrict the size programmatically using something like setrlimit?

Otherwise, you can easily use ulimit for a specific user and run that program as that user so it doesn't affect all the other processes running as other users.
 
Old 08-01-2008, 09:21 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Otherwise, you can easily use ulimit for a specific user and run that program as that user so it doesn't affect all the other processes running as other users.
Or you can run the process in a new instance of the bash shell, with ulimit set appropriately. The following code snippet exemplifies:
Code:
bash -c 'ulimit -t 1; perl -e "while(1){}"'

   --  resulting output --

bash: line 1: 14200 Killed                  perl -e "while(1){}"
In this example, ulimit is used to restrict CPU time, but it seems reasonable that other limits would apply similarly. I realize that launching a whole new shell is contrary to your objective of resource conservation, but depending on the magnitude of the memory usage, perhaps it still results in a net gain.

--- rod.

Last edited by theNbomr; 08-01-2008 at 09:22 AM.
 
Old 08-04-2008, 12:26 AM   #4
Micky_123
LQ Newbie
 
Registered: Dec 2007
Posts: 17

Original Poster
Rep: Reputation: 0
Hi,

I tried restricting the stack size using the stacksize used at the time of pthread creation. So I was thinking that I will observe quite a lot of reduction in the memory but I didn't. I will try using setrlimit.
Also, I have to run this process with the root priviledges and there are other processes as well which need to be run with root priviledges. So using ulimit doesn't looks to help me out.
ALso, I was wondering if there is any utility/tool that can tell exatly how much memory is used by my process. Top shows virtual memory which sometimes overshoot even the total memory of the system and so I feel it doesn't give a very good idea.
 
Old 08-04-2008, 12:46 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Try restricting its virtual memory by setting the soft limit from within the program.
ta0kira
 
Old 08-04-2008, 01:03 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,285

Rep: Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029Reputation: 1029
On recent (2.6.24+) kernels you can use the memory controller for cgroups (aka containers). Have a look at ../Documentation/controllers/memory.txt

This appears to be a much better approach than in the "old" cpusets, where memory could only be restricted by (NUMA) node. Very coarse and unusable by the majority of (home/small) users. I haven't gotten around to testing the new controller that was merged in 2.6.24
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
per process Cpu utilization kunal_patel22 Linux - Software 4 12-04-2007 05:14 PM
Per-process %CPU Utilization first_linux Linux - General 3 06-01-2007 11:53 AM
how to find per-process swap utilization? ananthbv Programming 1 11-02-2006 01:16 AM
why X window process consume 15% CPU utilization? paomo Linux - Enterprise 3 06-26-2006 12:11 PM
per process cpu utilization kunal_patel22 Linux - Software 1 05-19-2005 10:26 AM


All times are GMT -5. The time now is 11:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration