From patchwork Thu Nov 16 02:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13457529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E6A7C5ACB3 for ; Thu, 16 Nov 2023 02:24:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8E596B03DC; Wed, 15 Nov 2023 21:24:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D16C26B03DE; Wed, 15 Nov 2023 21:24:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6A1E6B03E0; Wed, 15 Nov 2023 21:24:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A3EC66B03DC for ; Wed, 15 Nov 2023 21:24:20 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 70A8A12035C for ; Thu, 16 Nov 2023 02:24:20 +0000 (UTC) X-FDA: 81462223080.15.8F6E953 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf22.hostedemail.com (Postfix) with ESMTP id A51E0C0008 for ; Thu, 16 Nov 2023 02:24:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=yfAMCvNz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3UX1VZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3UX1VZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700101458; a=rsa-sha256; cv=none; b=KsDfDpo5mJltMB7x8od2D3E45CQxH1elDZ2NA+b9/uz0X6SliaKWalTh+evBEnNAnfIRlD JHapsQP0G6JINOSXjhpgatj/ac83PLqyZDlNpmEBTqHhP2sNupOeWuZTYKY9OJNViKrCIA WkW+AqNMzbz5KjuCI4kD/asa/tCYCJc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=yfAMCvNz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3UX1VZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3UX1VZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700101458; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CsQgPePmMbwkmYg1tT46kxvFflY+DocB+A/S3VGDzrg=; b=09M03Xk53uuTiaJXHIEJ82QQXs2k/Zxft86s77t2ahTFzo/RjNZzWI2XZ+T9Vl6WrZTH8w rwoKcUAVX+6gY5IOVRgFWn5OX8UWn4uFOJFRzG76+m5iRNcb0ukmM4d7dPDgq6ampb02jX OrQuH3MBmQdBUlDFzJa5MvZkdaIpbpE= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5af16e00fadso4835207b3.0 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=kvack.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=yfAMCvNzpQAuhKmBkPeO3mXmAdmVJE3qavs3TwK0Mgw1yoDbWpqe6w1Ob0q3PI2OZO aR/dn97YTHfs9083Pm0Wm0VzYSMebAL5J+M5XHiscQzpVGtp0OTJaY0lBLTxTURptDpE T5Xkw3vMrRS6jX8A+8xFCeNjJjs6C7ZQ3zZrcMrhL6gpEwLzGER+yh3BjY4rvfhrb9xr pn5hDU8UN8q2Osv56dsEAfHD5kRAipIoyAh4EgegJJnFl2OaOmoM4h++Y38JQg38iH1u I/q0KnW2QEiXMJSWPxwCD7jBY9QeXTwcfgLDxlBlriIPOein6LOLsogGWh9/kx8bBbzC pXCA== 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=JnFQ6/Xupoh45y8SpSKlUlhunwigAdKmTuEdo9w3D8i/n/MGLbAgfw7XkjR/F/XnOF /eIuxjmC7sTvGfppG9ZCVD456SdKIMa6zqkWngigQMf4asgmeFeYnibzxOIKjAO9wxuk eG7aNfKp5yqCUfVEFCgxbcGVDdFoPORTVojxNDEse1dk90UpO55JOxWmBVpSDBxQDmaw oFzFnMyySpKTM3nWOFvBK1kFlfAsMZzTztqh0GXnZ7IphQEvoCsK1lxDBP5U804hSPZn k+YrW+Oi5XtCZBgE3O6SJEgE/NEQDUutzHQWCPcdYxkgB2bJRC1PjLnJIlQDBpHJCsO7 MzRQ== X-Gm-Message-State: AOJu0YzInYChwvLcGL63gPjqnIIKh66juDYjxvrnlGyOR5P2tCJ4HQiE KMcG7bRN6eu1A3PLfaoG3WVEzY3272JhWh0k X-Google-Smtp-Source: AGHT+IFLy40NOoa1rb6dZOa2HGVCBZYSVTkHt6esqpaY9lO76idIWli3bPfPKtfXVxgT/7MwnEla17Q3y28TlYUG 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_Koutn=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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A51E0C0008 X-Stat-Signature: 9az8hioa8f8maox3ugxjskn6raic6mdn X-HE-Tag: 1700101458-253701 X-HE-Meta: U2FsdGVkX19VcwjcIx6fvusYZ1/JlsfR6uyxRQ0eFjkKnBnuxrGb9mJfnQ80F+Ahzx9F4gODLmpABDmX96KFadNrndKtpdjStH3V1SU4NS/HBly6J2PVnhMmBhoeSdELGaXi4BC4DmVo9IY/3XipHxz8mP53W5xG6HOqVQMNzxTpp7UCsqrlOf8pj2DIF8UqYxOa7/2vhXQSxr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Cx39PM6hvKvB7VagYptao+OAC+fQ6IMUQYpMeeiuMN4Xl1RbSkAmq/fI2A150EE40/+luKpi/Y4KIDbMWaZm3ODVahi4CCxSTqdpIwSzth3iMrYT89VFrb4YzQdpzzVhKgPsWE6qe2pVfTxrRwpuGca4eNZAnIYXQwdsc9q+1fbfvrV10C9Q+OsQoMpRLFGakHykS75YWeUkMOo+mzAy1Gx/6QWT9UtTMTOJxmPeuBwk9tRCq3S+sZGB8J52TAGpfUeBhaUMqw8GhgpzsxoI3afcKXm/bSQ2+8BZJuk2H2uNVueayslGt0aHoqJNvEm46uMYX4IXc8tZPGJCj97Z2SEvv6Ek7iV644/0vA/7snxXFX7Zeo48I3k3TeAXnl/hwCU 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: List-Subscribe: List-Unsubscribe: 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 Acked-by: Shakeel Butt --- 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]);