You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian 12下Systemd user-0.slice无法覆盖user.slice内存限制问题

解决Debian 12中user-0.slice无法突破user.slice内存限制的问题

问题原因

user-0.slice是user.slice的子单元,systemd的资源限制遵循父单元限制为子单元硬上限的规则:

  • 当你给父单元user.slice设置MemoryMax=5GB,意味着该slice下所有子单元(包括root的user-0.slice)的总内存使用不能超过5GB
  • 子单元设置MemoryMax=infinity仅表示「继承父单元的限制」,而非突破父单元的上限,因此root的可用内存仍受限于user.slice的5GB配置

正确配置方案

要实现「普通用户单用户内存限制5GB,root无限制」的需求,需调整配置层级,避免在父slice设置全局总限制,改为针对普通用户的slice模板单独配置:

步骤1:移除user.slice的全局内存限制

删除父slice的全局限制文件:

rm /etc/systemd/system.control/user.slice.d/50-MemoryMax.conf

步骤2:配置普通用户slice的模板限制

创建用户slice的模板配置文件,用于给所有普通用户(UID≠0)的slice设置内存上限:

# 文件路径:/etc/systemd/system/user@.slice.d/50-MemoryMax.conf
[Slice]
MemoryMax=5368709120

步骤3:保留root slice的无限制配置

确保root的slice配置不变:

# 文件路径:/etc/systemd/system.control/user-0.slice.d/50-MemoryMax.conf
[Slice]
MemoryMax=infinity

步骤4:重新加载systemd并生效配置

执行命令让新配置生效:

systemctl daemon-reload
systemctl restart user-0.slice
systemctl restart user@*.slice

验证配置

查看各slice的内存限制是否符合预期:

# 查看root的内存限制,应返回infinity
systemctl show user-0.slice -p MemoryMax
# 查看普通用户(如UID=1000)的内存限制,应返回5368709120
systemctl show user@1000.slice -p MemoryMax

内容的提问来源于stack exchange,提问作者Ignatella

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 22:55:12