From patchwork Fri Jul 5 08:48:21 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: 13724553 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 0FB2EC3271F for ; Fri, 5 Jul 2024 08:48:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90B176B008A; Fri, 5 Jul 2024 04:48:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BA8B6B009A; Fri, 5 Jul 2024 04:48:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75B456B009B; Fri, 5 Jul 2024 04:48:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4F8D26B008A for ; Fri, 5 Jul 2024 04:48:29 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C609B414C2 for ; Fri, 5 Jul 2024 08:48:28 +0000 (UTC) X-FDA: 82305072696.18.B7E242F Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf11.hostedemail.com (Postfix) with ESMTP id 4D6884000C for ; Fri, 5 Jul 2024 08:48:27 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=Hlq1n32j; spf=pass (imf11.hostedemail.com: domain of ssengar@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=ssengar@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720169294; 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=0thq+BQ0rfesnQgGZNqX21vsSZLDMUtxpzXR/g19MkA=; b=AK3l2IV4ctBBepR2hm7HjIenPlj+zPM6lbZxCwQ0tgaP6ABPQr9IgLYaP+zVE2NXlSMIXz JYktTv2uQPlsp5eFt1P2h0mMI1LV4ZNZiEr7sN5qr7KMM9n5pjTKR/bSa+MnEP+PEMGHgL Syh0poMYRBvXUW4VfOcKPN6YyHQT9j4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=Hlq1n32j; spf=pass (imf11.hostedemail.com: domain of ssengar@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=ssengar@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720169294; a=rsa-sha256; cv=none; b=bD92vjFdpxIiHsxylA/xcaZ5csok62TyPSUCOW2/qXjQpXyGKVNtTIMIcIvjyokDblp0kv T0Yoi6k2tOHHG79+tXrov14dnONPdoRvygL2AzIJvPMZMmk/5Ecy3OYcvHyeP/UPFBXyaU +DhM0QOJ0ZhoCg+j3Y64uWWXFIDk2rg= Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 5041D20B7001; Fri, 5 Jul 2024 01:48:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5041D20B7001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1720169306; bh=0thq+BQ0rfesnQgGZNqX21vsSZLDMUtxpzXR/g19MkA=; h=From:To:Cc:Subject:Date:From; b=Hlq1n32jWKC7p4bjqM7cmiqf/I6OSmhHULQEiJkMsf1mEvii7LEFZW79TtyfaeVyK q4jMMfD46cunsQDKMcKm5PRlB+BZvg043PhxeTRMaYHtQHhKtjHPAU45GPiB0txZHs CLR3i2kVQbYOTxwHJGmxzOFWKQ7EfYbdWoJmSmQE= 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 Subject: [PATCH] mm/vmstat: Defer the refresh_zone_stat_thresholds after all CPUs bringup Date: Fri, 5 Jul 2024 01:48:21 -0700 Message-Id: <1720169301-21002-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 4D6884000C X-Stat-Signature: 1waqo9wb88b7go1tc1yf5unquzz3wwnd X-Rspam-User: X-HE-Tag: 1720169307-544486 X-HE-Meta: U2FsdGVkX19Q5R31uTbl3IA3rt2RGv3o4Lwz+P5UR0u2QHUHVAdIUamUd0E5TbAccYsdDzIInN1NpWAFMCQwXSwc4x2y4kf3RKlu0SrQdDS0i1CYk1/JBGeDw1+Hu1sj6k91SjNCfnwtuxPptDeCsL6CMZLpaY02enAwXu3slTivRh75GzLIqFs6odUQTdJ+F3MYGN4fQeQxzbJ9rds8Uq3vxVZEDi3zX/AOFXohHbghfeCm31lO9rnse/XUqcbnp4FYVL6TzeCdwaZ/PZy2Wp+CGkvNGIVVFb8HOQJ7FEL69hdyO0G+8qZ7PIc0WjhH8UYxSzvbRgDrexNKqtMpFAdlCiswZYL/gouynfeYlUxUTZBpN77UNNNwdWRySEKm8fAEef/tCYzjdLSRI/upkv7BUbAoFo7b11Dvkg74Wx73EDzr9JeDLlFe3lHWGj33y2vJsBdPqVoSBFfIEpql7sQigZypPvT+kKTlz41sOkCceEM4RHMduiRZht2iBnFItFLoiwFagULYvBMb/1yROn7h26E8nggs0G5KOl4Q9zwIZPOZiHFUs8P4gBnq0AuqCQUwyeK7UZSEau7fZuMGLqx+3IXWoFJxWQ+VIgMmZs6mG5RzLBNHaeg0Ms/eSaa6ztJfvwBp0MruAUH/B+jXHRUgaLWpnmcuIl6G7ekpOfC4xjMbBWlZO1aBpJT4H1MF07yWbEF/W9IiwETQiqEoeiZ71Q/lpR72gWM5CNJ3XsmuFxbGi02iJ6a8DJfnTUEv84NHXhubQccQu6pNoudLuW9vx5kPl/1lQ9SRRZ6CxhUpoNzK75ELOw51G+NrKXbPQ28w2aU8z/ZRIxai6W1o/+KwPVhTcPgoLNnX/u3/amQKidQ5aRWS0lKifHsyt5GLnjyzJICEIHNPzWO60bJ+vXzA7Qt83+GJn4zvYW559w+dxSOgqcHQ6HuAV7nVD9UXr0qSsYEkIUN/h0Drlle 68PPV24D tIaOJL9iqs5tw4e0YaVWJo6O0Im9dAYrQB2KWLmWUSfnuhG0fMIGR17V2EwcZtVr5xuCBj0guC3wdS26XkL6QQNRLqOz3gKkSm2PrpZ3IbDiQQEBFzGy11Sf66zeVg/VqInWMgoGLqRqLnVWSD3xBr8u5uiB25GhDD63TfgKcssX3E87xEUzqkKZBIJZKDoyaXdTqt5nsmzp2Ql/8spTUx0qKXX2OlqYtXTpsiqGkOg/CpR7RRU8u4yNQUhe6oWPv7UptN/9RfH7ggdM= 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 --- mm/vmstat.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/vmstat.c b/mm/vmstat.c index 6e3347789eb2..5c0df62238d9 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -31,6 +31,7 @@ #include "internal.h" +static int vmstat_late_init_done; #ifdef CONFIG_NUMA int sysctl_vm_numa_stat = ENABLE_NUMA_STAT; @@ -2107,7 +2108,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); @@ -2139,6 +2141,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;