Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4812317pxb; Mon, 15 Feb 2021 01:42:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwztBrbfl0qct8LCwh26wF0Hanuq6KALWEshirHPqwve2bBL1a/Zn49H74LTt74iX5IpKV X-Received: by 2002:a05:6402:26c9:: with SMTP id x9mr14645951edd.365.1613382150830; Mon, 15 Feb 2021 01:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613382150; cv=none; d=google.com; s=arc-20160816; b=psSRhYdORPU+7uhRmmhY1Jn0ztpdai4G5UDA+Uc/R8pZjVBDrIeuqP8aN9uaVUIIXC 4eQXSsd3lwkwKZvEh1GrSgrX6ohCArwXEsNY0GOhWty39iRH1bVagveLvq8+4+aCbUkt 8f3OmQHcY3488SdhPkrcbg47wSowj4IpvGnhmp40ldPYHp1oHJBAv5qO1VGAJnCF1Hhh vZiJTminsnrThP3T8AsxNUZjJg/Fsn/JgHQkBqrZsGjSC2UCDhSzgle26CssU1B52G4W eN+YUgkXvPolnDxidsZDZy2o0iUuRw7zACkfXy2Dt9uukHx5h+Xb/gkjFwm12ZctXEm1 aZWQ== 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=XuaD4qfV4mnOvBqozHEgf1LOzpJnPhnAAtC97LcZGCk=; b=Nbkh2GTI8Rz1Pwf+DGlcjtY4vqf+aeA6rjwUKSWPIBSk0NRmNG9UYoZS2Vr2HUoTp8 WNGV3gUGb4+qedaMpF9CClBsQtGEMm8eu6ERSR+ZyaWg7prB5aD26RsY2SdZ2pmYc70p hmTcXUUtss9jq1NtEMBhZECHRPVJ6YcmuV0sjelyQDUiflONfZt+3xD01ceCbqKYlD3m Dcjpagn1wxZEZ7vnXvYhiLPeA3Y+/3664yDj0sp80Icim7XSVx8wq82YrmlJ4dpPmTcX D5jNkrS2Cmp8FLUNEXqKTRsqh/nFxW7H8epomKOmrQA6amob3D3Pi8FUGxyUVcTNfQSb nmmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=CtjGqMQA; 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 l11si11585676edb.238.2021.02.15.01.42.07; Mon, 15 Feb 2021 01:42:30 -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=CtjGqMQA; 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 S230226AbhBOJip (ORCPT + 99 others); Mon, 15 Feb 2021 04:38:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:32834 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbhBOJig (ORCPT ); Mon, 15 Feb 2021 04:38:36 -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=1613381870; 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=XuaD4qfV4mnOvBqozHEgf1LOzpJnPhnAAtC97LcZGCk=; b=CtjGqMQAdl3bX8gk24RXRcfb1vzr7ejVovQ5dy3zYQPS92ojUHyx58gd/mPqesbnhYBhRI Nl0YE7gjJflJWnHS420wujgmc+H1PDNYKh7T0dk1k0HioJZaZqBEmg69kH/C9v/q3jU/Ng yTFf3dXJ15zn2BZEeCSxlVayWoauMcw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 08165AD3E; Mon, 15 Feb 2021 09:37:50 +0000 (UTC) Date: Mon, 15 Feb 2021 10:37:49 +0100 From: Michal Hocko To: Muchun Song Cc: hannes@cmpxchg.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] mm: memcontrol: add missing memcg_oom_recover() when uncharge slab page Message-ID: References: <20210212170159.32153-1-songmuchun@bytedance.com> <20210212170159.32153-2-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210212170159.32153-2-songmuchun@bytedance.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat 13-02-21 01:01:57, Muchun Song wrote: > When we uncharge a page, we wake up oom victims when the memcg oom > handling is outsourced to the userspace. The uncharge_batch do that > for normal and kmem pages but not slab pages. It is likely an > omission. So add the missing memcg_oom_recover() to > __memcg_kmem_uncharge(). And the function of memory.oom_control > is only suitable for cgroup v1. So guard this test (memcg->under_oom) > by the cgroup_subsys_on_dfl(memory_cgrp_subsys). User visible effects please? I believe there are unlikely any. I do not have any data at hands but I would expect that slab pages freeing wouldn't really contribute much to help a memcg out of oom without an external intervention for oom_disabled case. If that is the case then make it explicit to the changelog. If you have workloads which do see a suboptimal behavior then please mention that as well. This is important for future readers to understand the code and motivation behind it. Also, now I guess I can see why you have decided to not do cgroup v2 check directly in memcg_oom_recover. You do not want to repeat the check in paths which already do do check for you. That is fine. Appart from the uncharging path, none of the others is really a hot path so this is likely a reasonable decision. I have a minor comment below. > Signed-off-by: Muchun Song > --- > mm/memcontrol.c | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 7afca9677693..a3f26522765a 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3126,8 +3126,10 @@ static int __memcg_kmem_charge(struct mem_cgroup *memcg, gfp_t gfp, > */ > static void __memcg_kmem_uncharge(struct mem_cgroup *memcg, unsigned int nr_pages) > { > - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) > + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { > page_counter_uncharge(&memcg->kmem, nr_pages); > + memcg_oom_recover(memcg); > + } > > refill_stock(memcg, nr_pages); > } > @@ -6806,11 +6808,15 @@ static void uncharge_batch(const struct uncharge_gather *ug) > > if (!mem_cgroup_is_root(ug->memcg)) { > page_counter_uncharge(&ug->memcg->memory, ug->nr_pages); > - if (do_memsw_account()) > - page_counter_uncharge(&ug->memcg->memsw, ug->nr_pages); > - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && ug->nr_kmem) > - page_counter_uncharge(&ug->memcg->kmem, ug->nr_kmem); > - memcg_oom_recover(ug->memcg); > + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { > + if (!cgroup_memory_noswap) > + page_counter_uncharge(&ug->memcg->memsw, > + ug->nr_pages); This is functionally equivalent but I am not sure this will make a further maintainability easier. do_memsw_account check is used at many other places and it is a general helper which you have split into its current implementation. This makes any future changes more tricky. Is this miro-optimization worth it? > + if (ug->nr_kmem) > + page_counter_uncharge(&ug->memcg->kmem, > + ug->nr_kmem); > + memcg_oom_recover(ug->memcg); > + } > } > > local_irq_save(flags); > -- > 2.11.0 -- Michal Hocko SUSE Labs