Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp990617pxp; Wed, 16 Mar 2022 23:41:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUvCCEdxyC3qH6QT4bNkGofL7i3No7TOtTfatU6kh93sFSmPa+yZcDBMKaaNVOxpNwC83n X-Received: by 2002:a17:90b:2092:b0:1be:e373:2ed9 with SMTP id hb18-20020a17090b209200b001bee3732ed9mr3652513pjb.128.1647499288891; Wed, 16 Mar 2022 23:41:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647499288; cv=none; d=google.com; s=arc-20160816; b=ly2bh7325q3cy9U+hFAPYnH1hB/dueSgHQ4YcZO1F+Yi5XRuTtjlsVv89lELYnU1ol jOv8fmt0AkaKqFT6ZHITKlM3awclIxicTgYDsLwmPg65diAQ1wJiQwXAt7XlP6y+/ggo AG0v9aeqZ7aYr0ciL4KRlqVH39CkcBsK2G/MBk7YQn+a9SkP9HLinlWyPoJvL6rGWpa2 U3YfMKEX353Zq7/c7rndZiyxE5uYdmRzlX/vQXwOCxp13K65+sz/rJaW7B0Emc5qomJv mgfw2Iri/XZqp0r2/1RWEPvaIMTop2ZRZ1Bn94Wb/JB1FchDic2aISt1VikczU8g6wvB RdgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=HgGE9YveU0ky+v2732+pjA5kWB3lTy/qnu0A7Q7FEM0=; b=oKHGjQVYaVMB1Jmp5DY9B0+b5d/ne4rmyUQHs8OxPUQ0MdLsihU2Ek3+H87EmM4CLC FgS6Z1479NFOY5x1N5hOs1nBiy5jqTR1Rh9CCYlQh/Z+neTt1jWT7KbP/f2ENrbCyMkV xbyc3MPKi0BKdV9MZ6AEZ8O5yKbUT8dSoLCtIuSRR39Sw9Qf4CpI8yhOpyApyaytr915 avlp8BcdOAfBQwBl2rHj3CUVp+Q6zAFnkBXbYpRy4u242gM8YpNHfynbXAwjjbus/6Ew I7Hnvs8KC1SS8fVptBbGV2yirAo979PZ7s8kEEwST0gtKNVc0GIS7Zy0q4p3uMipo7Qx pv0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XlXxiMx3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t185-20020a6378c2000000b003816043ee9dsi1346599pgc.146.2022.03.16.23.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:41:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XlXxiMx3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6C3F32E1065; Wed, 16 Mar 2022 22:31:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345220AbiCOGmJ (ORCPT + 99 others); Tue, 15 Mar 2022 02:42:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235433AbiCOGmI (ORCPT ); Tue, 15 Mar 2022 02:42:08 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 689A913D04 for ; Mon, 14 Mar 2022 23:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647326457; x=1678862457; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=8I1wLnG20Ik3u34S3KwlGd2TYvCo27NadTKc1KIB5X8=; b=XlXxiMx3rG2RdYSy5mjj1tCCQ+bh47gc+Xbdsyvh0/YiueOteEwc18w9 BM/UGCAkT+8GOWg/ipQgxb0zdkmTYx2a3qyJS0cJspALj1hj4MZlgeE8k +Dfcn7KmELmNO7qDkAEm4BzF67ekB9IrP9dozYW8hdDp3UM81cYiI/c1G ow72F8eVi4beaIHqyrq1Gr2tVbpmUutOROOEp0oKvy0k+/n6qjTgUQ4MM mMInYUKcraSECRPVKcfy4EZur/tV83qZZ08fpZ2UFfI9YLlZwwruD6DH8 F/ev8h4GsjrIPi+31dRurdKyoQuhdqMDYSXMTlu4pxm4z1vwmHY0svdyr w==; X-IronPort-AV: E=McAfee;i="6200,9189,10286"; a="256177689" X-IronPort-AV: E=Sophos;i="5.90,182,1643702400"; d="scan'208";a="256177689" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2022 23:40:57 -0700 X-IronPort-AV: E=Sophos;i="5.90,182,1643702400"; d="scan'208";a="515746056" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.239.13.94]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2022 23:40:55 -0700 From: "Huang, Ying" To: Oscar Salvador Cc: Andrew Morton , Dave Hansen , Abhishek Goel , Baolin Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] mm: Only re-generate demotion targets when a numa node changes its N_CPU state References: <20220314150945.12694-1-osalvador@suse.de> Date: Tue, 15 Mar 2022 14:40:53 +0800 In-Reply-To: <20220314150945.12694-1-osalvador@suse.de> (Oscar Salvador's message of "Mon, 14 Mar 2022 16:09:45 +0100") Message-ID: <87pmmn3eh6.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Oscar Salvador writes: > Abhishek reported that after patch [1], hotplug operations are > taking ~double the expected time. [2] > > The reason behind is that the CPU callbacks that migrate_on_reclaim_init() > sets always call set_migration_target_nodes() whenever a CPU is brought > up/down. > But we only care about numa nodes going from having cpus to become > cpuless, and vice versa, as that influences the demotion_target order. > > We do already have two CPU callbacks (vmstat_cpu_online() and vmstat_cpu_dead()) > that check exactly that, so get rid of the CPU callbacks in > migrate_on_reclaim_init() and only call set_migration_target_nodes() from > vmstat_cpu_{dead,online}() whenever a numa node change its N_CPU state. > > [1] https://lore.kernel.org/linux-mm/20210721063926.3024591-2-ying.huang@intel.com/ > [2] https://lore.kernel.org/linux-mm/eb438ddd-2919-73d4-bd9f-b7eecdd9577a@linux.vnet.ibm.com/ > > Fixes: 884a6e5d1f93b ("mm/migrate: update node demotion order on hotplug events") > Reviewed-by: Baolin Wang > Tested-by: Baolin Wang > Reported-by: Abhishek Goel > Signed-off-by: Oscar Salvador > --- > v2 -> v3: > - Add feedback from Huang Ying > - Add tags > v1 -> v2: > - Add fedback from Huang Ying > - Add feedback from Baolin Wang > --- > include/linux/migrate.h | 8 +++++++ > mm/migrate.c | 47 +++++++++-------------------------------- > mm/vmstat.c | 13 +++++++++++- > 3 files changed, 30 insertions(+), 38 deletions(-) > > diff --git a/include/linux/migrate.h b/include/linux/migrate.h > index db96e10eb8da..90e75d5a54d6 100644 > --- a/include/linux/migrate.h > +++ b/include/linux/migrate.h > @@ -48,7 +48,15 @@ int folio_migrate_mapping(struct address_space *mapping, > struct folio *newfolio, struct folio *folio, int extra_count); > > extern bool numa_demotion_enabled; > +extern void migrate_on_reclaim_init(void); > +#ifdef CONFIG_HOTPLUG_CPU > +extern void set_migration_target_nodes(void); > #else > +static inline void set_migration_target_nodes(void) {} > +#endif > +#else > + > +static inline void set_migration_target_nodes(void) {} > > static inline void putback_movable_pages(struct list_head *l) {} > static inline int migrate_pages(struct list_head *l, new_page_t new, > diff --git a/mm/migrate.c b/mm/migrate.c > index e8a6933af68d..2561881f03b2 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -3193,7 +3193,7 @@ static void __set_migration_target_nodes(void) > /* > * For callers that do not hold get_online_mems() already. > */ > -static void set_migration_target_nodes(void) > +void set_migration_target_nodes(void) > { > get_online_mems(); > __set_migration_target_nodes(); > @@ -3257,51 +3257,24 @@ static int __meminit migrate_on_reclaim_callback(struct notifier_block *self, > return notifier_from_errno(0); > } > > -/* > - * React to hotplug events that might affect the migration targets > - * like events that online or offline NUMA nodes. > - * > - * The ordering is also currently dependent on which nodes have > - * CPUs. That means we need CPU on/offline notification too. > - */ > -static int migration_online_cpu(unsigned int cpu) > -{ > - set_migration_target_nodes(); > - return 0; > -} > - > -static int migration_offline_cpu(unsigned int cpu) > +void __init migrate_on_reclaim_init(void) > { > - set_migration_target_nodes(); > - return 0; > -} > - > -static int __init migrate_on_reclaim_init(void) > -{ > - int ret; > - > node_demotion = kmalloc_array(nr_node_ids, > sizeof(struct demotion_nodes), > GFP_KERNEL); > WARN_ON(!node_demotion); > > - ret = cpuhp_setup_state_nocalls(CPUHP_MM_DEMOTION_DEAD, "mm/demotion:offline", CPUHP_MM_DEMOTION_DEAD and CPUHP_AP_MM_DEMOTION_ONLINE needs to be deleted from include/linux/cpuhotplug.h too. Best Regards, Huang, Ying > - NULL, migration_offline_cpu); > + hotplug_memory_notifier(migrate_on_reclaim_callback, 100); > /* > - * In the unlikely case that this fails, the automatic > - * migration targets may become suboptimal for nodes > - * where N_CPU changes. With such a small impact in a > - * rare case, do not bother trying to do anything special. > + * At this point, all numa nodes with memory/CPus have their state > + * properly set, so we can build the demotion order now. > + * Let us hold the cpu_hotplug lock just, as we could possibily have > + * CPU hotplug events during boot. > */ > - WARN_ON(ret < 0); > - ret = cpuhp_setup_state(CPUHP_AP_MM_DEMOTION_ONLINE, "mm/demotion:online", > - migration_online_cpu, NULL); > - WARN_ON(ret < 0); > - > - hotplug_memory_notifier(migrate_on_reclaim_callback, 100); > - return 0; > + cpus_read_lock(); > + set_migration_target_nodes(); > + cpus_read_unlock(); > } > -late_initcall(migrate_on_reclaim_init); > #endif /* CONFIG_HOTPLUG_CPU */ > > bool numa_demotion_enabled = false; [snip]