From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3232EC433DB for ; Tue, 12 Jan 2021 19:00:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A5E07230F9 for ; Tue, 12 Jan 2021 19:00:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5E07230F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D54676B00A2; Tue, 12 Jan 2021 14:00:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D04436B00A4; Tue, 12 Jan 2021 14:00:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1A416B00A5; Tue, 12 Jan 2021 14:00:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id A86956B00A2 for ; Tue, 12 Jan 2021 14:00:16 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3C90D362E for ; Tue, 12 Jan 2021 19:00:13 +0000 (UTC) X-FDA: 77698038306.11.bait25_2c0086d27517 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 08891180F8B81 for ; Tue, 12 Jan 2021 19:00:13 +0000 (UTC) X-HE-Tag: bait25_2c0086d27517 X-Filterd-Recvd-Size: 5351 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 19:00:12 +0000 (UTC) Received: by mail-lj1-f181.google.com with SMTP id u11so4011200ljo.13 for ; Tue, 12 Jan 2021 11:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cY7LiOljtRpl7NP8koJL4MoVHQoaXBOmsr02Iq9gODY=; b=oS8itD4fagD9W0NDK8IL/kpF+AARyhuR4yh5nmMvhIUGA47rDp5coomF6EJpC62Dyw ToCn3gbqEFz6X1QbaUx5S/wUB4rwXFX3vIQLHosV8OKDpieZPjmIQFrlOot9id0T2ty3 4eewXDIOfQ4y0CgYEJX/eHqHPQb2R2M1PU4iwsmW28SYKQTGiNSVZ9sMsdT68+7Pypmd K0vqQbdjwoua0+2ReyH6Wdu6+4Sl2BzxuQCtyf2H7rjiQy47dBC1majpefS2fz3Uq7mk bECOoYxXCtMKsol4oYi1r02vng0JwkyNbQNUqRuDsdNNLj+zirPpWCI/85QKmQyHEumQ KaPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cY7LiOljtRpl7NP8koJL4MoVHQoaXBOmsr02Iq9gODY=; b=MIpji99XDXeGZMGHhZYYyioPW7lfxXFBJJ9Keqck2HADdKTLmj7osXEzjz5g8uBuW7 eUNPXS5fVSqM5YPyv0DMIaDZkbtO+HlJDOHTWQGb9SFTSJuK5fodij8pgwQc5CjCa8Sg d7NqD/4fdj6dACGh5nnXdDdMl3/GWynJ7Pp/IVNs7phyAb0xWsTRhUbvKjNOtpRaQL+Y CBFjZvbQtshlKdoQq9moja2yTa+k2/6WZXNOTrSVdwfukaVG4dwHmFeRdhjny5lT8nP4 949+cxhKheNk2vlbSsYpCfUeDyvtjmldRj62N1VAYbC3ZnmcbsP+RDbFyjuZvvp8htV1 t3pQ== X-Gm-Message-State: AOAM531oisIuBJTSXmEk9Jlbx/KNjpx1WNEZ8BVvZU+DGCxEL0CTSmif 3MjT9MXpyujVAoQFhJKZHs5Suwl/WVUlGPYX6FIgMQ== X-Google-Smtp-Source: ABdhPJyeoR+rXzzgDzQiOMYj/rsdGmCt6Tdsk+6ir6pLcQbcgrKoCWr+GiQTGW/dIXR+H2ZOnjM+Tx/49XaFMo599FA= X-Received: by 2002:a2e:850f:: with SMTP id j15mr287189lji.34.1610478009184; Tue, 12 Jan 2021 11:00:09 -0800 (PST) MIME-Version: 1.0 References: <20210112163011.127833-1-hannes@cmpxchg.org> In-Reply-To: <20210112163011.127833-1-hannes@cmpxchg.org> From: Shakeel Butt Date: Tue, 12 Jan 2021 10:59:58 -0800 Message-ID: Subject: Re: [PATCH] mm: memcontrol: prevent starvation when writing memory.high To: Johannes Weiner Cc: Andrew Morton , Tejun Heo , Roman Gushchin , Michal Hocko , Linux MM , Cgroups , LKML , Kernel Team Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jan 12, 2021 at 9:12 AM Johannes Weiner wrote: > > 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. > Is this observed on real workload? > > 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. > > Fixes: 536d3bf261a2 ("mm: memcontrol: avoid workload stalls when lowering memory.high") > Cc: # 5.8+ > Reported-by: Tejun Heo > Signed-off-by: Johannes Weiner > --- > mm/memcontrol.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 605f671203ef..63a8d47c1cd3 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -6275,7 +6275,6 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, > > for (;;) { > unsigned long nr_pages = page_counter_read(&memcg->memory); > - unsigned long reclaimed; > > if (nr_pages <= high) > break; > @@ -6289,10 +6288,10 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, > 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--) Any particular reason to remove !reclaimed? > + if (!nr_retries--) > break; > } > > -- > 2.30.0 >