大网数据广告活动
服务器运维问答

How to prevent kernel I/O thrashing in absence of swap memory on Linux?

· 52CE 我爱测

I had problem with a process spawning very many threads due to a bug, eating up memory, causing heavy swapping to the swap partition. Thus, I switched off swap – which is recommended in server clusters anyway – to let the buggy p…

问题原文

原帖链接 · Torsten Bronger · CC BY-SA 3.0

I had problem with a process spawning very many threads due to a bug, eating up memory, causing heavy swapping to the swap partition. Thus, I switched off swap – which is recommended in server clusters anyway – to let the buggy program fail early. To my surprise, this didn't improve things at all! Similarly, setting vm.swappiness to 0 didn't help. iotop revealed heavy reading from disk (almost no writing).

I suspect that the Linux kernel is still swapping code pages in memory, and re-reads overwritten code pages from disk when they are needed. When RAM is very low, this happens very frequently, causing thrashing, making the computer almost unresponsive.

How can one prevent this unfortunate and potentially dangerous situation? I tried switching off swap, cgroups for memory and CPU constraints for that process, and ulimit for max. 30 processes. Nothing even improved the situation. (Well, this is not entirely true: a RAM limit which left hundreds of MB permanently unused did help.)

In particular: Can I prevent swapping code segments in memory, and let the RAM-requesting process simply get a NULL for their next malloc?

已采纳解答

原帖链接 · Janne Pikkarainen · CC BY-SA 3.0

How about tuning the memory overcommit accounting and setting it to option 2 (do not overcommit) instead of the default option 0 (heuristic overcommit)? The description for that states

Don't overcommit. The total address space commit
for the system is not permitted to exceed swap + a
configurable amount (default is 50%) of physical RAM.
Depending on the amount you use, in most situations
this means a process will not be killed while accessing
pages but will receive errors on memory allocation as
appropriate.

The above snippet is from kernel documentation

The policy can be set with vm.overcommit tunable.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-02-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。