为什么 ulimit 无法成功限制常驻内存以及如何限制?

发布于 2024-09-11 17:51:29 字数 933 浏览 4 评论 0原文

我启动一个新的 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
"

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

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

限制常驻内存的目标是因为当一个进程几乎用完所有内存时计算机就会死机。

I start a new bash shell, and execute:

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.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月棠 2024-09-18 17:51:29

根据 setrlimit< 的手册页/代码>

RLIMIT_RSS

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

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

According to the man page for setrlimit:

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

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

朮生 2024-09-18 17:51:29

您可以使用 cgroup 限制驻留内存。请参阅驻留集大小 (RSS) 限制不起作用< /a>

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

雨落□心尘 2024-09-18 17:51:29

尽管限制最大内存大小不起作用,但您可以限制数据段大小。这与驻留内存不同,但它仍然有助于防止内存使用失控。

Although limiting max memory size doesn't work, you can limit data seg size. This isn't the same thing as resident memory, but it's still helpful in protecting against runaway memory usage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文