Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6138pxb; Mon, 8 Feb 2021 13:32:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwObKkf+ePXiXJnP9xTVYWv0txryr3hSL4mX9OfMqJtR3CAbPE7FmZtCvE2SPKDrXJXQKU/ X-Received: by 2002:a50:f382:: with SMTP id g2mr12445410edm.273.1612819938839; Mon, 08 Feb 2021 13:32:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612819938; cv=none; d=google.com; s=arc-20160816; b=aPj2hNYiXv5354y1qshOsPGUwKCX6ud9o4PBzrTJhVw1m5Os/M7imrHZQCZRgD3n0U Ki07xmWBSbS00RlBgr2yud4jkPBEkPxZDLefd/LofKggVZ9CkbYTl4ibjSuDTNY1VPg2 F9fJYtTjMr8fFCIfhAZlZIvApC+lEPN/JXTesE+Bgeg91mky9NuyMaLHrnPpPGNhVMxd 6QixiiuIbK1hi7IWoQeIsIi+j0UuzDiJjlrZ3p/kw+7i7Fl3KPExQjwMTtnzZ3bAwfmO Fjk4f5rKSArOSOjunUZHrKL1lM9XSCzKyQhEbtj90Sa875eciUF86z/4qDJdvdKsGopD dqQA== 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=trurRt8gUU2aadbEi0vZGrvIaapkw6K9paKqRwTKcaY=; b=c1OxF6JUBxqWiI1dd91YofqKEB+s6X1mrr/EY01Lwc8HborbmTgHLc8SgFGL5KD7yG nHd4nAkvI6oXbB8OMvO00WI37fgiE9bbBn1RgfOTdEVfcNtwBJo5AyVqmQVqbdxajJAb n71n/0YXh2l9GXUPAVXXME8Bqp4HzbKWLhXrC+GjdCKTQZBOXL3MR6E3UlxRP7p2EErk ukbWhnlyhJy1cGs7+zIGZCPC/LQQtQda5OPH6XkdJulwIJYQIsYWyowbdmtDGu6gKAr+ 7ymw2Dau3mw/DlnAXnV5z1vezMxgkKKjRDIrenZeM1Sjq8BMXlbSUL95AIpL5KWS4dgH hkLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=IL858Nl2; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h28si2474592edj.309.2021.02.08.13.31.52; Mon, 08 Feb 2021 13:32:18 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=IL858Nl2; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234478AbhBHVbR (ORCPT + 99 others); Mon, 8 Feb 2021 16:31:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232435AbhBHUl1 (ORCPT ); Mon, 8 Feb 2021 15:41:27 -0500 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4159BC06178A for ; Mon, 8 Feb 2021 12:40:47 -0800 (PST) Received: by mail-qv1-xf36.google.com with SMTP id p12so2731736qvv.5 for ; Mon, 08 Feb 2021 12:40:47 -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=GwcG+gZiclBni/FDFBynRZt9V0KFNjKiFxVJfSH0csTscRwiPH2qLPy5P7BnY2iNbg asb2xqrIcJZSOteVQqHTmayNm0g7/hOIITyRaettH82aO5eHTkpufEwZ+6hzt/rY5T+x Np3X+ao/VScdSa1sM8EqF93KzlzFzEYn2PTweqdI1NkqE/3ewKIn0QlMO4FeoRocQkq/ Z1SZn37jGEzSEGvUsRKu/2mY1kqxwsDUoYq74W2TTac18I71GtTm8z/6NdBi/FqbyWEn GVodZh5ivG1RSvzRC40aQubuJnuna3iJ80zanNBrAdoxAdeSMlrVz1XnxJ5ePqBn3M85 16Xw== X-Gm-Message-State: AOAM530lhCleYLJBGYTwnDTscsB1P5aujpcJFYA7TzUOxezAGp9e/eY8 5R4/xemKmmGSUkbV0i5Zw4Lgog== 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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