mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: "Gregory Price (Meta)" <gourry@gourry.net>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com, david@kernel.org, ziy@nvidia.com,
	rakie.kim@sk.com, ying.huang@linux.alibaba.com, harry@kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] mm/mempolicy: recompute automatic interleave weights on memory hotplug
Date: Fri, 30 Oct 2026 16:43:03 -0700	[thread overview]
Message-ID: <20261030164303.02c5cce0521c3d6fd4ddf015@linux-foundation.org> (raw)
In-Reply-To: <CAN+CAwN+OPMPpVdBA+XtQvFpDy+EOY2TAiusxMjYR+r0F+MPhw@mail.gmail.com>

On Fri, 30 Oct 2026 12:35:38 -0400 Joshua Hahn <joshua.hahnjy@gmail.com> wrote:

> On Fri, Oct 30, 2026 at 12:12 PM Gregory Price (Meta) <gourry@gourry.net> wrote:
> >
> > In auto mode, weighted interleave derives each node's weight from its
> > bandwidth, reduced over the nodes in N_MEMORY. HMAT and CXL report a
> > node's bandwidth once, when the node first gains memory, and nothing
> > else on the hotplug path recomputes the weights.
> >
> > This can result in a major skew in distribution and overload tiers
> > with more data than their respective bandwidth can support, resulting
> > in a performance regression.
> 
> ...
>
> I think you may have dropped my review tag from the previous
> version!!! I believe the only thing that changes is the warn, so
> please feel free to add:
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>

Actually, quite a lot changed, so dropping the v1 tags seems
appropriate.

v1->v2:

 mm/mempolicy.c |   36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

--- a/mm/mempolicy.c~mm-mempolicy-recompute-automatic-interleave-weights-on-memory-hotplug-v2
+++ a/mm/mempolicy.c
@@ -261,7 +261,11 @@ static int wi_state_refresh(void)
 	mutex_lock(&wi_state_lock);
 	old_wi_state = rcu_dereference_protected(wi_state,
 					lockdep_is_held(&wi_state_lock));
-	/* NULL wi_state assumes auto=true */
+	/*
+	 * Hotplug events can arrive before any node reported its bandwidth,
+	 * leaving nothing to compute weights from. NULL wi_state assumes
+	 * auto=true.
+	 */
 	if (!node_bw_table || (old_wi_state && !old_wi_state->mode_auto)) {
 		mutex_unlock(&wi_state_lock);
 		kfree(new_wi_state);
@@ -302,6 +306,28 @@ int mempolicy_set_node_perf(unsigned int
 	return wi_state_refresh();
 }
 
+/*
+ * HMAT and CXL report a node's bandwidth only when it first gains memory, so
+ * recompute the weights whenever N_MEMORY changes.
+ */
+static int wi_state_node_notifier(struct notifier_block *nb,
+				  unsigned long action, void *data)
+{
+	struct node_notify *nn = data;
+	int err;
+
+	if (action != NODE_ADDED_FIRST_MEMORY &&
+	    action != NODE_REMOVED_LAST_MEMORY)
+		return NOTIFY_OK;
+
+	/* The hotplug is done, failing the notification would not undo it */
+	err = wi_state_refresh();
+	if (err)
+		pr_warn_once("failed to recompute weighted interleave weights for node%d: %d\n",
+			     nn->nid, err);
+	return NOTIFY_OK;
+}
+
 /**
  * numa_nearest_node - Find nearest node by state
  * @node: Node id to start the search
@@ -3424,6 +3450,7 @@ void __init numa_policy_init(void)
 	if (do_set_mempolicy(MPOL_INTERLEAVE, 0, &interleave_nodes))
 		pr_err("%s: interleaving failed\n", __func__);
 
+	hotplug_node_notifier(wi_state_node_notifier, DEFAULT_CALLBACK_PRI);
 	check_numabalancing_enable();
 }
 
@@ -3910,15 +3937,8 @@ static int wi_node_notifier(struct notif
 	case NODE_REMOVED_LAST_MEMORY:
 		sysfs_wi_node_delete(nid);
 		break;
-	default:
-		return NOTIFY_OK;
 	}
 
-	/*
-	 * HMAT and CXL report a node's bandwidth only when it first gains
-	 * memory, so recompute the weights whenever N_MEMORY changes.
-	 */
-	wi_state_refresh();
 	return NOTIFY_OK;
 }
 
_


      reply	other threads:[~2026-10-30 23:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 16:12 Gregory Price (Meta)
2026-10-30 16:35 ` Joshua Hahn
2026-10-30 23:43   ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261030164303.02c5cce0521c3d6fd4ddf015@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=harry@kernel.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rakie.kim@sk.com \
    --cc=stable@vger.kernel.org \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®