linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memcontrol: stop resize loop if limit was changed again
@ 2024-03-20 10:03 Pavel Tikhomirov
  2024-03-20 10:28 ` Michal Hocko
  2024-03-20 17:09 ` Waiman Long
  0 siblings, 2 replies; 9+ messages in thread
From: Pavel Tikhomirov @ 2024-03-20 10:03 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
	Muchun Song, Andrew Morton
  Cc: Vladimir Davydov, cgroups, linux-mm, linux-kernel, kernel,
	Pavel Tikhomirov

In memory_max_write() we first set memcg->memory.max and only then
try to enforce it in loop. What if while we are in loop someone else
have changed memcg->memory.max but we are still trying to enforce
the old value? I believe this can lead to nasty consequence like getting
an oom on perfectly fine cgroup within it's limits or excess reclaim.

We also have exactly the same thing in memory_high_write().

So let's stop enforcing old limits if we already have a new ones.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 mm/memcontrol.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 61932c9215e7..81b303728491 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6769,6 +6769,9 @@ static ssize_t memory_high_write(struct kernfs_open_file *of,
 		unsigned long nr_pages = page_counter_read(&memcg->memory);
 		unsigned long reclaimed;
 
+		if (memcg->memory.high != high)
+			break;
+
 		if (nr_pages <= high)
 			break;
 
@@ -6817,6 +6820,9 @@ static ssize_t memory_max_write(struct kernfs_open_file *of,
 	for (;;) {
 		unsigned long nr_pages = page_counter_read(&memcg->memory);
 
+		if (memcg->memory.max != max)
+			break;
+
 		if (nr_pages <= max)
 			break;
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-21  5:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-20 10:03 [PATCH] mm/memcontrol: stop resize loop if limit was changed again Pavel Tikhomirov
2024-03-20 10:28 ` Michal Hocko
2024-03-20 10:55   ` Pavel Tikhomirov
2024-03-20 12:09     ` Michal Hocko
2024-03-20 22:38     ` Roman Gushchin
2024-03-20 17:09 ` Waiman Long
2024-03-20 17:12   ` Michal Hocko
2024-03-20 17:38     ` Michal Hocko
2024-03-21  5:15   ` Pavel Tikhomirov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox