[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Limit memory consumption of an ad hoc process



Greg Wooledge wrote:
> On Mon, Jul 05, 2021 at 10:15:19AM +0700, Victor Sudakov wrote:
> > FreeBSD has a simple way to run some ad-hoc program with memory limits:
> > 
> > $ limits -m 2G ./mytest
> >   memoryuse             2097152 kB
> >   vmemoryuse           infinity kB
> > $ limits -m 1G ./mytest
> >   memoryuse             1048576 kB
> >   vmemoryuse           infinity kB
> > 
> > How do I do the same in Linux (without root permissions)?
> 
> One way would be:
> 
> (ulimit -m 2097152; ./mytest)

Is the value in KB or MB? Seems KB. Anyway, the suggested method does not seem to work:

$ ulimit -m 640 ; stress-ng --vm 1 --vm-bytes 2G
-bash: ulimit: max memory size: cannot modify limit: Operation not permitted
stress-ng: info:  [10272] defaulting to a 86400 second (1 day, 0.00 secs) run per stressor
stress-ng: info:  [10272] dispatching hogs: 1 vm
^C

> 
> This assumes you're using bash as your shell.

I am, as you see above. I expect stress-ng to be killed when it tries to
allocate 2G of memory but it's not happening. Can you reproduce your
advice?

> 
> You never need root privileges to *reduce* one of your resource limits
> to a lower value.  Nor do you need root privs to raise your soft limit
> up to the hard limit.  However, you do need root privs to raise your
> hard limit.
> 

Then, why does it say "cannot modify limit: Operation not permitted" ?

-- 
Victor Sudakov VAS4-RIPE
http://vas.tomsk.ru/
2:5005/49@fidonet

Attachment: signature.asc
Description: PGP signature


Reply to: