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.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 50B9AC2D0DC for ; Fri, 27 Dec 2019 01:10:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1563B20740 for ; Fri, 27 Dec 2019 01:10:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K7YTp5qR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1563B20740 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9C74E8E0006; Thu, 26 Dec 2019 20:10:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 977688E0001; Thu, 26 Dec 2019 20:10:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88D5F8E0006; Thu, 26 Dec 2019 20:10:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 6F9A98E0001 for ; Thu, 26 Dec 2019 20:10:32 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 199D58249980 for ; Fri, 27 Dec 2019 01:10:32 +0000 (UTC) X-FDA: 76309141104.01.cub16_49ead9451257 X-HE-Tag: cub16_49ead9451257 X-Filterd-Recvd-Size: 5903 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Dec 2019 01:10:31 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id v18so24581824iol.2 for ; Thu, 26 Dec 2019 17:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Q1GRFRPnNQ0j9VDLy5xDDK1SFhmCSZ3Lj0rMxOvVuSg=; b=K7YTp5qR4EqXRMxB5KkC84WtoJ1zhuFYs9U7GEoZwVfu8dOC8/Dgjyfn85vqZBGCX5 m8/tI8gj0uF78Lp7M/cqlfs8C7R68l19Tj/Wgqy3g0KnAHzuO48OsERyXBQJMq1mw6ca 6+dNtktRqbwEJc6sBBtQ4P7mEKPmJwH9A/pyO/laVKcnEwhdwadnWV5CADc1CWoWiZKo Xt2OP2NXnXyRmAiB1g7EqhTjA252SPmy26YOnSGLqQbhGD0O5+BP4jA3wM6QMvHqYTya 4S0ErHoQled9NQQYm/8TsRb9bCOkpFgJxU9JfhJgWXkC2tDAcTsf1sMQTXmh/11/qC+E 7cjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Q1GRFRPnNQ0j9VDLy5xDDK1SFhmCSZ3Lj0rMxOvVuSg=; b=XEgn3iSmRc64Ep8TZ5c79icAnJXDg+RK4piZHSkY8g3AHnnNWmFdxVyk4t84mpkKdp aWZHJFxTMjkcMHZpRTEC/sVUcb7qKqJTeSHaEA8hpkxfoRex2JgPM5AlKG3ljRN4BFYy M9BGtrLuEWVoptPJn5m6srqcNdeiIgDXc9FCJQ5E4rLmDD9Y/VWycFaGzZ5YEGoJ880U aEzjsMYTLDwi2VilL+/0zan0/proXLh9kiMXl/uPm6TowliNN1khNTydd0o3ccd3Kw6P 2avLXvJxdIPMX6w34gR83lVLLqxNqf3uW+POmkdQPUL0bMGMGF0wjDnb7lF4bVzx3Qjn LYrQ== X-Gm-Message-State: APjAAAWQ0R0LBqeehMH9+mq0rdnhHdIfB4wavOtCVpZ0lk/0PxnqzArk BKdXTds6NVlKYp2NmdlsDsYCTsMXrr6GEJbA/hM= X-Google-Smtp-Source: APXvYqyMKdoNufCBdhXPbrHoQ1wdGuHcK5iZZdpGdKEeCSqRti5/yUqSvBcWsDbS2qdfF/k+ntJkfMRTFpnW/G9fcOY= X-Received: by 2002:a6b:b941:: with SMTP id j62mr34860236iof.168.1577409030866; Thu, 26 Dec 2019 17:10:30 -0800 (PST) MIME-Version: 1.0 References: <1577174006-13025-1-git-send-email-laoar.shao@gmail.com> <1577174006-13025-3-git-send-email-laoar.shao@gmail.com> <20191226213619.GB22734@tower.dhcp.thefacebook.com> In-Reply-To: <20191226213619.GB22734@tower.dhcp.thefacebook.com> From: Yafang Shao Date: Fri, 27 Dec 2019 09:09:54 +0800 Message-ID: Subject: Re: [PATCH v2 2/5] mm, memcg: introduce MEMCG_PROT_SKIP for memcg zero usage case To: Roman Gushchin Cc: "hannes@cmpxchg.org" , "david@fromorbit.com" , "mhocko@kernel.org" , "vdavydov.dev@gmail.com" , "akpm@linux-foundation.org" , "viro@zeniv.linux.org.uk" , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" 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 Fri, Dec 27, 2019 at 5:36 AM Roman Gushchin wrote: > > On Tue, Dec 24, 2019 at 02:53:23AM -0500, Yafang Shao wrote: > > If the usage of a memcg is zero, we don't need to do useless work to scan > > it. That is a minor optimization. > > The optimization isn't really related to the main idea of the patchset, > so I'd prefer to treat it separately. > Sure. > > > > Cc: Roman Gushchin > > Signed-off-by: Yafang Shao > > --- > > include/linux/memcontrol.h | 1 + > > mm/memcontrol.c | 2 +- > > mm/vmscan.c | 6 ++++++ > > 3 files changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > > index 612a457..1a315c7 100644 > > --- a/include/linux/memcontrol.h > > +++ b/include/linux/memcontrol.h > > @@ -54,6 +54,7 @@ enum mem_cgroup_protection { > > MEMCG_PROT_NONE, > > MEMCG_PROT_LOW, > > MEMCG_PROT_MIN, > > + MEMCG_PROT_SKIP, /* For zero usage case */ > > }; > > > > struct mem_cgroup_reclaim_cookie { > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index c5b5f74..f35fcca 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -6292,7 +6292,7 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, > > > > usage = page_counter_read(&memcg->memory); > > if (!usage) > > - return MEMCG_PROT_NONE; > > + return MEMCG_PROT_SKIP; > > I'm concerned that it might lead to a regression with the scraping of > last pages from a memcg. Charge is batched using percpu stocks, so the > value of the page counter is approximate. Skipping the cgroup entirely > we're losing all chances to reclaim these few pages. > Agree with you. It may lose the chances to reclaim these last few pages. I will think about it. > Idk how serious the problem could be in the real life, and maybe it's OK > to skip if the cgroup is online, but I'd triple check here. > > Also, because this optimization isn't really related to protection, > why not check the page counter first, e.g.: > > memcg = mem_cgroup_iter(root, NULL, NULL); > do { > unsigned long reclaimed; > unsigned long scanned; > > if (!page_counter_read(&memcg->memory)) > continue; > Seems better. Thanks for your suggestion. > switch (mem_cgroup_protected(root, memcg)) { > case MEMCG_PROT_MIN: > /* > * Hard protection. > * If there is no reclaimable memory, OOM. > */ > continue; > case MEMCG_PROT_LOW: > > -- > > Thank you!