From patchwork Fri May 3 02:09:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13652269 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 BB0E8C4345F for ; Fri, 3 May 2024 02:09:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A01A6B008A; Thu, 2 May 2024 22:09:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 350216B008C; Thu, 2 May 2024 22:09:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 218DB6B0092; Thu, 2 May 2024 22:09:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F27226B008A for ; Thu, 2 May 2024 22:09:47 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9DD9D80A41 for ; Fri, 3 May 2024 02:09:47 +0000 (UTC) X-FDA: 82075453614.02.14D23B5 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf26.hostedemail.com (Postfix) with ESMTP id E76C314000F for ; Fri, 3 May 2024 02:09:44 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TV5S4hUg; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714702185; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=MhL5IMfR/PIPcId0PwjBlUn/OiNG0ZYahayTjuFweeU=; b=zo0LJUCFGlde79M2QXPMYIsEWFpmPV77X5mShuMNIYCCLK/zqEdMJjhV18pfCNqA/Cy6Og ZHFLnfNqdJm7Gp8JJhH8pN746MkXVlKGnshroBgyJzbe4/GLqsF5B3RPdIIOPSIrOBYpGv Y3SodzmOpI2a2imFdjcXOCd7SSAv1rc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TV5S4hUg; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714702185; a=rsa-sha256; cv=none; b=2U/c8cZB+fPm61g8mrxX+QuKrbSQzTeCi4UfYMMdkM6KRHmq/bY39sz3EOEYC+ZcvKiUKv pSR+BvQEJPPSHLbw0AwNfebqRSobNWIwzTtauzlKaiATI77Yd3sUERVbt9BQqGFRy/OG8X 6d4FtJQTzKDUD+2jbxnDWkVF9P29QxU= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6edb76d83d0so7600913b3a.0 for ; Thu, 02 May 2024 19:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714702184; x=1715306984; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MhL5IMfR/PIPcId0PwjBlUn/OiNG0ZYahayTjuFweeU=; b=TV5S4hUgSLQ6/6ZBYapToFBwQ/C5bd1g3YvVegeZz/usuEZ6bXA7qoczAsKxhehG3n abULOqcfQRSE4k3JdbwskFS/+S1J1qdF4OQtv1B+gcVArHXZ7PS+MNk+A+DCWq1qFThd devMrGxOmXpfcDuf8fscyJv879uQfbsOjDYReRFX6fxQyGgePts7IGHjZD3D1ucAnDve PEdPC+PebAczIs5OtYhWNJenroXlCvtAXttwMtBUz7WYJQbsTcoLNq4IETguXWskNhkK aE88Nzatta5aZJ+api5y7NQvJmma606XkzmKE0rUBYOiuPlTKS6VQTWmQ5v0ch3ndZ99 pn0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714702184; x=1715306984; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MhL5IMfR/PIPcId0PwjBlUn/OiNG0ZYahayTjuFweeU=; b=S1IraZ17sD730IeUmTuIPgY7bXEZvS7VEAooksEIiKwiE7ZeYiAgpziTrvjo7ixDJ/ 5AK+Agpv5lX/hY0jCVPjCKdSITkgYEefmT3clVBT5U+peeNF65xGczTiK1DQecPgbRrl H+iL4byCfEYLS1fdZV4rpushaOEULCQsb+HJ8t9BGwYaufThBjIMAWNTRHBOz7jXVrCe rMzWW1l9+HeKkS9jTbOZ1VydSWtN/q9Q6gsgARtDrnYcx/nihbT/ftnckXolQC5cTChQ rjdX6GJGAm9rcljxNAebJlXEP8/z9tKdeYP6BfmayfqZmqkyCGlMSsxZw3uTCuJe5A/8 0pTw== X-Forwarded-Encrypted: i=1; AJvYcCV2OwPisGjeRx5YkH1X7jtowyLiOdm4ZSxMIvMTuuKNOZE7ny/Zy4NQyfIxbTag1JxjBUzWflQMy0ij0ONpbZDqqNw= X-Gm-Message-State: AOJu0YxfbDsS7rUPh/te3LXO6USbKnSjoTDveBs0etOHttICHWrhfxTC jUylVx/KLwV25i+LPq4xWX8AhrKU35lPnk/dopW8XvovvX8VnYk4 X-Google-Smtp-Source: AGHT+IGFfHVy5fUogSlRJyYhQr2KateAeFxl34nAMUxN7ZvfwM5gWink+XTgnMZ4VmD4Jc0as7TrVA== X-Received: by 2002:a05:6a00:464e:b0:6f3:ebb3:6bc3 with SMTP id kp14-20020a056a00464e00b006f3ebb36bc3mr1600958pfb.3.1714702183461; Thu, 02 May 2024 19:09:43 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id p8-20020a056a000a0800b006ecc6c1c67asm1956160pfh.215.2024.05.02.19.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 19:09:43 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org, ryan.roberts@arm.com Cc: hannes@cmpxchg.org, linux-kernel@vger.kernel.org, david@redhat.com, v-songbaohua@oppo.com, vbabka@suse.cz, willy@infradead.org Subject: [PATCH v2] mm/vmstat: sum up all possible CPUs instead of using vm_events_fold_cpu Date: Fri, 3 May 2024 14:09:24 +1200 Message-Id: <20240503020924.208431-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: E76C314000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: mhgngh6c846euoio5q1dxdgf3stmtqt6 X-HE-Tag: 1714702184-670028 X-HE-Meta: U2FsdGVkX1/q+0gjhAiDrQmpfMDLiICnrH/dYggT8JvBTaaUtDqgtpDIbtlAXKJ7KSGbp4GcJWphavc/wN7GSkGZH8srO+/RSFooHxmhuYqeJkeiYaG/oHMY8sZcCNhT40uMo8tPAMKutEv/Ajy1vKG499H247IIzEBrbzd07gS+RdXoZIGLXazaDm3c78swmOv/IiBETIUCVhEvC5S+Q5aupoZ8biE0coZ2ROYq3YLi5UBB8Nnj1a86JOfInQol8XLtyxVDCiY4eH6I84rqMkUjTUOLF2Evs0JSlhNU/+lyu/hAu/qSD5mHq9splI1ixOLglE4C3AWUnIZwDSvvDeGSu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I6Pid0eTJKFny60N53KpwHwZ41mrXJnYpJuonr97AwdOLM7IcxQ4xBmLEdEyWOLCd3LpqS25bAZu8McOmia9DbhNUOABFZ/+ixl8zoYfD9VQ8HvApVMjdsTonrDfW3Isj/5Z8QirEnSHlXMJWQ2bzuyti6k8EDyMam/LCNuIB0bUaevppVveP8pggcy+/QHh2Wa2E9z3UZWwceFb2HyDNqiClWhRdUlPH/PCJg8pnRDVs1Rb/nxuooQI= 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: From: Barry Song When unplugging a CPU, the current code merges its vm_events with an online CPU. Because, during summation, it only considers online CPUs, which is a crude workaround. By transitioning to summing up all possible CPUs, we can eliminate the need for vm_events_fold_cpu. Suggested-by: Ryan Roberts Signed-off-by: Barry Song --- originally suggested by Ryan while he reviewed mTHP counters patchset[1]; I am also applying this suggestion to vm_events -v2: also drop cpus_read_lock() as we don't care about cpu hotplug any more; -v1: https://lore.kernel.org/linux-mm/20240412123039.442743-1-21cnbao@gmail.com/ [1] https://lore.kernel.org/linux-mm/ca73cbf1-8304-4790-a721-3c3a42f9d293@arm.com/ include/linux/vmstat.h | 5 ----- mm/page_alloc.c | 8 -------- mm/vmstat.c | 21 +-------------------- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 735eae6e272c..f7eaeb8bfa47 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -83,8 +83,6 @@ static inline void count_vm_events(enum vm_event_item item, long delta) extern void all_vm_events(unsigned long *); -extern void vm_events_fold_cpu(int cpu); - #else /* Disable counters */ @@ -103,9 +101,6 @@ static inline void __count_vm_events(enum vm_event_item item, long delta) static inline void all_vm_events(unsigned long *ret) { } -static inline void vm_events_fold_cpu(int cpu) -{ -} #endif /* CONFIG_VM_EVENT_COUNTERS */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cd584aace6bf..8b56d785d587 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5826,14 +5826,6 @@ static int page_alloc_cpu_dead(unsigned int cpu) mlock_drain_remote(cpu); drain_pages(cpu); - /* - * Spill the event counters of the dead processor - * into the current processors event counters. - * This artificially elevates the count of the current - * processor. - */ - vm_events_fold_cpu(cpu); - /* * Zero the differential counters of the dead processor * so that the vm statistics are consistent. diff --git a/mm/vmstat.c b/mm/vmstat.c index db79935e4a54..aaa32418652e 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -114,7 +114,7 @@ static void sum_vm_events(unsigned long *ret) memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); - for_each_online_cpu(cpu) { + for_each_possible_cpu(cpu) { struct vm_event_state *this = &per_cpu(vm_event_states, cpu); for (i = 0; i < NR_VM_EVENT_ITEMS; i++) @@ -129,29 +129,10 @@ static void sum_vm_events(unsigned long *ret) */ void all_vm_events(unsigned long *ret) { - cpus_read_lock(); sum_vm_events(ret); - cpus_read_unlock(); } EXPORT_SYMBOL_GPL(all_vm_events); -/* - * Fold the foreign cpu events into our own. - * - * This is adding to the events on one processor - * but keeps the global counts constant. - */ -void vm_events_fold_cpu(int cpu) -{ - struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu); - int i; - - for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { - count_vm_events(i, fold_state->event[i]); - fold_state->event[i] = 0; - } -} - #endif /* CONFIG_VM_EVENT_COUNTERS */ /*