Skip to content

RFC memcg: Enable fine-grained per process memory control

Waiman Long cgroups linux-doc linux-fsdevel linux-mm lkml oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest8 patches 33 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8memcg: Enable fine-grained control of over memory.high actioninclude/linux/memcontrol.h include/linux/sched.h include/uapi/linux/prctl.h +2 more+178 -07 replies
2/8memcg, mm: Return ENOMEM or delay if memcg_over_limitinclude/linux/sched.h kernel/fork.c mm/memcontrol.c +3 more+61 -20 replies
3/8memcg: Allow the use of task RSS memory as over-high action triggerinclude/linux/memcontrol.h include/linux/sched.h include/uapi/linux/prctl.h +2 more+46 -90 replies
4/8fs/proc: Support a new procfs memctl filefs/proc/base.c+109 -00 replies
5/8memcg: Allow direct per-task memory limit checkinginclude/uapi/linux/prctl.h mm/memcontrol.c+40 -160 replies
6/8memcg: Introduce additional memory control slowdown if neededmm/memcontrol.c+16 -60 replies
7/8memcg: Enable logging of memory control mitigation actioninclude/uapi/linux/prctl.h mm/memcontrol.c+34 -10 replies
8/8memcg: Add over-high action prctl() documentationDocumentation/userspace-api/index.rst Documentation/userspace-api/memcontrol.rst+175 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/8] memcg: Enable fine-grained per process memory control

Memory controller can be used to control and limit the amount of physical memory used by a task. When a limit is set in "memory.high" in a v2 non-root memory cgroup, the memory controller will try to reclaim memory if the limit has been exceeded. Normally, that will be enough to keep the physical memory consumption of tasks in the memory cgroup to be around or below the "memory.high" limit.

Sometimes, memory reclaim may not be able to recover memory in a rate that can catch up to the physical memory allocation rate. In this case, the physical memory consumption will keep on increasing. When it reaches "memory.max" for memory cgroup v2 or when the system is running out of free memory, the OOM killer will be invoked to kill some tasks to free up additional memory. However, one has little control of which tasks are going to be killed by an OOM killer. Killing tasks that hold some important resources without freeing them first can create other system problems down the road.

Users who do not want the OOM killer to be invoked to kill random tasks in an out-of-memory situation can use the memory control facility provided by this new patchset via prctl(2) to better manage the mitigation action that needs to be performed to various tasks when the specified memory limit is exceeded with memory cgroup v2 being used.

The currently supported mitigation actions include the followings:

1) Return ENOMEM for some syscalls that allocate or handle memory
2) Slow down the process for memory reclaim to catch up
3) Send a specific signal to the task
4) Kill the task

The users that want better memory control for their applicatons can either modify their applications to call the prctl(2) syscall directly with the new memory control command code or write the desired action to the newly provided memctl procfs files of their applications provided that those applications run in a non-root v2 memory cgroup.

Waiman Long (8):
memcg: Enable fine-grained control of over memory.high action memcg, mm: Return ENOMEM or delay if memcg_over_limit
memcg: Allow the use of task RSS memory as over-high action trigger fs/proc: Support a new procfs memctl file
memcg: Allow direct per-task memory limit checking
memcg: Introduce additional memory control slowdown if needed
memcg: Enable logging of memory control mitigation action
memcg: Add over-high action prctl() documentation

 Documentation/userspace-api/index.rst      |   1 +
 Documentation/userspace-api/memcontrol.rst | 174 ++++++++++++++++
 fs/proc/base.c                             | 109 ++++++++++
 include/linux/memcontrol.h                 |   4 +
 include/linux/sched.h                      |  24 +++
 include/uapi/linux/prctl.h                 |  48 +++++
 kernel/fork.c                              |   1 +
 kernel/sys.c                               |  16 ++
 mm/memcontrol.c                            | 227 +++++++++++++++++++++
 mm/mlock.c                                 |   6 +
 mm/mmap.c                                  |  12 ++
 mm/mprotect.c                              |   3 +
 12 files changed, 625 insertions(+)
 create mode 100644 Documentation/userspace-api/memcontrol.rst
Signature · 1 line
2.18.1