Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3004919rdb; Wed, 15 Nov 2023 18:24:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3ngQWuE0qrAM836o3L6g5t/hwv9BdrqpZ1B62TnlbmD2H1fR+4d1/E8hnN5fXo4Ovk7wj X-Received: by 2002:a17:90b:1810:b0:280:2652:d42 with SMTP id lw16-20020a17090b181000b0028026520d42mr16844669pjb.23.1700101474567; Wed, 15 Nov 2023 18:24:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700101474; cv=none; d=google.com; s=arc-20160816; b=B9CzCl79N+x/u2plod0A52Cozi3w9WIvcm8Np7Wb2A97wd6WgNrVkE/i9IL8mF6Wbf mP6rOoa8XA6eA02KKPISdKB97uA+vzDevu2nDXn+TI86GqqcGqd/omq5eRCCmtQ8IlpO omgy5Z7dNR7TDLPbTNgSy2djxUjE4qGBOc5RP+9yzJR1NaxJFtzhheX8k3AwtbzYkh5a /R5zCWsQRv0n88apGCWMRpcN6ItPfZ3nmE8PmBTawBcRJ6OnLQlhf9ECHw9PbQdBvDbW TojXGodPGUHJoczw20W2HBpC6U3HS3ML0oN5MZMJmo2E3yECc/prlDXLEYzh7lMGEuHb fWsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=CsQgPePmMbwkmYg1tT46kxvFflY+DocB+A/S3VGDzrg=; fh=IfBS1eUR4Ph2d1rlykJm3WUUhflOgyoV/WQxPmHrs48=; b=PxZinVEogDa1SkM9VlPYb5Hv2XR3yySYZDzcYYl0GD3FcDpwsptABYAYowIQluF2/U ttOBTlAKfq6aygCIGAryYgWxnN2DqTMGxEjslYXmGAiDoAToJdIBafxOFjOMAx8AYbHj b3etP0RjOlhi5dFLjYmPBQrzpd5Gx1WCduXs9U5LmqAU7F3tmtrHAxOwcEbDTlGkAhUA yaUz3VS0ROwl38wcR4PLZO9hVLx3g/rf4/8a24bE2wPRysRTDq/4grSjbL0yMxwdht5n 38CeDR/PTLBCVTmX4+JpiD45jhR+igBy4MR/neEZLt16J0bGCtNg3Qj4zPn+c8BttN+R Nvkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SSq1gjJG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id gj15-20020a17090b108f00b002802838d557si965404pjb.55.2023.11.15.18.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 18:24:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SSq1gjJG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E1EEE80C8D4D; Wed, 15 Nov 2023 18:24:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344506AbjKPCY2 (ORCPT + 99 others); Wed, 15 Nov 2023 21:24:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344483AbjKPCYV (ORCPT ); Wed, 15 Nov 2023 21:24:21 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B54B127 for ; Wed, 15 Nov 2023 18:24:18 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a90d6ab944so4518917b3.2 for ; Wed, 15 Nov 2023 18:24:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700101458; x=1700706258; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CsQgPePmMbwkmYg1tT46kxvFflY+DocB+A/S3VGDzrg=; b=SSq1gjJGYKByfSc1ezcEZl5ZLzu+0Gp49FDvhZLXMmMAZiEzYmtiwWHY9lp5sxFhfN ED2X1gOJrbfkbLJpx8GZv/6TfkAOaCaxPdiLOWOzdsyL/YMcCovMr1MS6xWLMuUWgjZ0 fwtN68iG7IfCfdUGyMD04z+JM8GRrdmSiqE5ajmCC68UCqbQU3MmWQ8r3KgmZjzy+MUL AWu40HmAP3acYhQ8bRvC3JvcDGnTTyepgs5en4aSS1s9g62t7PbCqtGp+S7CN1UJ41kg WapT3sabVpYTmaQOPOmrrt/m+sFQlvKV1Dar6DQ7H+mzaZoF3Q8TWR/PSDYwFW2NlZW0 /agg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700101458; x=1700706258; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CsQgPePmMbwkmYg1tT46kxvFflY+DocB+A/S3VGDzrg=; b=S66DvckMf6f7NiBZi+K0ipHmLZgaLIDfrh781AE9DBmRui3hKjkuBlK77/WAPEye4p pd2gNgJAhIJQ2aWV2aH1FKoOUXUdWjxwqe6/wOKQ9RzhY0vwK/GGU89T8KaXeCGLgLc9 FDS78pTLl8no840pDyY1aTX8WPkzA55u9Hn5+4PtnCsOL2xTIVZTUNus/G6WYMXrnEim 8JeWy9/GmieJH60iLrg/cW5PAn9+ALOB8mTm/MZnjJwGeOyhlV+N1Br/VOCydU1E05dy MlQxAGtito49gvDcOTIr2pvxzycTvv5fXq2/+yKsOQZ/KtLS80nBz7ULWTTaqm3ShAVC DZEw== X-Gm-Message-State: AOJu0YzVnmhAwLm5T0ulVAoW+STB2ctgAT34V7yIIgCyWWzKXuqgqCIv 5MsoMLWQWHN2eVzRAfi3qPNmruX//qzSwD2Q X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a0d:d747:0:b0:5a7:a929:5b1d with SMTP id z68-20020a0dd747000000b005a7a9295b1dmr375983ywd.4.1700101457790; Wed, 15 Nov 2023 18:24:17 -0800 (PST) Date: Thu, 16 Nov 2023 02:24:07 +0000 In-Reply-To: <20231116022411.2250072-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20231116022411.2250072-1-yosryahmed@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231116022411.2250072-3-yosryahmed@google.com> Subject: [PATCH v3 2/5] mm: memcg: move vmstats structs definition above flushing code From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Tejun Heo , "=?UTF-8?q?Michal=20Koutn=C3=BD?=" , Waiman Long , kernel-team@cloudflare.com, Wei Xu , Greg Thelen , Domenico Cerasuolo , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 18:24:33 -0800 (PST) The following patch will make use of those structs in the flushing code, so move their definitions (and a few other dependencies) a little bit up to reduce the diff noise in the following patch. No functional change intended. Signed-off-by: Yosry Ahmed Tested-by: Domenico Cerasuolo --- mm/memcontrol.c | 146 ++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 18931d82f108f..5ae2a8f04be45 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -573,6 +573,79 @@ mem_cgroup_largest_soft_limit_node(struct mem_cgroup_tree_per_node *mctz) return mz; } +/* Subset of vm_event_item to report for memcg event stats */ +static const unsigned int memcg_vm_event_stat[] = { + PGPGIN, + PGPGOUT, + PGSCAN_KSWAPD, + PGSCAN_DIRECT, + PGSCAN_KHUGEPAGED, + PGSTEAL_KSWAPD, + PGSTEAL_DIRECT, + PGSTEAL_KHUGEPAGED, + PGFAULT, + PGMAJFAULT, + PGREFILL, + PGACTIVATE, + PGDEACTIVATE, + PGLAZYFREE, + PGLAZYFREED, +#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) + ZSWPIN, + ZSWPOUT, +#endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + THP_FAULT_ALLOC, + THP_COLLAPSE_ALLOC, + THP_SWPOUT, + THP_SWPOUT_FALLBACK, +#endif +}; + +#define NR_MEMCG_EVENTS ARRAY_SIZE(memcg_vm_event_stat) +static int mem_cgroup_events_index[NR_VM_EVENT_ITEMS] __read_mostly; + +static void init_memcg_events(void) +{ + int i; + + for (i = 0; i < NR_MEMCG_EVENTS; ++i) + mem_cgroup_events_index[memcg_vm_event_stat[i]] = i + 1; +} + +static inline int memcg_events_index(enum vm_event_item idx) +{ + return mem_cgroup_events_index[idx] - 1; +} + +struct memcg_vmstats_percpu { + /* Local (CPU and cgroup) page state & events */ + long state[MEMCG_NR_STAT]; + unsigned long events[NR_MEMCG_EVENTS]; + + /* Delta calculation for lockless upward propagation */ + long state_prev[MEMCG_NR_STAT]; + unsigned long events_prev[NR_MEMCG_EVENTS]; + + /* Cgroup1: threshold notifications & softlimit tree updates */ + unsigned long nr_page_events; + unsigned long targets[MEM_CGROUP_NTARGETS]; +}; + +struct memcg_vmstats { + /* Aggregated (CPU and subtree) page state & events */ + long state[MEMCG_NR_STAT]; + unsigned long events[NR_MEMCG_EVENTS]; + + /* Non-hierarchical (CPU aggregated) page state & events */ + long state_local[MEMCG_NR_STAT]; + unsigned long events_local[NR_MEMCG_EVENTS]; + + /* Pending child counts during tree propagation */ + long state_pending[MEMCG_NR_STAT]; + unsigned long events_pending[NR_MEMCG_EVENTS]; +}; + /* * memcg and lruvec stats flushing * @@ -684,79 +757,6 @@ static void flush_memcg_stats_dwork(struct work_struct *w) queue_delayed_work(system_unbound_wq, &stats_flush_dwork, FLUSH_TIME); } -/* Subset of vm_event_item to report for memcg event stats */ -static const unsigned int memcg_vm_event_stat[] = { - PGPGIN, - PGPGOUT, - PGSCAN_KSWAPD, - PGSCAN_DIRECT, - PGSCAN_KHUGEPAGED, - PGSTEAL_KSWAPD, - PGSTEAL_DIRECT, - PGSTEAL_KHUGEPAGED, - PGFAULT, - PGMAJFAULT, - PGREFILL, - PGACTIVATE, - PGDEACTIVATE, - PGLAZYFREE, - PGLAZYFREED, -#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) - ZSWPIN, - ZSWPOUT, -#endif -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - THP_FAULT_ALLOC, - THP_COLLAPSE_ALLOC, - THP_SWPOUT, - THP_SWPOUT_FALLBACK, -#endif -}; - -#define NR_MEMCG_EVENTS ARRAY_SIZE(memcg_vm_event_stat) -static int mem_cgroup_events_index[NR_VM_EVENT_ITEMS] __read_mostly; - -static void init_memcg_events(void) -{ - int i; - - for (i = 0; i < NR_MEMCG_EVENTS; ++i) - mem_cgroup_events_index[memcg_vm_event_stat[i]] = i + 1; -} - -static inline int memcg_events_index(enum vm_event_item idx) -{ - return mem_cgroup_events_index[idx] - 1; -} - -struct memcg_vmstats_percpu { - /* Local (CPU and cgroup) page state & events */ - long state[MEMCG_NR_STAT]; - unsigned long events[NR_MEMCG_EVENTS]; - - /* Delta calculation for lockless upward propagation */ - long state_prev[MEMCG_NR_STAT]; - unsigned long events_prev[NR_MEMCG_EVENTS]; - - /* Cgroup1: threshold notifications & softlimit tree updates */ - unsigned long nr_page_events; - unsigned long targets[MEM_CGROUP_NTARGETS]; -}; - -struct memcg_vmstats { - /* Aggregated (CPU and subtree) page state & events */ - long state[MEMCG_NR_STAT]; - unsigned long events[NR_MEMCG_EVENTS]; - - /* Non-hierarchical (CPU aggregated) page state & events */ - long state_local[MEMCG_NR_STAT]; - unsigned long events_local[NR_MEMCG_EVENTS]; - - /* Pending child counts during tree propagation */ - long state_pending[MEMCG_NR_STAT]; - unsigned long events_pending[NR_MEMCG_EVENTS]; -}; - unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) { long x = READ_ONCE(memcg->vmstats->state[idx]); -- 2.43.0.rc0.421.g78406f8d94-goog