提交 536d3bf2 编写于 作者: R Roman Gushchin 提交者: Linus Torvalds

mm: memcontrol: avoid workload stalls when lowering memory.high

Memory.high limit is implemented in a way such that the kernel penalizes
all threads which are allocating a memory over the limit.  Forcing all
threads into the synchronous reclaim and adding some artificial delays
allows to slow down the memory consumption and potentially give some time
for userspace oom handlers/resource control agents to react.

It works nicely if the memory usage is hitting the limit from below,
however it works sub-optimal if a user adjusts memory.high to a value way
below the current memory usage.  It basically forces all workload threads
(doing any memory allocations) into the synchronous reclaim and sleep.
This makes the workload completely unresponsive for a long period of time
and can also lead to a system-wide contention on lru locks.  It can happen
even if the workload is not actually tight on memory and has, for example,
a ton of cold pagecache.

In the current implementation writing to memory.high causes an atomic
update of page counter's high value followed by an attempt to reclaim
enough memory to fit into the new limit.  To fix the problem described
above, all we need is to change the order of execution: try to push the
memory usage under the limit first, and only then set the new high limit.
Reported-by: NDomas Mituzas <domas@fb.com>
Signed-off-by: NRoman Gushchin <guro@fb.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: NShakeel Butt <shakeelb@google.com>
Acked-by: NMichal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Chris Down <chris@chrisdown.name>
Link: http://lkml.kernel.org/r/20200709194718.189231-1-guro@fb.comSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 eda330e5
...@@ -6213,8 +6213,6 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, ...@@ -6213,8 +6213,6 @@ static ssize_t memory_high_write(struct kernfs_open_file *of,
if (err) if (err)
return err; return err;
page_counter_set_high(&memcg->memory, high);
for (;;) { for (;;) {
unsigned long nr_pages = page_counter_read(&memcg->memory); unsigned long nr_pages = page_counter_read(&memcg->memory);
unsigned long reclaimed; unsigned long reclaimed;
...@@ -6238,6 +6236,8 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, ...@@ -6238,6 +6236,8 @@ static ssize_t memory_high_write(struct kernfs_open_file *of,
break; break;
} }
page_counter_set_high(&memcg->memory, high);
return nbytes; return nbytes;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册