Skip to contentSkip to conversation

Documentation: Clarify usage of memory limits

PATCH Applied Dan Schatzberg 5 participants 8 messages Jun 1, 2023 – Jun 6, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation: Clarify usage of memory limits

The existing documentation refers to memory.high as the "main mechanism to control memory usage." This seems incorrect to me - memory.high can result in reclaim pressure which simply leads to stalls unless some external component observes and actions on it (e.g. systemd-oomd can be used for this purpose). While this is feasible, users are unaware of this interaction and are led to believe that memory.high alone is an effective mechanism for limiting memory.

The documentation should recommend the use of memory.max as the effective way to enforce memory limits - it triggers reclaim and results in OOM kills by itself.

---
 Documentation/admin-guide/cgroup-v2.rst | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +10 -12
index f67c0829350b..e592a9364473 100644
@@ -1213,23 +1213,25 @@ PAGE_SIZE multiple when read back.
 	A read-write single value file which exists on non-root
 	cgroups.  The default is "max".
 
-	Memory usage throttle limit.  This is the main mechanism to
-	control memory usage of a cgroup.  If a cgroup's usage goes
+	Memory usage throttle limit.  If a cgroup's usage goes
 	over the high boundary, the processes of the cgroup are
 	throttled and put under heavy reclaim pressure.
 
 	Going over the high limit never invokes the OOM killer and
-	under extreme conditions the limit may be breached.
+	under extreme conditions the limit may be breached. The high
+	limit should be used in scenarios where an external process
+	monitors the limited cgroup to alleviate heavy reclaim
+	pressure.
 
   memory.max
 	A read-write single value file which exists on non-root
 	cgroups.  The default is "max".
 
-	Memory usage hard limit.  This is the final protection
-	mechanism.  If a cgroup's memory usage reaches this limit and
-	can't be reduced, the OOM killer is invoked in the cgroup.
-	Under certain circumstances, the usage may go over the limit
-	temporarily.
+	Memory usage hard limit.  This is the main mechanism to limit
+	memory usage of a cgroup.  If a cgroup's memory usage reaches
+	this limit and can't be reduced, the OOM killer is invoked in
+	the cgroup. Under certain circumstances, the usage may go
+	over the limit temporarily.
 
 	In default configuration regular 0-order allocations always
 	succeed unless OOM killer chooses current task as a victim.
@@ -1238,10 +1240,6 @@ PAGE_SIZE multiple when read back.
 	Caller could retry them differently, return into userspace
 	as -ENOMEM or silently ignore in cases like disk readahead.
 
-	This is the ultimate protection mechanism.  As long as the
-	high limit is used and monitored properly, this limit's
-	utility is limited to providing the final safety net.
-
   memory.reclaim
 	A write-only nested-keyed file which exists for all cgroups.
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Dan Schatzberg

The existing documentation refers to memory.high as the "main mechanism to control memory usage." This seems incorrect to me - memory.high can result in reclaim pressure which simply leads to stalls unless some external component observes and actions on it (e.g. systemd-oomd can be used for this purpose). While this is feasible, users are unaware of this interaction and are led to believe that memory.high alone is an effective mechanism for limiting memory.

The documentation should recommend the use of memory.max as the effective way to enforce memory limits - it triggers reclaim and results in OOM kills by itself.

That is not how my understanding of memory.high works. When memory usage goes past memory.high, memory reclaim will be initiated to reclaim the memory back. Stall happens when memory.usage keep increasing like by consuming memory faster than what memory reclaim can recover. When memory.max is reached, OOM killer will then kill off the tasks.

IOW, memory consumption should not go past memory.high in normal usage scenario. I believe what you describe here isn't quite correct.

Cheers,
Longman

Quoted 54 lines
---
  Documentation/admin-guide/cgroup-v2.rst | 22 ++++++++++------------
  1 file changed, 10 insertions(+), 12 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +10 -12
index f67c0829350b..e592a9364473 100644
@@ -1213,23 +1213,25 @@ PAGE_SIZE multiple when read back.
  	A read-write single value file which exists on non-root
  	cgroups.  The default is "max".
 
-	Memory usage throttle limit.  This is the main mechanism to
-	control memory usage of a cgroup.  If a cgroup's usage goes
+	Memory usage throttle limit.  If a cgroup's usage goes
  	over the high boundary, the processes of the cgroup are
  	throttled and put under heavy reclaim pressure.
 
  	Going over the high limit never invokes the OOM killer and
-	under extreme conditions the limit may be breached.
+	under extreme conditions the limit may be breached. The high
+	limit should be used in scenarios where an external process
+	monitors the limited cgroup to alleviate heavy reclaim
+	pressure.
 
    memory.max
  	A read-write single value file which exists on non-root
  	cgroups.  The default is "max".
 
-	Memory usage hard limit.  This is the final protection
-	mechanism.  If a cgroup's memory usage reaches this limit and
-	can't be reduced, the OOM killer is invoked in the cgroup.
-	Under certain circumstances, the usage may go over the limit
-	temporarily.
+	Memory usage hard limit.  This is the main mechanism to limit
+	memory usage of a cgroup.  If a cgroup's memory usage reaches
+	this limit and can't be reduced, the OOM killer is invoked in
+	the cgroup. Under certain circumstances, the usage may go
+	over the limit temporarily.
 
  	In default configuration regular 0-order allocations always
  	succeed unless OOM killer chooses current task as a victim.
@@ -1238,10 +1240,6 @@ PAGE_SIZE multiple when read back.
  	Caller could retry them differently, return into userspace
  	as -ENOMEM or silently ignore in cases like disk readahead.
 
-	This is the ultimate protection mechanism.  As long as the
-	high limit is used and monitored properly, this limit's
-	utility is limited to providing the final safety net.
-
    memory.reclaim
  	A write-only nested-keyed file which exists for all cgroups.
 
maintainer
#2 lore raw
Quoted 13 lines · Waiman Long
Quoted 11 lines · Dan Schatzberg

The existing documentation refers to memory.high as the "main mechanism to control memory usage." This seems incorrect to me - memory.high can result in reclaim pressure which simply leads to stalls unless some external component observes and actions on it (e.g. systemd-oomd can be used for this purpose). While this is feasible, users are unaware of this interaction and are led to believe that memory.high alone is an effective mechanism for limiting memory.

The documentation should recommend the use of memory.max as the effective way to enforce memory limits - it triggers reclaim and results in OOM kills by itself.

Quoted 5 lines

That is not how my understanding of memory.high works. When memory usage goes past memory.high, memory reclaim will be initiated to reclaim the memory back. Stall happens when memory.usage keep increasing like by consuming memory faster than what memory reclaim can recover. When memory.max is reached, OOM killer will then kill off the tasks.

This was the initial plan indeed: Slow down the workload and thus slow the growth; hope that the workload recovers with voluntary frees; set memory.max as a safety if it keeps going beyond.

This never panned out. Once workloads are stuck, they might not back down on their own. By increasingly slowing growth, it becomes harder and harder for them to reach the memory.max intervention point.

It's a very brittle configuration strategy. Unless you very carefully calibrate memory.high and memory.max together with awareness of the throttling algorithm, workloads that hit memory.high will just go to sleep indefinitely. They require outside intervention that either adjusts limits or implements kill policies based on observed sleeps (they're reported as pressure via psi).

So the common usecases today end up being that memory.max is for enforcing kernel OOM kills, and memory.high is a tool to implement userspace OOM killing policies.

Dan is right to point out the additional expectations for userspace management when memory.high is in used. And memory.max is still the primary, works-out-of-the-box method of memory containment.

#3 lore raw
Quoted 33 lines · Johannes Weiner
Quoted 9 lines · Waiman Long
Quoted 8 lines · Dan Schatzberg

The existing documentation refers to memory.high as the "main mechanism to control memory usage." This seems incorrect to me - memory.high can result in reclaim pressure which simply leads to stalls unless some external component observes and actions on it (e.g. systemd-oomd can be used for this purpose). While this is feasible, users are unaware of this interaction and are led to believe that memory.high alone is an effective mechanism for limiting memory.

Quoted 8 lines
Quoted 3 lines

The documentation should recommend the use of memory.max as the effective way to enforce memory limits - it triggers reclaim and results in OOM kills by itself.

That is not how my understanding of memory.high works. When memory usage goes past memory.high, memory reclaim will be initiated to reclaim the memory back. Stall happens when memory.usage keep increasing like by consuming memory faster than what memory reclaim can recover. When memory.max is reached, OOM killer will then kill off the tasks.

This was the initial plan indeed: Slow down the workload and thus slow the growth; hope that the workload recovers with voluntary frees; set memory.max as a safety if it keeps going beyond.

This never panned out. Once workloads are stuck, they might not back down on their own. By increasingly slowing growth, it becomes harder and harder for them to reach the memory.max intervention point.

It's a very brittle configuration strategy. Unless you very carefully calibrate memory.high and memory.max together with awareness of the throttling algorithm, workloads that hit memory.high will just go to sleep indefinitely. They require outside intervention that either adjusts limits or implements kill policies based on observed sleeps (they're reported as pressure via psi).

Quoted 7 lines

So the common usecases today end up being that memory.max is for enforcing kernel OOM kills, and memory.high is a tool to implement userspace OOM killing policies.

Dan is right to point out the additional expectations for userspace management when memory.high is in used. And memory.max is still the primary, works-out-of-the-box method of memory containment.

Thanks for clarification. I have to reset my false assumption.

Cheers,
Longman

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Dan Schatzberg
Quoted 8 lines · Dan Schatzberg

The existing documentation refers to memory.high as the "main mechanism to control memory usage." This seems incorrect to me - memory.high can result in reclaim pressure which simply leads to stalls unless some external component observes and actions on it (e.g. systemd-oomd can be used for this purpose). While this is feasible, users are unaware of this interaction and are led to believe that memory.high alone is an effective mechanism for limiting memory.

Quoted 5 lines

