mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, guro@fb.com, hannes@cmpxchg.org,
	linux-mm@kvack.org, mhocko@suse.com, mkoutny@suse.com,
	mm-commits@vger.kernel.org, shakeelb@google.com,
	stable@vger.kernel.org, tj@kernel.org,
	torvalds@linux-foundation.org
Subject: [patch 06/19] mm: memcontrol: prevent starvation when writing memory.high
Date: Sat, 23 Jan 2021 21:01:19 -0800	[thread overview]
Message-ID: <20210124050119.34lm1Gw1Q%akpm@linux-foundation.org> (raw)
In-Reply-To: <20210123210029.a7c704d0cab204683e41ad10@linux-foundation.org>

From: Johannes Weiner <hannes@cmpxchg.org>
Subject: mm: memcontrol: prevent starvation when writing memory.high

When a value is written to a cgroup's memory.high control file, the
write() context first tries to reclaim the cgroup to size before putting
the limit in place for the workload.  Concurrent charges from the workload
can keep such a write() looping in reclaim indefinitely.

In the past, a write to memory.high would first put the limit in place for
the workload, then do targeted reclaim until the new limit has been met -
similar to how we do it for memory.max.  This wasn't prone to the
described starvation issue.  However, this sequence could cause excessive
latencies in the workload, when allocating threads could be put into long
penalty sleeps on the sudden memory.high overage created by the write(),
before that had a chance to work it off.

Now that memory_high_write() performs reclaim before enforcing the new
limit, reflect that the cgroup may well fail to converge due to concurrent
workload activity.  Bail out of the loop after a few tries.

Link: https://lkml.kernel.org/r/20210112163011.127833-1-hannes@cmpxchg.org
Fixes: 536d3bf261a2 ("mm: memcontrol: avoid workload stalls when lowering memory.high")
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Reported-by: Tejun Heo <tj@kernel.org>
Acked-by: Roman Gushchin <guro@fb.com>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org>	[5.8+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/memcontrol.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

--- a/mm/memcontrol.c~mm-memcontrol-prevent-starvation-when-writing-memoryhigh
+++ a/mm/memcontrol.c
@@ -6273,7 +6273,6 @@ static ssize_t memory_high_write(struct
 
 	for (;;) {
 		unsigned long nr_pages = page_counter_read(&memcg->memory);
-		unsigned long reclaimed;
 
 		if (nr_pages <= high)
 			break;
@@ -6287,10 +6286,10 @@ static ssize_t memory_high_write(struct
 			continue;
 		}
 
-		reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_pages - high,
-							 GFP_KERNEL, true);
+		try_to_free_mem_cgroup_pages(memcg, nr_pages - high,
+					     GFP_KERNEL, true);
 
-		if (!reclaimed && !nr_retries--)
+		if (!nr_retries--)
 			break;
 	}
 
_

  parent reply	other threads:[~2021-01-24  5:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-24  5:00 incoming Andrew Morton
2021-01-24  5:00 ` [patch 01/19] x86/setup: don't remove E820_TYPE_RAM for pfn 0 Andrew Morton
2021-01-24  5:01 ` [patch 02/19] mm: fix initialization of struct page for holes in memory layout Andrew Morton
2021-01-24  5:01 ` [patch 03/19] mm: memcg/slab: optimize objcg stock draining Andrew Morton
2021-01-24  5:01 ` [patch 04/19] mm: memcg: fix memcg file_dirty numa stat Andrew Morton
2021-01-24  5:01 ` [patch 05/19] mm: fix numa stats for thp migration Andrew Morton
2021-01-24  5:01 ` Andrew Morton [this message]
2021-01-24 18:01   ` [patch 06/19] mm: memcontrol: prevent starvation when writing memory.high Shakeel Butt
2021-01-24 18:35     ` Linus Torvalds
2021-01-24  5:01 ` [patch 07/19] kasan: fix unaligned address is unhandled in kasan_remove_zero_shadow Andrew Morton
2021-01-24  5:01 ` [patch 08/19] kasan: fix incorrect arguments passing in kasan_add_zero_shadow Andrew Morton
2021-01-24  5:01 ` [patch 09/19] kasan: fix HW_TAGS boot parameters Andrew Morton
2021-01-24  5:01 ` [patch 10/19] kasan, mm: fix conflicts with init_on_alloc/free Andrew Morton
2021-01-24  5:01 ` [patch 11/19] kasan, mm: fix resetting page_alloc tags for HW_TAGS Andrew Morton
2021-01-24  5:01 ` [patch 12/19] ubsan: disable unsigned-overflow check for i386 Andrew Morton
2021-01-24  5:01 ` [patch 13/19] mm: fix page reference leak in soft_offline_page() Andrew Morton
2021-01-24  5:01 ` [patch 14/19] sparc/mm/highmem: flush cache and TLB Andrew Morton
2021-01-24  5:02 ` [patch 15/19] mm/highmem: prepare for overriding set_pte_at() Andrew Morton
2021-01-24  5:02 ` [patch 16/19] mips/mm/highmem: use set_pte() for kmap_local() Andrew Morton
2021-01-24  5:02 ` [patch 17/19] powerpc/mm/highmem: use __set_pte_at() " Andrew Morton
2021-01-24  5:02 ` [patch 18/19] proc_sysctl: fix oops caused by incorrect command parameters Andrew Morton
2021-01-24  5:02 ` [patch 19/19] MAINTAINERS: add a couple more files to the Clang/LLVM section Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210124050119.34lm1Gw1Q%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mkoutny@suse.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=shakeelb@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).