Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4206240pxu; Tue, 20 Oct 2020 10:43:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM8aV5mepFHh1yZq9aPD5RMJrtJI7DQ8zvtZ146t2M04UWM2ug405DuhVBkK3qWOXBaUs0 X-Received: by 2002:a17:906:5e49:: with SMTP id b9mr4309526eju.436.1603215835325; Tue, 20 Oct 2020 10:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603215835; cv=none; d=google.com; s=arc-20160816; b=jfrRf1ZY6JdUI1xKgZcSYPiFfzdp0yhVAL+VxxdilYD2xvJpkq96EWoN+50gCe5ZgI V2xpIs61o9TuKp5EBczVwROaaz4vBaL64XumCZGDcAmCve3hnWT62I9OkEGepilkOg3l 7ZHtka3Hi056GPhxBSY6SIq1ZCfAuxN/xRqnR+q7NPv156x0E4yUYGpmDOZU9UJQ5grl Jobe4NV4HXAHIm9BxhxpupDR1Od+1Dx0XMT2RPhltbZIeknjxz8RGuUo5rPB3RkPcNZC /9ScfPHH9J7qgi+lJF60eHqY9zGmHvg+fqJz/RymlbcKnznAD+uWsLeTZ5mPG6TWHKHL MdJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to :reply-to:subject:cc:to:from:user-agent:references; bh=gp0Y572r7t20aT/I35vxD5Xx3VvyUyF85a1/jBIFMQg=; b=AVBeGwwAhdRCuYq4IEXnivQOPBiQyjEJayzTDShdIqjl2xAL8vOoUa8USM+BcIr+3O 3qtWdtWcp3+j8/Rrz1wlFpLEj2gISpnHEz2Tmv/PWXoSEK9O8qyGmrT4uAz4sWBZ6HVT naiCepV0p1IVeRU34vx58walUJP6E+KtRkC8sOpQ4ixI2mlxls76cPiMphzTP5KF5hRU 7BT9YxzRMsn+tjit+I0APpOwlACo3z/u4rjtvNw74m1jOhHwvnE7tJ/W3CI2+2U0lMRO KyXDrr3Ffmlxmz9GtGRffw34YSTlTBfalYCFolvN+OzHGZYQM2fVplvmRWOS3lB6PWAB q4Kg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si1867208ejh.43.2020.10.20.10.43.32; Tue, 20 Oct 2020 10:43:55 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391753AbgJTFwL (ORCPT + 99 others); Tue, 20 Oct 2020 01:52:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:54234 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391744AbgJTFwL (ORCPT ); Tue, 20 Oct 2020 01:52:11 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.