The documentation should recommend the use of memory.max as the effective way to enforce memory limits - it triggers reclaim and results in OOM kills by itself.

Yeah, this is quite stale. How this ended up working in practice is a bit different from how we initially conceived it.

Thanks for updating it.

Acked-by on v1 1/1
#5 lore raw
In reply to Dan Schatzberg
Quoted 8 lines · Dan Schatzberg

The existing documentation refers to memory.high as the "main mechanism to control memory usage." This seems incorrect to me - memory.high can result in reclaim pressure which simply leads to stalls unless some external component observes and actions on it (e.g. systemd-oomd can be used for this purpose). While this is feasible, users are unaware of this interaction and are led to believe that memory.high alone is an effective mechanism for limiting memory.

Quoted 5 lines

The documentation should recommend the use of memory.max as the effective way to enforce memory limits - it triggers reclaim and results in OOM kills by itself.

Oof, the documentation is very out of date indeed -- no wonder people were confused by other advice to only use memory.high with something external monitoring the cgroup.

Thanks!

Quoted 56 lines

---
Documentation/admin-guide/cgroup-v2.rst | 22 ++++++++++------------

1 file changed, 10 insertions(+), 12 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +10 -12
index f67c0829350b..e592a9364473 100644
@@ -1213,23 +1213,25 @@ PAGE_SIZE multiple when read back.
 	A read-write single value file which exists on non-root
 	cgroups.  The default is "max".
 
-	Memory usage throttle limit.  This is the main mechanism to
-	control memory usage of a cgroup.  If a cgroup's usage goes
+	Memory usage throttle limit.  If a cgroup's usage goes
 	over the high boundary, the processes of the cgroup are
 	throttled and put under heavy reclaim pressure.
 
 	Going over the high limit never invokes the OOM killer and
-	under extreme conditions the limit may be breached.
+	under extreme conditions the limit may be breached. The high
+	limit should be used in scenarios where an external process
+	monitors the limited cgroup to alleviate heavy reclaim
+	pressure.
 
  memory.max
 	A read-write single value file which exists on non-root
 	cgroups.  The default is "max".
 
-	Memory usage hard limit.  This is the final protection
-	mechanism.  If a cgroup's memory usage reaches this limit and
-	can't be reduced, the OOM killer is invoked in the cgroup.
-	Under certain circumstances, the usage may go over the limit
-	temporarily.
+	Memory usage hard limit.  This is the main mechanism to limit
+	memory usage of a cgroup.  If a cgroup's memory usage reaches
+	this limit and can't be reduced, the OOM killer is invoked in
+	the cgroup. Under certain circumstances, the usage may go
+	over the limit temporarily.
 
 	In default configuration regular 0-order allocations always
 	succeed unless OOM killer chooses current task as a victim.
@@ -1238,10 +1240,6 @@ PAGE_SIZE multiple when read back.
 	Caller could retry them differently, return into userspace
 	as -ENOMEM or silently ignore in cases like disk readahead.
 
-	This is the ultimate protection mechanism.  As long as the
-	high limit is used and monitored properly, this limit's
-	utility is limited to providing the final safety net.
-
  memory.reclaim
 	A write-only nested-keyed file which exists for all cgroups.
 
Signature · 1 line
2.34.1
maintainer Applied
#6 lore raw
In reply to Dan Schatzberg

Hello,

Quoted 8 lines · Dan Schatzberg

The existing documentation refers to memory.high as the "main mechanism to control memory usage." This seems incorrect to me - memory.high can result in reclaim pressure which simply leads to stalls unless some external component observes and actions on it (e.g. systemd-oomd can be used for this purpose). While this is feasible, users are unaware of this interaction and are led to believe that memory.high alone is an effective mechanism for limiting memory.

Quoted 5 lines

The documentation should recommend the use of memory.max as the effective way to enforce memory limits - it triggers reclaim and results in OOM kills by itself.

Applied to cgroup/for-6.4-fixes. Please see below for a comment tho.

Quoted 6 lines
Documentation/admin-guide/cgroup-v2.rst +0 -2
@@ -1213,23 +1213,25 @@ PAGE_SIZE multiple when read back.
 	A read-write single value file which exists on non-root
 	cgroups.  The default is "max".
 
-	Memory usage throttle limit.  This is the main mechanism to
-	control memory usage of a cgroup.  If a cgroup's usage goes

Documentation/admin-guide/cgroup-v2.rst PAGE_SIZE multiple when read back. · line 1224

Quoted 10 lines
Documentation/admin-guide/cgroup-v2.rst +5 -1
+	Memory usage throttle limit.  If a cgroup's usage goes
 	over the high boundary, the processes of the cgroup are
 	throttled and put under heavy reclaim pressure.
 
 	Going over the high limit never invokes the OOM killer and
-	under extreme conditions the limit may be breached.
+	under extreme conditions the limit may be breached. The high
+	limit should be used in scenarios where an external process
+	monitors the limited cgroup to alleviate heavy reclaim
+	pressure.

I think it'd be helpful to provide pointers to oomd and systemd's implementation of it here.

Thanks.

Signature · 1 line
tejun