Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #236926

Re: Limit memory consumption of an ad hoc process

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: Limit memory consumption of an ad hoc process
Date 2021-07-05 19:00 +0200
Message-ID <CxA6S-1LS-5@gated-at.bofh.it> (permalink)
References <Cxzkt-1vS-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Jul 05, 2021 at 10:57:03PM +0700, Victor Sudakov wrote:
> Greg Wooledge wrote:
> > One way would be:
> > 
> > (ulimit -m 2097152; ./mytest)
> 
> Is the value in KB or MB? Seems KB.

Please read the documentation.

unicorn:~$ ulimit -a | grep -- -m
max memory size             (kbytes, -m) unlimited

> 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

Have you been omitting the parentheses in your previous testing?

unicorn:~$ (ulimit -m 640; /bin/echo hi)
hi

Setting the resource limit DOWNWARD should always be allowed.  This
particular one is set to infinity by default in Debian, so the only way
setting it to 640 kbytes would be disallowed is if you had previously
set it lower than that.  Which, judging by the lack of parentheses in
your sample call, is a thing you might have done.

You don't want to nuke resources limits in your interactive shell.  That's
what the explicit subshells are for.


On Mon, Jul 05, 2021 at 11:06:31PM +0700, Victor Sudakov wrote:
> Even as root, there is no "Operation not permitted" message, but there
> is no working limit either:
> 
> 
> # 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?

And in any case, when you test this stuff, use the subshells.  Or be
prepared to discard and re-spawn a whole lot of terminal windows.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Limit memory consumption of an ad hoc process Victor Sudakov <vas@sibptus.ru> - 2021-07-05 05:40 +0200
  Re: Limit memory consumption of an ad hoc process Greg Wooledge <greg@wooledge.org> - 2021-07-05 14:00 +0200
    Re: Limit memory consumption of an ad hoc process Victor Sudakov <vas@sibptus.ru> - 2021-07-05 18:00 +0200
      Re: Limit memory consumption of an ad hoc process Victor Sudakov <vas@sibptus.ru> - 2021-07-05 18:10 +0200
        Re: Limit memory consumption of an ad hoc process Greg Wooledge <greg@wooledge.org> - 2021-07-05 19:00 +0200
          Re: Limit memory consumption of an ad hoc process Victor Sudakov <vas@sibptus.ru> - 2021-07-06 04:50 +0200
            Re: Limit memory consumption of an ad hoc process The Wanderer <wanderer@fastmail.fm> - 2021-07-06 05:10 +0200
              Re: Limit memory consumption of an ad hoc process Greg Wooledge <greg@wooledge.org> - 2021-07-06 05:20 +0200
              Re: Limit memory consumption of an ad hoc process Greg Wooledge <greg@wooledge.org> - 2021-07-06 05:20 +0200
                Re: Limit memory consumption of an ad hoc process Victor Sudakov <vas@sibptus.ru> - 2021-07-06 06:30 +0200
              Re: Limit memory consumption of an ad hoc process Victor Sudakov <vas@sibptus.ru> - 2021-07-06 06:40 +0200
  Re: Limit memory consumption of an ad hoc process Victor Sudakov <vas@sibptus.ru> - 2021-07-06 06:30 +0200

csiph-web