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

Re: Limit memory consumption of an ad hoc process



Greg Wooledge wrote:

[dd]

> > 
> > 
> > # ulimit -m 1048576 ; stress-ng --vm 1 --vm-bytes 8G
> > stress-ng: info:  [10961] defaulting to a 86400 second (1 day, 0.00 secs) run per stressor
> > stress-ng: info:  [10961] dispatching hogs: 1 vm
> > 
> > stress-ng is not killed. Swap is not enabled on this test host.
> 
> Perhaps -m is not the correct resource limit for what you're trying to
> achieve.  You've been assuming that it is, but I told you to read
> setrlimit(3) to see what each of them is and what it actually controls.
> 
> >From ulimit's output:
> 
> max memory size             (kbytes, -m) unlimited
> 
> >From bash(1):
> 
>               -m     The maximum resident set size (many systems do not  honor
>                      this limit)
> 
> >From setrlimit(3):
> 
>        RLIMIT_RSS
>               This is a limit (in bytes) on the process's  resident  set  (the
>               number of virtual pages resident in RAM).  This limit has effect
>               only in Linux 2.4.x, x < 30, and there  affects  only  calls  to
>               madvise(2) specifying MADV_WILLNEED.
> 
> Perhaps you want "ulimit -v" instead?

You are correct, `ulimit -v` works:

$ ulimit -v 1048576 ; stress-ng --vm 1 --vm-bytes 8G
stress-ng: info:  [11081] defaulting to a 86400 second (1 day, 0.00 secs) run per stressor
stress-ng: info:  [11081] dispatching hogs: 1 vm
stress-ng: error: [11083] stress-ng-vm: gave up trying to mmap, no available memory
stress-ng: info:  [11081] successful run completed in 10.01s
$ 

> 
> And in any case, when you test this stuff, use the subshells.  

Well, my goal is to find a way to limit programs run from cron, PHP's
proc_open() etc., not from the interactive shell. What would you advise?

The equivalent of FreeBSD's `/usr/bin/limits` wrapper seems to be
`/usr/bin/prlimit` but I'm really at a loss what limit to specify for
testing (the equivalent of `ulimit -v`). Should be RLIMIT_AS but --as 
crashes prlimit:

$ prlimit --as=1048576 /bin/ls
/bin/ls: error while loading shared libraries: libselinux.so.1: failed to map segment from shared object
$
$ prlimit --as=1048576 stress-ng
Segmentation fault
$

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

Attachment: signature.asc
Description: PGP signature


Reply to: