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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 E1047C433E6 for ; Fri, 5 Mar 2021 09:11:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 748A464EEE for ; Fri, 5 Mar 2021 09:11:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 748A464EEE Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EBD726B0007; Fri, 5 Mar 2021 04:11:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E46D86B0008; Fri, 5 Mar 2021 04:11:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE7826B000A; Fri, 5 Mar 2021 04:11:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id AEBAA6B0007 for ; Fri, 5 Mar 2021 04:11:34 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 729A02489 for ; Fri, 5 Mar 2021 09:11:34 +0000 (UTC) X-FDA: 77885252508.20.0F709A2 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf19.hostedemail.com (Postfix) with ESMTP id 67DF690009EE for ; Fri, 5 Mar 2021 09:11:33 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1614935493; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EzbUJaQzdHyWQWYArhmveTTGFRarGR/POWGz43IcYds=; b=WRAaCcQBvs+ROf3f9UYV/D5gQd6QjIR+GA8FQRtJa9yLj8pNsiAOX+ib91QiwXx0hYx4RR mn/4s+tYkhD/511Jt70xhn81DN9x2VKzKHKpFTYjldQOsPKUbcNBryoZvo3dIj3w0LXlXm RMeKmKWNxJzpK7WkhmjVLRsp90kFNSs= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DC864AF24; Fri, 5 Mar 2021 09:11:32 +0000 (UTC) Date: Fri, 5 Mar 2021 10:11:32 +0100 From: Michal Hocko To: Tim Chen Cc: Andrew Morton , Johannes Weiner , Vladimir Davydov , Dave Hansen , Ying Huang , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] mm: Fix dropped memcg from mem cgroup soft limit tree Message-ID: References: <8d35206601ccf0e1fe021d24405b2a0c2f4e052f.1613584277.git.tim.c.chen@linux.intel.com> <72cb8618-73af-ce08-d5d5-30cab30755a3@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <72cb8618-73af-ce08-d5d5-30cab30755a3@linux.intel.com> X-Stat-Signature: e6ko3dgmeji6ww5nu9oeos3nncydn6eb X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 67DF690009EE Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614935493-478334 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 Thu 04-03-21 09:35:08, Tim Chen wrote: > > > On 2/18/21 11:13 AM, Michal Hocko wrote: > > > > > Fixes: 4e41695356fb ("memory controller: soft limit reclaim on contention") > > Acked-by: Michal Hocko > > > > Thanks! > >> --- > >> mm/memcontrol.c | 6 +++++- > >> 1 file changed, 5 insertions(+), 1 deletion(-) > >> > >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c > >> index ed5cc78a8dbf..a51bf90732cb 100644 > >> --- a/mm/memcontrol.c > >> +++ b/mm/memcontrol.c > >> @@ -3505,8 +3505,12 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, > >> loop > MEM_CGROUP_MAX_SOFT_LIMIT_RECLAIM_LOOPS)) > >> break; > >> } while (!nr_reclaimed); > >> - if (next_mz) > >> + if (next_mz) { > >> + spin_lock_irq(&mctz->lock); > >> + __mem_cgroup_insert_exceeded(next_mz, mctz, excess); > >> + spin_unlock_irq(&mctz->lock); > >> css_put(&next_mz->memcg->css); > >> + } > >> return nr_reclaimed; > >> } > >> > >> -- > >> 2.20.1 > > > > Mel, > > Reviewing this patch a bit more, I realize that there is a chance that the removed > next_mz could be inserted back to the tree from a memcg_check_events > that happen in between. So we need to make sure that the next_mz > is indeed off the tree and update the excess value before adding it > back. Update the patch to the patch below. This scenario is certainly possible but it shouldn't really matter much as __mem_cgroup_insert_exceeded bails out when the node is on the tree already. -- Michal Hocko SUSE Labs