From mboxrd@z Thu Jan 1 00:00:00 1970 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 516E2C49EA1 for ; Fri, 9 Aug 2024 05:20:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 705F56B0089; Fri, 9 Aug 2024 01:20:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B5BE6B008A; Fri, 9 Aug 2024 01:20:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A49D6B008C; Fri, 9 Aug 2024 01:20:12 -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 3C7EB6B0089 for ; Fri, 9 Aug 2024 01:20:12 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BCF7180865 for ; Fri, 9 Aug 2024 05:20:11 +0000 (UTC) X-FDA: 82431555822.07.3D1E1D4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id F3D5140006 for ; Fri, 9 Aug 2024 05:20:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=WM5m8X0Q; spf=pass (imf01.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723180722; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xDs3GbHQyzAwRH34ZtbsRHQjt7R+hyPoAjlwobseYds=; b=QOWZvTrMsgViALv9XYaxDA1DTe5VD3pbkb4YaWjmTvEaf6I50lDhjbMRteFJPQSX/HkxJB 5fwnYBwN0ywUwCcBF8kkA1T66Psstq/wLXR9/9373ZlD1peKDsuP76IuT8QARLk/Rm3Ecz xWnCBr6xS4P4/jnvXz5VugbUajF3IPc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=WM5m8X0Q; spf=pass (imf01.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723180722; a=rsa-sha256; cv=none; b=DECSbHH69G5ZNOCCe9F1J8I45WGcpLcnz1cE7ZXqofelF+JH3tNe796OpiC59yl9VxNoCy taSgtWC33h7BOwAizQvwbNpHlv0cVJYTyxvrOyGo9qaEwm/blTcoQkqwrQf4ID09P/epBx 9DfrfEBs9K0/0MWSgqmdEA2s5YeYyl4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C7AD061435; Fri, 9 Aug 2024 05:20:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4497BC4AF0D; Fri, 9 Aug 2024 05:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1723180807; bh=yzMqCYpZGTsjXi1DWGC9h3DsWjJ6QDDyqPUffbMvsps=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WM5m8X0QfF+/Z9lGQnSSvGLNbHm/e+vMSp7yLviYzINni3vjA/zhXsHBTstBIL139 78A5U0TUEZpQYFgrUVghlf1hutT/EjtHuDRIjApIn5rJpaft1C0McOoC3a3P8+wpDd 2EIS/PcrA3MS2C2CKaeBGF2oW9icmSRokJFrjEw8= Date: Thu, 8 Aug 2024 22:20:06 -0700 From: Andrew Morton To: Saurabh Sengar Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ssengar@microsoft.com, wei.liu@kernel.org Subject: Re: [PATCH] mm/vmstat: Defer the refresh_zone_stat_thresholds after all CPUs bringup Message-Id: <20240808222006.72071b7b945b290e5270eb30@linux-foundation.org> In-Reply-To: <1720169301-21002-1-git-send-email-ssengar@linux.microsoft.com> References: <1720169301-21002-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: F3D5140006 X-Stat-Signature: a1nxrjjeck5k6dzik4b4tsdmiox9w6rp X-Rspam-User: X-HE-Tag: 1723180808-541140 X-HE-Meta: U2FsdGVkX185yPlsI9aFpvAMU4PayAUJdaDBAQnNcKu6ypqSpIoftGwyOhhxbdjN3FSrCQaPYDbX5x8w/Kv7MSDP19JUHNij3y2+SR5NynJqWUKcHEl+o4DVpzoXzAftndl8VQV59U5DQlw4y1T2l1BEJXf2U3imrDwQVFaAkYzoKtr93qqXgQfwKJbFCTOKG9bEJrgA2Mhptp7miAfdXjddaE4EgmHOh9QqrC9x88Ce9LAykM+IyDL7ADt44rT+rE57WyLzSaPmvAkVYZVeS+Yx8M8LEGHFyU7pI6lvhweEwRQ0PzaSmLs/7kAB4Du/hJvHNP/0vCLJeANcorb1adDbDdreyPczIGMVZVuvetdpNMNQBOHOwqYwUVZ4GJ82HhLDKbdE7n4zT/fVN7aO86NBKRvRIZIo2g+xI+uKmR5hASZ/RqaEaOy3Dsn6n35M7/gRAJI3Zbyw1rMkhRTkH42ANKOfc0jYbMAwzsV/qLJmlOmBrPANVhXdI2r9Tlc5eu6Lpc+JSJuVUjwmskhBwO2piq19llx/0pCzdufV6W9Dk0gDZqCW4Hze/YB+wLhYSNQsWwx1OVHnleIyjzeCxow1epTbkYUXlsZsCVZBL7I25r3GRj9FS1Is9Hrmpx8LGeqXnLqZJb8ibQKUvLI0TavdLxAXqJCjjcR0tmqQ8o5L/abcw5QaQOzrC29m55uHZlcSM2CGwfVWC4/e/9BOu7yPttQACr8yN/XlMWZJrtGMEMDjfmsRhGcTYzC0B3P+iF9zU8B8J1sH0nEHqPO7WxPiQSsKKmEwxET0vkxJOOSuTYFsrS+um/lwPCAtqQTQfYlnghz4jzJ8F2XSyRA3qY8g3jk/Q8Xb0KGdkSg0wfWt+fuvP4vhYCV7W9TE4lEZA4D4VOOgcvWubrM31/8yJzIq7dj0gV1YwKigmczj7ieBERa5FE0HhxNoANPm267LvY9bpUuh/dnA8C5fmk7 dTu+RzCa h63zBHIfAt6HLT+xZnXXA8I8f7KJIlsxPgn4HsASmYsCuFLtV3MKNTJLQGbH52AKs7hyb0kV6pp03oKgYaEgy4jJlDihBLaLVQio9rz2jMvTgBt5cUstmcuUNpODv9Ucz/B/SiL9UjDQ+btB+JEbLDtu9l/nLKN2hXimJA5SFICnxRrTW3sAurpbiSw1dR3yutarTFwlA+bzw9e6baAQeufsruyL77v4dqZ/9fIGXxwYANw8RBxTlIYhhNX+Bz/kBMnN63pWECRGZubXHLoJG4sw65YFh2lBa3KW2ZLtoMnTupJk= 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: On Fri, 5 Jul 2024 01:48:21 -0700 Saurabh Sengar wrote: > 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. > > ... > > --- 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); OK, so what's happening here. Once all CPUs are online and running around doing heaven knows what, one of the CPUs sets up everyone's thresholds. So for a period, all the other CPUs are running with inappropriate threshold values. So what are all the other CPUs doing at this point in time, and why is it safe to leave their thresholds in an inappropriate state while they are doing it?