Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2277261rdb; Thu, 21 Sep 2023 13:49:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7g4noW7h59ScUg3QFcmMzst3gClGmjwmmNPNHPrbRektvRg2PKYm7G6hXJYTuRzP6Mw2Z X-Received: by 2002:a05:6870:b24d:b0:1be:d9cc:d902 with SMTP id b13-20020a056870b24d00b001bed9ccd902mr7084026oam.57.1695329340001; Thu, 21 Sep 2023 13:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695329339; cv=none; d=google.com; s=arc-20160816; b=h54KvMuwFpFM3/UpdjOQMhMPQLyts/Ty7oBlpGetWdqeq36LhjL8fuGydpF8THeIdU RA+jMqyXeE3UvQO2Eq7lVrdXr7PCHF3atEk0vo2nNL0AIGNqRCWBZHq8fz9XjO2jl2/c zTpsi8C5OaaAchSBfwNOsiFsaa0lkFQCaD4BWaXR69XWvL2OKbTh4pmDfs6X90ednwV0 dQaHs+P1jXPSkmZPML4R1Q2AXoMI+Iw6b40b5xC3NsVoFAlwR/Rj9TZYlMKKJRiE0mNe IYgtdmhNffyGa9xDArkAW5kAAw+LfIegnsKFG2uru62M2dOwYgfqloGy47PXJiHhwhbK o1aA== 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=VUfaq4QWGo6Pgq9+Gc0pYjCdwcXd4ikm64XsTJ+V7zI=; fh=i6r7D8Tbv5L0V2RUiJXfGU+sNI1eFV0UjCNL0oNyQ80=; b=CZpqlICzzH8YoRbyHktXgc7h8cq8t1X0WjocyS4X7DWvlv+EAJuF0c6v6XsVaJ3y9E 2hgTj6kU2QIkbTJhKl42bmZMeVaH1hjW5vT76p3MJQBo6/V8kff8DbytWtMFqDGg4Zp9 bWtBnO32JSDoWPrUCVUy3Au3plYfwGcz0vrJkJJ65TgDAl9YY/couXwWsqfahEOHwy6D ORzqgFszRame0+922cPR07ALYEobhy6zSXqZfa/VdxfoREKTlhl8PNX8b7ttvFOn+WKR kFfs1HbbNOoO+/Aqtb96QYNOiIZx3/p2Wo2JqWlDQWeLoijdMTrQ+po9nE1vLuYY6deF XjiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QuBq6sLq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id m1-20020a633f01000000b0057777451a91si2229877pga.581.2023.09.21.13.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:48:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QuBq6sLq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 5E3B4807CF76; Thu, 21 Sep 2023 10:07:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230055AbjIURFe (ORCPT + 99 others); Thu, 21 Sep 2023 13:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230247AbjIURFD (ORCPT ); Thu, 21 Sep 2023 13:05:03 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7263346BE for ; Thu, 21 Sep 2023 10:04:21 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id d75a77b69052e-414bbfbdf37so11508421cf.1 for ; Thu, 21 Sep 2023 10:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695315762; x=1695920562; 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=VUfaq4QWGo6Pgq9+Gc0pYjCdwcXd4ikm64XsTJ+V7zI=; b=QuBq6sLql1/NQJP//6nMgyiuHs7KLNNKfCjPoe+v5RXfTahnNrGFoHfMMGrfNhUSsS IATnEC5YqgIjG725bI0tgy2ZXJ8JdM7tXXEwfEKocJLA3ZmkvowCebsyN8CCMGFuY99+ bPFkrkeW0Z/n0zwKouaRPySRMvRKLH5MH47Zy8oCt1x6I0/43q4j7ru6NgLN8dnAxuTA X4QTEhH4SPzvDqrjBeGCIPkzUIR6GxDlod2ZZ2rnbA3PpJ08+UFePCVSuotCf0h0DnlE zLbfpbdZb31hrFpWFSLDl5XuNMb14E/iPjWD68Q1rL3nQLO1WTj7BCBph8adegaqow6S 1evA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695315762; x=1695920562; 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=VUfaq4QWGo6Pgq9+Gc0pYjCdwcXd4ikm64XsTJ+V7zI=; b=xDfxJ6L5WpgG7jzZVXylShxEezof0gqPSxv+Uga2lkgvf38bp6bHSn2rdvrXEKrFgu SLtZ6KuwVE1gEPXId4eRu9Ppy9vWIU++fRzJKvWOCsiFAeezuZAJ53wFkVjXaoOW3cSD iRy6FFe46wuX9hkubLQRlkhm2v+08Od9s6aQZkTkYnGcRUFGy2E5mbiWJjViNk20EXoQ D1CxF/Aq6m7crHPJ6pwyO2zX4iLSRszW2b2qCvkxSn1n2u6+MwJkbz2LUt9i5Tdq3cMM 2EP0ut2PbtjebmlWDsT9Edp/iXn+3m7YiMDk4UQgIWwiWBcndAWuG8WX3GCAXJYy7fnu QZlw== X-Gm-Message-State: AOJu0YwhcN2The9ONsovie+7+pUPfgGuZ6f9Am8Tc5OmmsYpdDOU1hLL oLQpk4ppealwglU8MToZde9tZyF/eqTLiKj0 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a81:b656:0:b0:59b:f493:813c with SMTP id h22-20020a81b656000000b0059bf493813cmr74625ywk.9.1695283865279; Thu, 21 Sep 2023 01:11:05 -0700 (PDT) Date: Thu, 21 Sep 2023 08:10:54 +0000 In-Reply-To: <20230921081057.3440885-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230921081057.3440885-1-yosryahmed@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230921081057.3440885-3-yosryahmed@google.com> Subject: [PATCH 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 , 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=-7.2 required=5.0 tests=DATE_IN_PAST_06_12, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:07:19 -0700 (PDT) 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 --- mm/memcontrol.c | 146 ++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 49562dfdeab2..ef7ad66a9e4c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -570,6 +570,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 * @@ -681,79 +754,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.42.0.459.ge4e396fd5e-goog