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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 5BCF7C433DB for ; Mon, 8 Feb 2021 20:40:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 94C1564DAE for ; Mon, 8 Feb 2021 20:40:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94C1564DAE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 10BCA6B0005; Mon, 8 Feb 2021 15:40:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 098096B006C; Mon, 8 Feb 2021 15:40:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC7E16B006E; Mon, 8 Feb 2021 15:40:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id D7F056B0005 for ; Mon, 8 Feb 2021 15:40:47 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A10AAB7A1 for ; Mon, 8 Feb 2021 20:40:47 +0000 (UTC) X-FDA: 77796269334.03.toy73_6209e2f27601 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 79E0528A4E9 for ; Mon, 8 Feb 2021 20:40:47 +0000 (UTC) X-HE-Tag: toy73_6209e2f27601 X-Filterd-Recvd-Size: 8227 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Mon, 8 Feb 2021 20:40:46 +0000 (UTC) Received: by mail-qv1-f46.google.com with SMTP id f18so1495278qvm.9 for ; Mon, 08 Feb 2021 12:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=trurRt8gUU2aadbEi0vZGrvIaapkw6K9paKqRwTKcaY=; b=IL858Nl22Xe2hZD/k7dFdDA3y+XeQMUvCmXDBjIFTXBken1a9/tGC8cuqXn/3roGxK 7jtigYEaOOLoafpuKYhSmZEhQvp5Ocgsr1V7H+sKcbBBM3kyznclWFpSeqQ9iRaa8RK2 valQydK60iZosDHNE6P+Gh8p0hvoJgaeznnlGjsKJ7ViMr3IIrDDQMozxhaG736LO4DV e0/hPjQZqz6YtgVg/HjadSA3vP6U+nx/XGm7VrQJwvqyTA4j6j2M/17ReimA5yhY3F7u lRNLTmFdnGave+CFQ3023/gG5YM7ARcRFQQkgsMbpJ5JcFIA8xm5HVIvIP7j6TblfL36 kJXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=trurRt8gUU2aadbEi0vZGrvIaapkw6K9paKqRwTKcaY=; b=ubP/5rIl6FFZh8dJV1f4zX7pHV+J091kkQVd5HOs+QLRkHiVY301N5E6q+duw9XL/j 3q6z91OPQdaAkBZwilqX04slY5V3/UoluxEkgcRmdb9pdDSldQm9RgKxSTJxZaz31N8+ Jw2nASPP9wCklyej6beM7Kys02SBn/GJwDaGfGmPPzkEr5rAa+zbl+n7pGGMRymZod14 6EgusOe/ApPN4br8KopSwE85Lx7tbJBOY7mMfV5JdsNppNkXOYYUt0TwV2fC0yxiLcsm VVmZnGVDg7Q/of3WHBZMoEAAdphL3ZW9uctxjYO8FmM9NiC1ZCaXKQuVNh4AceiQXTvJ cv4g== X-Gm-Message-State: AOAM530YKW6tJM7/czIGh0muJiQhPqi9LS28QRSZPflsP3YfdyQk3m79 zYtdQ/rkVwEdtX/LuT9nK0B0r1+94CPiCg== X-Google-Smtp-Source: ABdhPJwQyYGfIra8FZyNeaFtDsJvs7t0G5hWhE50xoYQf0FKtdiPESvQ624JJeOejSIA8QCtlXcLxA== X-Received: by 2002:ad4:54a7:: with SMTP id r7mr18166203qvy.47.1612816846042; Mon, 08 Feb 2021 12:40:46 -0800 (PST) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id r10sm3584020qtn.21.2021.02.08.12.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 12:40:44 -0800 (PST) Date: Mon, 8 Feb 2021 15:40:44 -0500 From: Johannes Weiner To: Shakeel Butt Cc: Andrew Morton , Tejun Heo , Michal Hocko , Roman Gushchin , Linux MM , Cgroups , LKML , Kernel Team Subject: Re: [PATCH 6/8] mm: memcontrol: switch to rstat Message-ID: References: <20210205182806.17220-1-hannes@cmpxchg.org> <20210205182806.17220-7-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Sun, Feb 07, 2021 at 06:19:04PM -0800, Shakeel Butt wrote: > On Fri, Feb 5, 2021 at 10:28 AM Johannes Weiner wrote: > > > > Replace the memory controller's custom hierarchical stats code with > > the generic rstat infrastructure provided by the cgroup core. > > > > The current implementation does batched upward propagation from the > > write side (i.e. as stats change). The per-cpu batches introduce an > > error, which is multiplied by the number of subgroups in a tree. In > > systems with many CPUs and sizable cgroup trees, the error can be > > large enough to confuse users (e.g. 32 batch pages * 32 CPUs * 32 > > subgroups results in an error of up to 128M per stat item). This can > > entirely swallow allocation bursts inside a workload that the user is > > expecting to see reflected in the statistics. > > > > In the past, we've done read-side aggregation, where a memory.stat > > read would have to walk the entire subtree and add up per-cpu > > counts. This became problematic with lazily-freed cgroups: we could > > have large subtrees where most cgroups were entirely idle. Hence the > > switch to change-driven upward propagation. Unfortunately, it needed > > to trade accuracy for speed due to the write side being so hot. > > > > Rstat combines the best of both worlds: from the write side, it > > cheaply maintains a queue of cgroups that have pending changes, so > > that the read side can do selective tree aggregation. This way the > > reported stats will always be precise and recent as can be, while the > > aggregation can skip over potentially large numbers of idle cgroups. > > > > The way rstat works is that it implements a tree for tracking cgroups > > with pending local changes, as well as a flush function that walks the > > tree upwards. The controller then drives this by 1) telling rstat when > > a local cgroup stat changes (e.g. mod_memcg_state) and 2) when a flush > > is required to get uptodate hierarchy stats for a given subtree > > (e.g. when memory.stat is read). The controller also provides a flush > > callback that is called during the rstat flush walk for each cgroup > > and aggregates its local per-cpu counters and propagates them upwards. > > > > This adds a second vmstats to struct mem_cgroup (MEMCG_NR_STAT + > > NR_VM_EVENT_ITEMS) to track pending subtree deltas during upward > > aggregation. It removes 3 words from the per-cpu data. It eliminates > > memcg_exact_page_state(), since memcg_page_state() is now exact. > > Only if cgroup_rstat_flush() has been called before memcg_page_state(), right? Yes, correct. > > Signed-off-by: Johannes Weiner > > Reviewed-by: Roman Gushchin > > Acked-by: Michal Hocko > > Overall the patch looks good to me with a couple of nits/queries below. > > Reviewed-by: Shakeel Butt Thanks! > > @@ -1383,8 +1388,16 @@ void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx) > > { > > } > > > > -static inline void lruvec_memcg_debug(struct lruvec *lruvec, struct page *page) > > +static inline void mem_cgroup_split_huge_fixup(struct page *head) > > +{ > > +} > > + > > +static inline > > +unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, > > + gfp_t gfp_mask, > > + unsigned long *total_scanned) > > { > > + return 0; > > Any technical reason to move around mem_cgroup_soft_limit_reclaim(), > mem_cgroup_split_huge_fixup() and lruvec_memcg_debug() or just > aesthetics? Yeah, just a while-at-it cleanup. It seemed too minor to justify a separate patch. > > #endif /* CONFIG_MEMCG */ > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index 2f97cb4cef6d..5dc0bd53b64a 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -757,6 +757,11 @@ mem_cgroup_largest_soft_limit_node(struct mem_cgroup_tree_per_node *mctz) > > return mz; > > } > > > > +static void memcg_flush_vmstats(struct mem_cgroup *memcg) > > +{ > > + cgroup_rstat_flush(memcg->css.cgroup); > > +} > > cgroup_rstat_flush() has one line wrapper but cgroup_rstat_updated() > does not, any reason? cgroup_rstat_flush() seemed a bit low-level to sprinkle around the code base. Especially with cgroup_rstat_updated() encapsulated by the mod_memcg_state() layer, a reader of such a callsite might not easily understand what rstat even is and when and why it needs to be called. > > @@ -3618,6 +3569,8 @@ static unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap) > > { > > unsigned long val; > > > > + memcg_flush_vmstats(memcg); > > + > > if (mem_cgroup_is_root(memcg)) { > > I think memcg_flush_vmstats(memcg) should be here. Good catch! I'll fix that in the next revision. Thanks Shakeel