Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1862710pxb; Fri, 5 Mar 2021 01:13:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9eBXfOeAJVWYOuN5cJ1xADlkSpiaVt/3OjP8y8hSMVi1oqFpv/T4WLSqO++bNY/apnz1B X-Received: by 2002:aa7:c9cf:: with SMTP id i15mr8222948edt.296.1614935606521; Fri, 05 Mar 2021 01:13:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614935606; cv=none; d=google.com; s=arc-20160816; b=ai8M/uSO8dfUBRtN0kIx3DZFJs0oeZVFHDbYzKwTFcxWuDXYY6Jv9l0734i3UT77IS II25uGfAaqtxODNYolABkNDBNLSuZB13WYV+We9gcWKLrsMMSOT5umEpqgHNWiXk8SBp I6O3zC5ncCATQSkZtx7ZoAO6uqKGVP18R+jHiNMhrs3ooSlA4CwI2FYZ2yw/aAJU4ZZO QoSYBPtSa6XaHqkK9R9rG5YKul9k6mNfpdLzAA+dBMyDuXrYnwTrdotn8SuOfI9mI1N9 Pz6RWuSSLivrABr2aEiLIIeLz351G27opdmIcYONqZ6JfWrHQYB+7mdsu6fGelGgDmaY Fmhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EzbUJaQzdHyWQWYArhmveTTGFRarGR/POWGz43IcYds=; b=UU8vOwW9SMHppsJEFJ+Kl2AB8RZQ8RHLekFzHCQbNlP4kG2p4m9KxstVRPj5Kz5tvd tnYTJQU8Edti/w5v7OSPr/H9PhdhfF1VuEBp/5qOWpuOUw0WpliX02aDqiTmpEur0bFu +Ib+3uX/0xe9G4mNiZTL8C+8zafzRha6Tfg5airygktwj+7OerbN3CA6JRT5Sx2Yeq8k 6Fq/jFFzbCDMFCUxJ5IVXMxbLVzpQ+/MgfjRZ2/c08MmXXCRNgWZlctaBcNgPUJYbFOU Ci7s+BlY4HKRchGL1RX20Ym2zFweVY+8SkPUPhb9859pp/qN5ct4tr38y+aDx2WLGr55 0irw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=WRAaCcQB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si1058508ejx.329.2021.03.05.01.13.03; Fri, 05 Mar 2021 01:13:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=WRAaCcQB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229528AbhCEJMF (ORCPT + 99 others); Fri, 5 Mar 2021 04:12:05 -0500 Received: from mx2.suse.de ([195.135.220.15]:47222 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbhCEJLe (ORCPT ); Fri, 5 Mar 2021 04:11:34 -0500 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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