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=-6.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 42700C433DF for ; Tue, 20 Oct 2020 05:52:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 989152245F for ; Tue, 20 Oct 2020 05:52:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 989152245F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 93F6E6B005C; Tue, 20 Oct 2020 01:52:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F11F6B0062; Tue, 20 Oct 2020 01:52:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DF366B0068; Tue, 20 Oct 2020 01:52:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 4ECF36B005C for ; Tue, 20 Oct 2020 01:52:12 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E39E082CDEDD for ; Tue, 20 Oct 2020 05:52:11 +0000 (UTC) X-FDA: 77391233262.29.taste04_4210a6e2723d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id C391618086CD8 for ; Tue, 20 Oct 2020 05:52:11 +0000 (UTC) X-HE-Tag: taste04_4210a6e2723d X-Filterd-Recvd-Size: 3936 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 20 Oct 2020 05:52:11 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CE8A2AD7C; Tue, 20 Oct 2020 05:52:09 +0000 (UTC) References: <87lfg2ob83.fsf@suse.de> <20201019095812.25710-1-rpalethorpe@suse.com> User-agent: mu4e 1.4.13; emacs 27.1 From: Richard Palethorpe To: Shakeel Butt Cc: Linux MM , LKML , LTP List , Roman Gushchin , Johannes Weiner , Andrew Morton , Christoph Lameter , Michal Hocko , Tejun Heo , Vlastimil Babka Subject: Re: [PATCH v3] mm: memcg/slab: Stop reparented obj_cgroups from charging root Reply-To: rpalethorpe@suse.de In-reply-to: Date: Tue, 20 Oct 2020 06:52:08 +0100 Message-ID: <87mu0hwik7.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain 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: Hello Shakeel, Shakeel Butt writes: >> >> V3: Handle common case where use_hierarchy=1 and update description. >> >> mm/memcontrol.c | 7 +++++-- >> 1 file changed, 5 insertions(+), 2 deletions(-) >> >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >> index 6877c765b8d0..34b8c4a66853 100644 >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c >> @@ -291,7 +291,7 @@ static void obj_cgroup_release(struct percpu_ref *ref) >> >> spin_lock_irqsave(&css_set_lock, flags); >> memcg = obj_cgroup_memcg(objcg); >> - if (nr_pages) >> + if (nr_pages && (!mem_cgroup_is_root(memcg) || memcg->use_hierarchy)) > > If we have non-root memcg with use_hierarchy as 0 and this objcg was > reparented then this __memcg_kmem_uncharge() can potentially underflow > the page counter and give the same warning. Yes, although the kernel considers such a config to be broken, and prints a warning to the log, it does allow it. > > We never set root_mem_cgroup->objcg, so, no need to check for root I don't think that is relevant as we get the memcg from objcg->memcg which is set during reparenting. I suppose however, we can determine if the objcg was reparented by inspecting memcg->objcg. > here. I think checking just memcg->use_hierarchy should be sufficient. If we just check use_hierarchy then objects directly charged to the memcg where use_hierarchy=0 will not be uncharged. However, maybe it is better to check if it was reparented and if use_hierarchy=0. > >> __memcg_kmem_uncharge(memcg, nr_pages); >> list_del(&objcg->list); >> mem_cgroup_put(memcg); >> @@ -3100,6 +3100,7 @@ static bool consume_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes) >> static void drain_obj_stock(struct memcg_stock_pcp *stock) >> { >> struct obj_cgroup *old = stock->cached_objcg; >> + struct mem_cgroup *memcg; >> >> if (!old) >> return; >> @@ -3110,7 +3111,9 @@ static void drain_obj_stock(struct memcg_stock_pcp *stock) >> >> if (nr_pages) { >> rcu_read_lock(); >> - __memcg_kmem_uncharge(obj_cgroup_memcg(old), nr_pages); >> + memcg = obj_cgroup_memcg(old); >> + if (!mem_cgroup_is_root(memcg) || memcg->use_hierarchy) >> + __memcg_kmem_uncharge(memcg, nr_pages); >> rcu_read_unlock(); >> } >> >> -- >> 2.28.0 >> -- Thank you, Richard.