From nobody Sat Feb 7 20:43:57 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63EAE3715E for ; Mon, 12 Aug 2024 06:13:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723443227; cv=none; b=mN9W0OeyhnLeFbWaF+M3SYdnXdQ06hkGN97rEb66JwdsAGvpyJvlks4N1etohkEI40mFcquyZPSFobxSbSQz7kQ2VV5XsMgqgiCxiN4C38ECLYEpJPI2dgR6sVIfgSCp/c/x6vCI7OrrW3KG/Fb2S99WESEzgZVTVWBzFNEVl6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723443227; c=relaxed/simple; bh=63aIivKusA3rq9+2Llqi5WIx1GratG6DrP7QyO0Xr3E=; h=From:To:Cc:Subject:Date:Message-Id; b=GBuBh1gVXzik58Wv748zMyHlWpEZcXgypJ1HbR7Rf/9iYiSy1KgM2eDBQErkSyy9GLqlcrxmKsZdDpZzSzv/Mlo4pikZgVwzSn6uIS8uTUEjYiyGlB+N8KdN9xyJrbtvDypyCIUHd2Y+EBrCzNK8r/RC4lgTdRxtolt41GhwXrg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=KEKDBxKy; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="KEKDBxKy" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id D4EA920B7165; Sun, 11 Aug 2024 23:13:45 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D4EA920B7165 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1723443225; bh=UHju3hrLliyn4aLgBcrXKTfn/eved4RXuOjZBYYgczY=; h=From:To:Cc:Subject:Date:From; b=KEKDBxKyq/ZHcu+a6BDafEqICqQWIGyGXcYP/nHEBBuhGV9FyFMcA4R5X1CnDc0/J d/obfZQhfftf8UUy5KCVKXaZAiT9k2lQ9Cp1pWIFB/ajTUnrSPSPvr3yUsuJr3K94b 2TFri3Pd61N2fp3a6vRyUoyw08bGYinYE4AfNB9I= From: Saurabh Sengar To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: ssengar@microsoft.com, wei.liu@kernel.org, srivatsa@csail.mit.edu Subject: [PATCH v2] mm/vmstat: Defer the refresh_zone_stat_thresholds after all CPUs bringup Date: Sun, 11 Aug 2024 23:13:40 -0700 Message-Id: <1723443220-20623-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" refresh_zone_stat_thresholds function has two loops which is expensive for higher number of CPUs and NUMA nodes. Below is the rough estimation of total iterations done by these loops based on number of NUMA and CPUs. Total number of iterations: nCPU * 2 * Numa * mCPU Where: nCPU =3D total number of CPUs Numa =3D total number of NUMA nodes mCPU =3D mean value of total CPUs (e.g., 512 for 1024 total CPUs) For the system under test with 16 NUMA nodes and 1024 CPUs, this results in a substantial increase in the number of loop iterations during boot-up when NUMA is enabled: No NUMA =3D 1024*2*1*512 =3D 1,048,576 : Here refresh_zone_stat_threshol= ds takes around 224 ms total for all the CPUs in the system under test. 16 NUMA =3D 1024*2*16*512 =3D 16,777,216 : Here refresh_zone_stat_threshol= ds takes around 4.5 seconds total for all the CPUs in the system under test. Calling this for each CPU is expensive when there are large number of CPUs along with multiple NUMAs. Fix this by deferring refresh_zone_stat_thresholds to be called later at once when all the secondary CPUs are up. Also, register the DYN hooks to keep the existing hotplug functionality intact. Signed-off-by: Saurabh Sengar --- [V2] - Move vmstat_late_init_done under CONFIG_SMP to fix variable 'defined but not used' warning. mm/vmstat.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/vmstat.c b/mm/vmstat.c index 4e2dc067a654..fa235c65c756 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1908,6 +1908,7 @@ static const struct seq_operations vmstat_op =3D { #ifdef CONFIG_SMP static DEFINE_PER_CPU(struct delayed_work, vmstat_work); int sysctl_stat_interval __read_mostly =3D HZ; +static int vmstat_late_init_done; =20 #ifdef CONFIG_PROC_FS static void refresh_vm_stats(struct work_struct *work) @@ -2110,7 +2111,8 @@ static void __init init_cpu_node_state(void) =20 static int vmstat_cpu_online(unsigned int cpu) { - refresh_zone_stat_thresholds(); + if (vmstat_late_init_done) + refresh_zone_stat_thresholds(); =20 if (!node_state(cpu_to_node(cpu), N_CPU)) { node_set_state(cpu_to_node(cpu), N_CPU); @@ -2142,6 +2144,14 @@ static int vmstat_cpu_dead(unsigned int cpu) return 0; } =20 +static int __init vmstat_late_init(void) +{ + refresh_zone_stat_thresholds(); + vmstat_late_init_done =3D 1; + + return 0; +} +late_initcall(vmstat_late_init); #endif =20 struct workqueue_struct *mm_percpu_wq; --=20 2.43.0