Memory and Paging

Rashkae ubuntu at tigershaunt.com
Thu Feb 12 00:21:26 UTC 2009


John Hubbard wrote:
> My computer has some memory.  When I need more memory than the computer 
> writes some of the stuff in memory to the hard drive to free up the 
> memory.  This is troublesome because the hard drive is very slow.  While 
> moving stuff around the computer often slows way down since there is no 
> free memory.  To fix things I often need to kill the run away task.  
> (Usually some code that I have written that is misbehaving or behaving 
> properly, but using more memory than I expected.)  When in this state, 
> it often takes a very long time to ssh into the machine to kill the task 
> in question.  I am trying to figure out a solution to this problem.  It 
> seems like I would need to do a few things. 
> 
> 1) Have a process running that 'owns' a certain amount of memory (enough 
> to run bash/top/kill/pidof and a few other small programs) and keeps 
> this memory from being paged out. 
> 2) Enough memory set aside for SSHD to allow a new connection. 
> 3) Some way to ssh in and access that memory owning process or request 
> memory from that process. 
> 
> Is there any way to do these things?  Does someone else have a different 
> approach that accomplishes the same thing?  How much memory am I talking 
> about?  Would 5MB be enough?  Any other thoughts or comments?
> 


Do your misbehaving programs have to run as root?  If not, create a user
for them, and stick that user with a reasonable memory limit using
ulimit, (sorry, I forget exact details on how to do this, but that
should be enough info to get google going.)  That way, when user foo
reaches 500MB of used memory, it won't get anymore, and you can ssh in
to kill bad processes at your leisure.

Otherwise, you can reduce the size of your swap space and disable linux
default of "overcommit" (again, I forget the details, but this one is
easy to do).  When an application starts filling ram, you should hit OOM
 (out of memory) really fast, and with luck, the kernel will actually do
the right think and kill a memory hungry app.  (unfortunately, kernel
OOM handling, in my experience, is a blunt trauma force instrument that
damages far more than just the misbehaving process.  But at least that
way you aren't swapping into infinity before the system becomes
accessible again.)




More information about the ubuntu-users mailing list