From patchwork Mon Aug 12 06:13:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 13760161 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 A705EC3DA7F for ; Mon, 12 Aug 2024 06:13:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE6156B008A; Mon, 12 Aug 2024 02:13:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E95D06B008C; Mon, 12 Aug 2024 02:13:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5D436B0092; Mon, 12 Aug 2024 02:13:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B80EB6B008A for ; Mon, 12 Aug 2024 02:13:49 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0D2101A082A for ; Mon, 12 Aug 2024 06:13:49 +0000 (UTC) X-FDA: 82442577378.01.90CE17B Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf28.hostedemail.com (Postfix) with ESMTP id 7332AC000E for ; Mon, 12 Aug 2024 06:13:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=KEKDBxKy; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf28.hostedemail.com: domain of ssengar@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=ssengar@linux.microsoft.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723443216; a=rsa-sha256; cv=none; b=eESyDk98ZSzYWLBZBzFMnmLaY8FusM5FPC/3r6dkKCM3QEy2g2YsinsuRHHCi9Y2IM083m +2BZZtR1D5cn/bubR/a8fpbtWgaLjk/wq7IPmgyx1QeoARsOeM96Xavx6e5u13ZVbfyKpr xTyfYEHTjhxtmSFfylF02rTUppfYmwI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=KEKDBxKy; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf28.hostedemail.com: domain of ssengar@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=ssengar@linux.microsoft.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723443216; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=UHju3hrLliyn4aLgBcrXKTfn/eved4RXuOjZBYYgczY=; b=zMlxLQ4B0Bl7Lz0T3L8zVBeRbJ5t7FpDQYri0nRQ0LmKwGOQzPEKRuSVnQsHNOAHmNR96O YE4/IXPq0iUqzpuRagVy6sXATsLlm6LLWH8rAIG3FKQeCEVbos6CwZp2B8OIGmkc9HseUr Q8JoysMP5eHo6Ggk3r83XuH+MdPNXrk= 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 X-Rspam-User: X-Rspamd-Queue-Id: 7332AC000E X-Rspamd-Server: rspam01 X-Stat-Signature: tf3ozf6rxr7cuxwgnoaafr76tui9ot4h X-HE-Tag: 1723443227-55192 X-HE-Meta: U2FsdGVkX19J8+EHxdiOS2pVQqvuw/oEyFkdZursx6YoEplWlgKY6R+MnRG5JUpKl5TfRHvb0A8Un7wr0119+b2X+j3ijfCIRAQDXaOOkGL2LSWr9wMUBr0jdLAm92xfNmvbsq2+q3tm+TP0peJa1xxHmnxPk3+eqVm2KBbIYlZoeWFWBJsfeRtsn02Fxt4HFBGjd0AjBuY6hmAYOQrK99WERX60ommaKZa5/CL363uLMdq2PwF3Euj8AkxsMpmNG+b+jAlDoW99OrNCYd+CfMB/AdZOwvEdYEKP/f3C9Kko9qbkUYJpMrr2/cyi8itB2+zD+18cwHHpbWrYWVOpTAUDXSBq6M5RctZg2E+r4ors4E3F2OJyDvc/pz68ydkwNbW9t4EtW2i9eB/yHZWBy3tpeWkpBC7yiXtr4CWOPyYeyVOB9IOOd87qXKkyDIGGAXYPJHZO0e6yTmJ7JBCXTXu8Xe85SX6zkJbsB10oY43iHGhiOyXhsqoa5g/6wyLNqgCktIXQmiGOHx5VH8pdCoB7khKjOSanLavveOKqyUk3caPy25cBmAnE1o7It/XFwBqs4jG/Ay13M7Dv9dHiYO1e1nQ4jD4Coq/MwzBRd61muUA1AVc/SbNV94lpdHZJDtzA06thDwTCtguIHtnHmq8F7RwvFgYA2bkFV5XX8Q8tSaEJmc2fcA/7sIfZZviT9mNNXByXl3FzN5SyQ8w3dfoKAzyOwhoKx81m4rjkn80T42g4TfNDFsvZ+rRg9UVEcTocb75kcp1sd6ov/g8Ygoid09xGNNKFV5ffTduUAvwL6wLuwh4UIDrwriBbex0OILV7jGhNQwLo5TeIDr05SZ7TsBMv+/mlj/Bj8TkLgw9+efsd0IvzewZPVAjNphweDE2BjaCylAWhEH8U0DS/IkznsrfY5vc3895mhbRPt1xx+yN/askjsJy0TvxMAtrbVkImECleJX39UumJ0oz qORqB4Nn sG5zPf/ljTMwPuUR/weJCuk24+m/sVuXHUeI9GsAvcQq527zWDJERaOBywV2eyLRJcnDx0DXtuSU3ACsXSerVg7ZS7xCieDa1aGPVWSnuKLdr1Qolol9MAMxZavSSk8ElSF9Qv6y5yN8zWdx8YsPrLvKI5G5VUWGewmmM5ScE/Je5O1FtBvWvA1684c9iTCAo5Eo6yb9eXrTFVt7ENWT9RDgdtodrzV242rnl8aOLlMbFahdj1bfYjyzrVBqCwLBLZmbWkuyPShtoeXw= 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: 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 = total number of CPUs Numa = total number of NUMA nodes mCPU = 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 = 1024*2*1*512 = 1,048,576 : Here refresh_zone_stat_thresholds takes around 224 ms total for all the CPUs in the system under test. 16 NUMA = 1024*2*16*512 = 16,777,216 : Here refresh_zone_stat_thresholds 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 Acked-by: Christoph Lameter Reviewed-by: Srivatsa S. Bhat (Microsoft) --- [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 = { #ifdef CONFIG_SMP static DEFINE_PER_CPU(struct delayed_work, vmstat_work); int sysctl_stat_interval __read_mostly = HZ; +static int vmstat_late_init_done; #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) static int vmstat_cpu_online(unsigned int cpu) { - refresh_zone_stat_thresholds(); + if (vmstat_late_init_done) + refresh_zone_stat_thresholds(); 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; } +static int __init vmstat_late_init(void) +{ + refresh_zone_stat_thresholds(); + vmstat_late_init_done = 1; + + return 0; +} +late_initcall(vmstat_late_init); #endif struct workqueue_struct *mm_percpu_wq;