为什么ulimit不能成功限制驻留内存以及如何?

时间:2021-12-24 02:40:39

I start a new bash shell, and execute:

我启动一个新的bash shell,然后执行:

ulimit -m 102400
ulimit -a
"
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) 102400
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
"

and then ,I execute compiling a huge project. the Linking of it will use large memory, more then 2G. The result, process ld used more then 2G resident memory.

然后,我执行编译一个巨大的项目。它的链接将使用大内存,超过2G。结果,进程ld使用了超过2G的驻留内存。

is there any wrong ? how to use ulimit or can I use other programs to limit resident memory?

有什么不对吗?如何使用ulimit或我可以使用其他程序来限制驻留内存?

the target of limit resident memory, is because computer will freeze when one process almost used all memory.

限制驻留内存的目标,是因为当一个进程几乎使用所有内存时计算机将冻结。

2 个解决方案

#1


7  

According to the man page for setrlimit:

根据setrlimit的手册页:

RLIMIT_RSS

RLIMIT_RSS

Specifies the limit (in pages) of the process's resident set (the number of virtual pages resident in RAM). This limit only has effect in Linux 2.4.x, x < 30, and there only affects calls to madvise(2) specifying MADV_WILLNEED

指定进程驻留集的限制(以页为单位)(驻留在RAM中的虚拟页数)。此限制仅在Linux 2.4.x中有效,x <30,并且仅影响对madvise(2)的调用,指定MADV_WILLNEED

You probably want to set the virtual memory size instead, via ulimit -v

您可能希望通过ulimit -v设置虚拟内存大小

#2


5  

You can restrict the resident memory using cgroups. See Resident Set Size (RSS) limit has no effect

您可以使用cgroup限制驻留内存。请参阅驻留集大小(RSS)限制无效

#1


7  

According to the man page for setrlimit:

根据setrlimit的手册页:

RLIMIT_RSS

RLIMIT_RSS

Specifies the limit (in pages) of the process's resident set (the number of virtual pages resident in RAM). This limit only has effect in Linux 2.4.x, x < 30, and there only affects calls to madvise(2) specifying MADV_WILLNEED

指定进程驻留集的限制(以页为单位)(驻留在RAM中的虚拟页数)。此限制仅在Linux 2.4.x中有效,x <30,并且仅影响对madvise(2)的调用,指定MADV_WILLNEED

You probably want to set the virtual memory size instead, via ulimit -v

您可能希望通过ulimit -v设置虚拟内存大小

#2


5  

You can restrict the resident memory using cgroups. See Resident Set Size (RSS) limit has no effect

您可以使用cgroup限制驻留内存。请参阅驻留集大小(RSS)限制无效