Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp613173pxu; Wed, 7 Oct 2020 11:06:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRh0TelZ5LIqY6sNeHJIFjULRlC/feGPb97qonWbhg5y9iNNJb79z8IMmFyS/jUP+tnOXh X-Received: by 2002:aa7:c154:: with SMTP id r20mr4896107edp.337.1602093982258; Wed, 07 Oct 2020 11:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602093982; cv=none; d=google.com; s=arc-20160816; b=B9nPEpnYLjphSQ7hTpxOFnHnTTaqjp26DVWZdFY5pxgqzXJ/wQF1ZT7lh3Vzy1QQU/ +agfxbyDTnA5YdybIvgmsGHuA2RGn+xTroGjBIVqUjk1TunGVlMIeT7MP8XkEtm5BFLQ mqwBx/hiTF1aie21phAnnUJKDJIxGXz1fANTvMHLBOyPLPiLXA4+SS/BtJ8HZzCHNeFk JcdubgRMDHvU9GjfMLfxl6qthpw0ZVBSSUyjXlfAzKKu6Kk79c3PewoTN7NaKz+0t34X bngsnqzDqwAfL6esFi+aiL6+nJuSVLHq2KqIPD4l0sdzzzYbEjvvaULx7hVV6UuwAmSp pPaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:in-reply-to:references:date:from:cc :to:subject:ironport-sdr:ironport-sdr; bh=63gjNrWKgSjQsUq4Gof6rcHKDrcLLbq18TOQxmdyOao=; b=PplNdOUfHyHKP4badJhFOZW0N/Zhlt58CoB0a27bcwi9Do1alxpiGx3byb6NMjwJkJ eW/knzW0j2lcZFFd0z7UBy18p0YHu4ppuCcLCk4XTNBIdeS7ijG3lUX+YZRJFDifnzR/ AhwEIMohokmDOXJCARcuyJ3AQgXcJ9/vKqgU4hgqFZRJAznLuXJgRYCn6fRVuU1kQfMH 8AotM7e4PFuv8vLIVIXqlfZzhKcomXy4rhkMB83UX/Y04CbpgITTT7AcWxAKWKQ9y6Il 5ASdsLsACyZKB3YmdpgVdwBQuW8Lm76RZf0csLupWW1zpapK1zZ2J5Ii7fzAT6DpzsF3 BSoA== 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 bu25si1884188edb.438.2020.10.07.11.05.48; Wed, 07 Oct 2020 11:06:22 -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 S1727766AbgJGQRw (ORCPT + 99 others); Wed, 7 Oct 2020 12:17:52 -0400 Received: from mga05.intel.com ([192.55.52.43]:59178 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729179AbgJGQRt (ORCPT ); Wed, 7 Oct 2020 12:17:49 -0400 IronPort-SDR: cTF+h+9BllbkO8fQV9QW36Gc5TdcdAXH3T+OWjAx57qGohK11qDKD/UGFcfK3KYXiLJIsV+o4u CGAsWRG/JcBg== X-IronPort-AV: E=McAfee;i="6000,8403,9767"; a="249718684" X-IronPort-AV: E=Sophos;i="5.77,347,1596524400"; d="scan'208";a="249718684" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2020 09:17:49 -0700 IronPort-SDR: 8HPIDvb9j3GVeLiCNh2f2i/uckzsBEixx1tHzFSrBXnFo8jFzdOq69fA+lQSJnuhFZ/b/HevRQ cZ3xhuN0TLgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,347,1596524400"; d="scan'208";a="316279973" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga006.jf.intel.com with ESMTP; 07 Oct 2020 09:17:48 -0700 Subject: [RFC][PATCH 3/9] mm/migrate: update migration order during on hotplug events To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen , yang.shi@linux.alibaba.com, rientjes@google.com, ying.huang@intel.com, dan.j.williams@intel.com, david@redhat.com From: Dave Hansen Date: Wed, 07 Oct 2020 09:17:41 -0700 References: <20201007161736.ACC6E387@viggo.jf.intel.com> In-Reply-To: <20201007161736.ACC6E387@viggo.jf.intel.com> Message-Id: <20201007161741.DDC85648@viggo.jf.intel.com> 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 Cc: David Hildenbrand --- 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-10-07 09:15:28.260642449 -0700 +++ b/mm/migrate.c 2020-10-07 09:15:28.266642449 -0700 @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -3241,9 +3242,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 */ _