Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3312144pxa; Tue, 18 Aug 2020 11:52:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHru3U3vrGOaWBehfjZvY72tuohXH9nT8SBzTegfEp/Zx2NZH3NrZrAIs9YLlWcxLjL+A/ X-Received: by 2002:a17:906:68e:: with SMTP id u14mr714254ejb.166.1597776729774; Tue, 18 Aug 2020 11:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597776729; cv=none; d=google.com; s=arc-20160816; b=JkqAt7bCTFWHXvl7q+rIM8If0W/6+kSRIqo7ZUFESzl0jrfkVFd9u9cnyi+QrqBmiU AJ7mENkFjD1fnH/5K06AJs7QRr7qmBOW4AmMkJvgUC4OLsgj/eXcl2vkOhAkY3lAb6nK no3AhqKxsTf4qRi2L9Pt/x9b1xUY5gFecGcE1yRXr48ftsSf3eL+ndh5uIvnZdWtekjb mssmbRgcpoUgMXaPDf7VhJSgEyGfsePQcgLBC2ap6f3LCB6YQopkZ2ymcg38pawPrAZq XDsM+dYHYQLSq6qdJW/cECKx7q91Zkw7wV9eXZ86hW95eMJoK6/Ywn5W18mL9jRmrRvK XEaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:references:date :from:cc:to:subject:ironport-sdr:ironport-sdr; bh=BF1CY9IDlEQa4eCMmNA4goOUAfG9XRypyTacpPCMLJQ=; b=UwXyXCwHmR461fLs7mr18HotT8GU2F5FMa7s4Ay8CTzHyTIcgVWG94hRi7yDqLZKtC f22Oia3tgd6DphpWB7ehfCzGDtB04w8/0e3DP7vwImX7Mdck4VXP97p9RQBvC8PeacT2 rhbhXwiLxMsiZ7CZHo0RjGIKFAQstHYpXu+Gl1XMhhhX3i73l43wwagYtg/NHRLI6cc0 nkMODgfuDORbfVIL0Omru2v+rokrvRxBuIw3FYqVjPxChbPsSudGlpiUvfZ1Cjg6Oyfg BD6fT+IfeCX+Znm39X2hF57TT+Dy2Vhr/T3OoToztcbYH7oBPj/GZ4cLsXVglmquF2ac +Vxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ov24si13872632ejb.229.2020.08.18.11.51.45; Tue, 18 Aug 2020 11:52:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726852AbgHRSs0 (ORCPT + 99 others); Tue, 18 Aug 2020 14:48:26 -0400 Received: from mga14.intel.com ([192.55.52.115]:63808 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbgHRSsT (ORCPT ); Tue, 18 Aug 2020 14:48:19 -0400 IronPort-SDR: DQKCtZFFwFlkRSHphVQkQm3TQobJQg2YVHziYr4y29IzYeRUaUMMuVbZ2+fT/qvTaCz/4uKvvs ArNxgLQk0jNg== X-IronPort-AV: E=McAfee;i="6000,8403,9717"; a="154248706" X-IronPort-AV: E=Sophos;i="5.76,328,1592895600"; d="scan'208";a="154248706" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2020 11:48:07 -0700 IronPort-SDR: emSl2c0c4Z2kpGQzxXQI1LdUHj3B37UgttUoY8IhQqBclhLlUQuUpkpFiadz5S7ul3PsZjhyjE ttq7+9vwAbtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,328,1592895600"; d="scan'208";a="496948337" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga006.fm.intel.com with ESMTP; 18 Aug 2020 11:48:06 -0700 Subject: [RFC][PATCH 3/9] mm/migrate: update migration order during on hotplug events To: linux-kernel@vger.kernel.org Cc: Dave Hansen , yang.shi@linux.alibaba.com, rientjes@google.com, ying.huang@intel.com, dan.j.williams@intel.com From: Dave Hansen Date: Tue, 18 Aug 2020 11:41:27 -0700 References: <20200818184122.29C415DF@viggo.jf.intel.com> In-Reply-To: <20200818184122.29C415DF@viggo.jf.intel.com> Message-Id: <20200818184127.C3B49AB6@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen Reclaim-based migration is attempting to optimize data placement in memory based on the system topology. If the system changes, so must the migration ordering. The implementation here is pretty simple and entirely unoptimized. On any memory or CPU hotplug events, assume that a node was added or removed and recalculate all migration targets. This ensures that the node_demotion[] array is always ready to be used in case the new reclaim mode is enabled. This recalculation is far from optimal, most glaringly that it does not even attempt to figure out if nodes are actually coming or going. But, given the expected paucity of hotplug events, this should be fine. Signed-off-by: Dave Hansen Cc: Yang Shi Cc: David Rientjes Cc: Huang Ying Cc: Dan Williams --- b/mm/migrate.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff -puN mm/migrate.c~enable-numa-demotion mm/migrate.c --- a/mm/migrate.c~enable-numa-demotion 2020-08-18 11:36:50.193583185 -0700 +++ b/mm/migrate.c 2020-08-18 11:36:50.197583185 -0700 @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -3130,9 +3131,101 @@ again: goto again; } +/* + * For callers that do not hold get_online_mems() already. + */ void set_migration_target_nodes(void) { get_online_mems(); __set_migration_target_nodes(); put_online_mems(); } + +/* + * React to hotplug events that might affect the migration targes + * 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) +{ + set_migration_target_nodes(); + return 0; +} + +/* + * This leaves migrate-on-reclaim transiently disabled + * between the MEM_GOING_OFFLINE and MEM_OFFLINE events. + * This runs reclaim-based micgration is enabled or not. + * This ensures that the user can turn reclaim-based + * migration at any time without needing to recalcuate + * migration targets. + * + * These callbacks already hold get_online_mems(). That + * is why __set_migration_target_nodes() can be used as + * opposed to set_migration_target_nodes(). + */ +#if defined(CONFIG_MEMORY_HOTPLUG) +static int __meminit migrate_on_reclaim_callback(struct notifier_block *self, + unsigned long action, void *arg) +{ + switch (action) { + case MEM_GOING_OFFLINE: + /* + * Make sure there are not transient states where + * an offline node is a migration target. This + * will leave migration disabled until the offline + * completes and the MEM_OFFLINE case below runs. + */ + disable_all_migrate_targets(); + break; + case MEM_OFFLINE: + case MEM_ONLINE: + /* + * Recalculate the target nodes once the node + * reaches its final state (online or offline). + */ + __set_migration_target_nodes(); + break; + case MEM_CANCEL_OFFLINE: + /* + * MEM_GOING_OFFLINE disabled all the migration + * targets. Reenable them. + */ + __set_migration_target_nodes(); + break; + case MEM_GOING_ONLINE: + case MEM_CANCEL_ONLINE: + break; + } + + return notifier_from_errno(0); +} + +static int __init migrate_on_reclaim_init(void) +{ + int ret; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "migrate on reclaim", + migration_online_cpu, + migration_offline_cpu); + /* + * 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. + */ + WARN_ON(ret < 0); + + hotplug_memory_notifier(migrate_on_reclaim_callback, 100); + return 0; +} +late_initcall(migrate_on_reclaim_init); +#endif /* CONFIG_MEMORY_HOTPLUG */ _