Skip to content

Instantly share code, notes, and snippets.

@yugr
Created July 23, 2023 09:40
Show Gist options
  • Save yugr/270a376d323045df82d0cf462207fac8 to your computer and use it in GitHub Desktop.
Save yugr/270a376d323045df82d0cf462207fac8 to your computer and use it in GitHub Desktop.
Using cgroups to limit Memory usage
Based on https://www.flamingbytes.com/blog/cgroups-limit-memory/
Install prerequisites:
$ apt install libcgroup libcgroup-tools
Create new group:
$ cgcreate -g memory:/memlimited
Set limit:
$ echo 32G > /sys/fs/cgroup/memory/memlimited/memory.limit_in_bytes
$ cgset -r memory.limit_in_bytes=32G memlimited
Limit usage for current shell and subprocesses:
$ echo $$ > /sys/fs/cgroup/memory/memlimited/tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment