NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: ulimit -d/-m do not actually work
mlelstv%serpens.de@localhost (Michael van Elst) writes:
> malloc doesn't use the "data segment", so that limit doesn't apply to it.
>
> -d the data segment size of a process (kilobytes)
>
> RLIMIT_DATA The maximum size (in bytes) of the data segment for a
> process; this defines how far a program may extend its
> break with the sbrk(2) system call.
Thanks. So that solves why "ulimit -d" doesn't do what someone would
expect it to do.
> You can try sbrk(2), it should still obey the data segment size (and
> may fail if you use it concurrently with malloc()).
Sure, but my real goal is to have a memory limit that works, so that I
can test that software isn't unreasonably piggy, and to protect the
system.
> "max memory size" is about physical memory usage and isn't a hard limit.
>
> -m the total physical memory that can be in use by a
> process (kilobytes)
>
> RLIMIT_RSS The maximum size (in bytes) to which a process's resident
> set size may grow. This imposes a limit on the amount of
> physical memory to be given to a process; if memory is
> tight, the system will prefer to take memory from
> processes that are exceeding their declared resident set
> size.
Interesting, but that seems to be a NetBSD extension. Looking at
POSIX, -m is not defined:
https://pubs.opengroup.org/onlinepubs/9799919799/
but setrlimit defines RLIMIT_AS (and not RLIMIT_RSS):
https://pubs.opengroup.org/onlinepubs/9799919799/functions/getrlimit.html
Our shell has -m and -v, both not specified by POSIX, and these
therefore must be about RLIMIT_RSS and RLIMIT_AS respectively.
> Things were much easier when these limits were invented, in particular
> without multithreading and shared libraries, a single heap (the
> "data segment") was sufficient for all memory allocations.
Sure, but it's really surprising that POSIX does not define a way to
limit total usage.
My test program can allocate 53548 kB, when total vsize is 200000 kB
$ ulimit -v 200000
$ ./test-limits
53548
so this does limit memory usage.
Thanks for making me realize that "memory" in -m is pages allocated to
real memory.
Home |
Main Index |
Thread Index |
Old Index