# Memory limits



## rihad (Dec 24, 2010)

Hi, all. Is there any way to limit process memory based on top's RES column? virtualmem (limits -v) seems to limit on the SIZE column, but that's not what I want, since SIZE can be huge with no ill effects. memoryuse & datasize limits don't seem to be RES either.


----------



## anomie (Dec 24, 2010)

Just so we're starting on the same page, from top(1): 


> RES is the current amount of resident
> memory (both SIZE and RES are given in kilobytes)



To solve your problem, I would set up a special user class in login.conf(5), and then join the user(s) who need this memory restriction to that class. 

I _think_ top(1)'s 'RES' is synonymous with login.conf(5)'s 'memorylocked' resource. But you will need to test to see whether that is true.


----------



## Tomtor (Dec 25, 2010)

*Use "memoryuse" for limiting Resident Set Size*



			
				anomie said:
			
		

> I _think_ top(1)'s 'RES' is synonymous with login.conf(5)'s 'memorylocked' resource. But you will need to test to see whether that is true.



A grep over the source shows:


```
./lib/libutil/login_class.c:    { "memoryuse",       login_getcapsize, RLIMIT_RSS     },
```

so memoryuse is what we're looking for (see also setrlimit(2))


----------



## anomie (Dec 25, 2010)

Thanks for clarifying. OP should have the info he needs, then.


----------



## rihad (Sep 3, 2021)

For some reason limits -m 3m (memoryuse) allows the process to pass that limit (top's RES column) indefinitely and continue running.
But limits -v 30m (virtualmem) does cause a core dump.


----------



## Sevendogsbsd (Sep 3, 2021)

I was going to remind you not to necro-bump because this thread is 11 years old, but you are the OP  You don't see many posts with that time gap and the OP actually responds.


----------



## dd_ff_bb (Sep 3, 2021)

Sevendogsbsd said:


> this thread is 11 years old, but you are the OP


Now...this is what i call dedication


----------

