mm/mempolicy: introduce package-aware weighted interleave
Subsystems (6)
Rakie Kim
reviewercover mm/mempolicy: introduce package-aware weighted interleave
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
Changes from RFC:
https://lore.kernel.org/all/[email protected]/
- Added an opt-in sysfs toggle (off by default) and a read-only sysfs view of the package topology
- Added topology validation with a clean fallback to plain weighted interleave on unsupported topologies
- Hardened the allocation, device-teardown, and node-hotplug paths
Weighted interleave places pages on nodes in proportion to per-node weights that are set from each node's bandwidth. Within one package the weight given to a node matches the bandwidth a task sees from it. Across packages it no longer does: a memory node's physical bandwidth is fixed, but the bandwidth a task effectively sees depends on which package its CPU is in, because memory reached from another package, over the interconnect between them, is slower than the same memory reached within the package. The weights are set once from device bandwidth and applied the same way wherever the task runs, so a node in another package is given a weight higher than the bandwidth it can deliver to that task. The kernel has no package abstraction and does not record which package a node belongs to, so it cannot tell which node pairs are separated by the interconnect.
node0 node1
+-------+ +-------+
| CPU 0 |---------| CPU 1 |
+-------+ +-------+
| DRAM0 | | DRAM1 |
+---+---+ +---+---+
| |
+---+---+ +---+---+
| CXL 0 | | CXL 1 |
+-------+ +-------+
node2 node3The numbers below are illustrative single-stream bandwidths (GB/s). Local DRAM sustains 300 and local CXL 150; any path that crosses to another package, over the interconnect, is capped at 100, so a node in another package delivers 100 whether it is DRAM or CXL. Note that local CXL (150) is still faster than any node in another package (100). The effective bandwidth each CPU sees is therefore:
node0 node1 node2 node3
from CPU 0: 300 100 150 100 from CPU 1: 100 300 100 150
Since a single per-node weight cannot encode the interconnect penalty, a reasonable set of global weights is taken from local device bandwidth (local DRAM : local CXL = 300 : 150 = 2 : 1): node0=2 node1=2 node2=1 node3=1.
Applied the same way to every source, these weights give the map:
node0 node1 node2 node3
global: 2 2 1 1
A task on CPU 0 gives node1 - remote DRAM, effective 100 - the same weight 2 as its own local node0 at 300. Worse, node1 is weighted above node2, the task's local CXL at effective 150, even though node2 is the faster of the two. The flat weights rank a slower interconnect-bound node above a faster local one, which is exactly backwards.
This series makes weighted interleave package-aware. When it is on, weighted interleave prefers the task's current package: while the package's nodes have room, the task's pages are spread across them by weight, so allocations stay off the interconnect. The rest of the policy nodemask is used when the local package cannot serve the request
- when a node in it is under pressure and the page allocator falls back along the zonelist, or when the policy nodemask happens to exclude every node of the current package, in which case the package spanned by the policy's own nodes is used instead. The nodes considered are always within the policy nodemask, which mempolicy already narrows to the task's cpuset, so cpusets and the task nodemask stay in control.
node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1
A task on CPU 0 now places pages on node0 (weight 2) and node2 (weight 1) at 2:1, which matches their effective bandwidth of 300:150; a task on CPU 1 places on node1 and node3 the same way. Placement follows the bandwidth each task actually sees, NUMA locality is preserved, and interleave traffic stays off the interconnect.
To make this possible the kernel needs a notion of which nodes share a package. The NUMA distance model offers only relative latencies and no structural grouping, which is especially limiting for CXL memory nodes that come online without an explicit package association.
The series adds a package-aware topology layer that groups CPU and memory-only nodes into a "memory package", built from the physical package ids firmware reports and, for a memory-only node, an initiator CPU node or SLIT distances. A package can contain more than one CPU node or more than one memory-only node, so the layer maps a package to a set of nodes rather than to a single node or a single CXL device.
The feature is off by default and opt-in through a sysfs toggle. The package topology itself is exposed read-only under /sys/devices/system/package/; there is deliberately no writable override, since a machine whose firmware describes its topology incorrectly should be fixed in firmware. On a topology that does not have the symmetric shape the placement relies on, enabling is refused and any active mode degrades cleanly to the original flat behavior.
Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)
1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)
2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)
A small CXL driver change registers a CXL memory node into its package as the node comes online, using the initiator the driver resolves for the region; this is where the package layer gets the CPU-side association that plain NUMA distance does not carry.
The memory_package layer offers a broader interface for grouping and querying package topology - usable by memory tiering as well - and package-aware weighted interleave uses the subset it needs.
[PATCH 1/4] mm/numa: introduce nearest_nodes_nodemask()
Add a NUMA helper that returns every node sharing the minimum distance from a source node.
[PATCH 2/4] mm/memory-tiers: package-aware topology management
Group NUMA nodes into memory packages from firmware topology data, expose the grouping read-only under /sys/devices/system/package/, and validate the symmetric shape that package-aware placement relies on.
[PATCH 3/4] mm/memory-tiers: register CXL nodes to packages
Bind a CXL memory node to a package using an initiator CPU node.
[PATCH 4/4] mm/mempolicy: package-aware weighted interleave
Prefer the current package for weighted interleave node selection, behind an opt-in package_mode sysfs toggle that is off by default.
Rakie Kim (4):
mm/numa: introduce nearest_nodes_nodemask() mm/memory-tiers: introduce package-aware topology management for NUMA
nodes
mm/memory-tiers: register CXL nodes to memory packages via initiator mm/mempolicy: enhance weighted interleave with package-aware locality
.../ABI/testing/sysfs-devices-system-package | 35 + ...fs-kernel-mm-mempolicy-weighted-interleave | 17 + drivers/cxl/core/region.c | 54 + drivers/cxl/cxl.h | 1 + drivers/dax/kmem.c | 3 + include/linux/memory-tiers.h | 113 ++ include/linux/numa.h | 11 + mm/memory-tiers.c | 1009 +++++++++++++++++ mm/mempolicy.c | 200 +++- 9 files changed, 1439 insertions(+), 4 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-system-package
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
Signature · 1 line
2.25.1
Rakie Kim
reviewerPATCH 1/4 mm/numa: introduce nearest_nodes_nodemask()
Add a NUMA helper, nearest_nodes_nodemask(), that returns every node in a given nodemask located at the minimum distance from a source node.
Unlike nearest_node_nodemask(), which returns only a single node, this helper reports the complete set of nodes that share the closest distance. This is needed when several nodes are equally near and all of the nearest candidates must be considered together.
The helper clears the output nodemask and sets every node that meets the minimum-distance condition. It returns 0 on success, or -EINVAL when the output argument is invalid.
--- include/linux/numa.h | 11 +++++++++++ mm/mempolicy.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
include/linux/numa.h +11 -0
@@ -33,6 +33,8 @@ int numa_nearest_node(int node, unsigned int state);int nearest_node_nodemask (int node,nodemask_t *mask); +int nearest_nodes_nodemask (int node,const nodemask_t *mask,nodemask_t *out); +#ifndef memory_add_physaddr_to_nidint memory_add_physaddr_to_nid (u64 start);#endif
@@ -54,6 +56,15 @@ static inline int nearest_node_nodemask(int node, nodemask_t *mask)return NUMA_NO_NODE ; } +static inline int nearest_nodes_nodemask (int node,const nodemask_t *mask, +nodemask_t *out) +{ +if (!out) +return -EINVAL ; +nodes_clear (*out); +return 0 ; +} +static inline int memory_add_physaddr_to_nid (u64 start) {return 0 ;
mm/mempolicy.c +41 -0
47 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH 1/4] mm/numa: introduce nearest_nodes_nodemask()
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The function fails silently if the input and output nodemasks alias, wiping the input. - [Low]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The function fails silently if the input and output nodemasks alias, wiping the input.
- [Low] The non-NUMA fallback implementation incorrectly reports an empty mask for valid inputs. --
--- Patch [1]: [PATCH 1/4] mm/numa: introduce nearest_nodes_nodemask() --- commit 5ec50dc5c5bbc33fbae64a16296aa9f2dc086600
Author: Rakie Kim <[email protected]>
mm/numa: introduce nearest_nodes_nodemask()
This commit introduces nearest_nodes_nodemask(), a helper function that finds all candidate nodes in a given nodemask located at the minimum distance from a source node. It updates an output nodemask with the complete set of nearest nodes, returning 0 on success.
Quoted 4 lines
include/linux/numa.h +0
-0
[ ... ]
include/linux/numa.h static inline int nearest_node_nodemask(int node, nodemask_t *mask) · line 64
Quoted 10 lines
include/linux/numa.h +6
-0@@ -54,6 +56,15 @@ static inline int nearest_node_nodemask(int node, nodemask_t *mask)return NUMA_NO_NODE ; } +static inline int nearest_nodes_nodemask (int node,const nodemask_t *mask, +nodemask_t *out) +{ +if (!out) +return -EINVAL ; +nodes_clear (*out);
[Severity: Low]
On systems with CONFIG_NUMA disabled, there is only a single implicit node (Node 0). If a caller passes an input mask containing Node 0, that node is trivially the nearest.
Should this fallback stub preserve the valid node from the input mask instead of unconditionally clearing the output mask and falsely reporting no nearest nodes?
Quoted 10 lines
include/linux/numa.h +3
-0+return 0 ; +} +static inline int memory_add_physaddr_to_nid (u64 start) {return 0 ;mm/mempolicy.c +0
-0
[ ... ]
mm/mempolicy.c int nearest_node_nodemask(int node, nodemask_t *mask) · line 363
Quoted 8 lines
mm/mempolicy.c +8
-0+int nearest_nodes_nodemask (int node,const nodemask_t *mask,nodemask_t *out) +{ +int dist, n, min_dist =INT_MAX ; + +if (!out) +return -EINVAL ; + +nodes_clear (*out);
[Severity: Medium]
What happens if a caller attempts to filter a nodemask in-place by passing the same pointer for both the input and output masks?
In-place filtering is a common pattern in the kernel (for example, with nodes_and()), but if nearest_nodes_nodemask(node, &my_mask, &my_mask) is called, this initial nodes_clear(*out) will wipe out the input mask before the loop even begins iterating.
mm/mempolicy.c int nearest_node_nodemask(int node, nodemask_t *mask) · line 370
Quoted 7 lines
mm/mempolicy.c +7
-0+ +for_each_node_mask (n, *mask) { + dist =node_distance (node, n); + +if (dist < min_dist) { + min_dist = dist; +nodes_clear (*out);
[Severity: Medium]
Similarly, if the input and output pointers alias, clearing the output mask dynamically here destroys the remaining iteration state for the for_each loop.
Could this be avoided by using a temporary nodemask on the stack, and copying it to *out at the end of the function?
Quoted 10 lines
mm/mempolicy.c +10
-0+node_set (n, *out); + }else if (dist == min_dist) { +node_set (n, *out); + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (nearest_nodes_nodemask); +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Rakie Kim
reviewerPATCH 2/4 mm/memory-tiers: introduce package-aware topology management for NUMA nodes
In reply to Rakie KimThe NUMA distance model provides only relative latency values between nodes and has no notion of structural grouping. Memory policies based on distance alone therefore cannot tell which nodes are local to the same physical package and which belong to a different one, which limits how well they can keep placement and migration within a package.
Introduce a package-aware topology layer that groups NUMA nodes into a "memory package": a set of CPU nodes and their local memory-only nodes (such as CXL or HBM). A subsystem that owns a node registers a resolver to supply its package, and a policy can query, for any node, the other nodes that belong to the same package.
The grouping is built from the information firmware already provides, as nodes come online. A CPU node is placed in the package named by its firmware physical package id. A memory-only node is placed by an initiator CPU node when a driver supplies one, or otherwise by its nearest CPU node under the SLIT distance table; a SLIT-derived entry is provisional and is upgraded once a driver supplies an initiator. This makes the package association explicit so that policies can consume it, and the mapping can be revisited as firmware interfaces expose better information.
A single package may hold more than one CPU node or more than one memory-only node, so the model does not assume a one-to-one package to node or package to CXL device relationship.
The current package topology is exposed read-only under /sys/devices/system/package/packageN/: package_nodes (all NUMA nodes in the package), package_cpu_nodes (CPU nodes), package_mem_only_nodes (memory-only nodes), physical_package_id (physical package id).
The interface is read-only by design: it reports the topology the kernel derived but does not let user space override it. A machine whose firmware describes the topology incorrectly should be fixed in firmware rather than papered over through sysfs.
Topology is also validated for the symmetric shape that package-aware placement relies on - every package having the same number of CPU and memory-only nodes, at least two packages, and at least two nodes per package. The verdict is recomputed at boot and on node hotplug and is published for policies to consult.
On any topology that does not meet these conditions the verdict is simply false, so a consumer degrades to its original, non-package-aware behavior instead of acting on a grouping that does not describe the machine.
--- .../ABI/testing/sysfs-devices-system-package | 35 + include/linux/memory-tiers.h | 113 ++ mm/memory-tiers.c | 1009 +++++++++++++++++ 3 files changed, 1157 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-devices-system-package
Documentation/ABI/testing/sysfs-devices-system-package new file +35 -0
@@ -0,0 +1,35 @@ +What: /sys/devices/system/package/ +Date: August 2026 +Contact: Linux memory management mailing list <[email protected]> +Description: Memory package topology + + A "memory package" groups the NUMA nodes associated with one + physical CPU package (socket): the nodes that have CPUs and + the nodes that only have memory (e.g. CXL or HBM). + + All attributes are read-only; the topology cannot be + overridden from user space. + +What: /sys/devices/system/package/packageN/package_nodes +Date: August 2026 +Contact: Linux memory management mailing list <[email protected]> +Description: All NUMA nodes in this package, in nodelist format + (e.g. "0,2"). + +What: /sys/devices/system/package/packageN/package_cpu_nodes +Date: August 2026 +Contact: Linux memory management mailing list <[email protected]> +Description: The nodes that have CPUs in this package, in nodelist + format. + +What: /sys/devices/system/package/packageN/package_mem_only_nodes +Date: August 2026 +Contact: Linux memory management mailing list <[email protected]> +Description: The nodes that only have memory (e.g. CXL/HBM) in this + package, in nodelist format. + +What: /sys/devices/system/package/packageN/physical_package_id +Date: August 2026 +Contact: Linux memory management mailing list <[email protected]> +Description: The physical package id this group corresponds to, as + reported by CPU topology.
include/linux/memory-tiers.h +113 -0
134 lines not on this page · raw message
mm/memory-tiers.c +1009 -0
1,022 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH 2/4] mm/memory-tiers: introduce package-aware topology management for NUMA nodes
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider: - [High] CPU nodes without local memory are completely excluded from the package topology. - [High]…
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
- [High] CPU nodes without local memory are completely excluded from the package topology.
- [High] Upgrading a provisional SLIT entry permanently unbinds and orphans the node.
- [High] TOCTOU race in bind_node_to_package binds a newly upgraded node to the wrong package.
- [High] unbind_node_to_package clears the node from the wrong nodemask if the node's state changed, permanently leaking the package.
- [High] memory_package_lock is acquired in a reclaim path while also being held during a GFP_KERNEL allocation, causing a deadlock.
- [Medium] Initialization loop in memory_package_init() permanently leaks kobjects and sysfs devices on failure.
- [Medium] Mixing goto-based error handling with scope-based guard() violates strict cleanup guidelines.
- [Medium] Global topology symmetry state is not recalculated when a provisional node is dropped.
- [Medium] The package notifier chain is exported but never invoked during node creation.
- [Medium] Exported API mp_add_package_node_by_initiator lacks bounds checking on nid, causing an out-of-bounds array access. --
--- Patch [2]: [PATCH 2/4] mm/memory-tiers: introduce package-aware topology management for NUMA nodes --- commit 0e269cf99bac40f9c00f53199f76f3781bc439c6
Author: Rakie Kim <[email protected]> Date: Thu Aug 6 08:09:33 2026 +0000
mm/memory-tiers: introduce package-aware topology management for NUMA nodes
The NUMA distance model provides only relative latency values between nodes and has no notion of structural grouping. Memory policies based on distance alone therefore cannot tell which nodes are local to the same physical package and which belong to a different one, which limits how well they can keep placement and migration within a package.
Introduce a package-aware topology layer that groups NUMA nodes into a "memory package": a set of CPU nodes and their local memory-only nodes (such as CXL or HBM). A subsystem that owns a node registers a resolver to supply its package, and a policy can query, for any node, the other nodes that belong to the same package.
Quoted 4 lines
mm/memory-tiers.c +0
-0
[ ... ]
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1337
Quoted 12 lines
mm/memory-tiers.c +12
-0+static void mp_snapshot_rebuild (void ) +{ +struct mp_snapshot *new, *old; +struct memory_package *mp; +int nr =0 , i =0 , nid; + +lockdep_assert_held (&memory_package_lock); + +list_for_each_entry (mp, &memory_packages, list) + nr++; + + new =kvzalloc (struct_size (new, pkg, nr),GFP_KERNEL );
[Severity: High]
Could this allocation trigger a deadlock?
The memory_package_lock is held here during a GFP_KERNEL allocation, which can trigger direct reclaim. However, the same lock is acquired in __mp_get_preferred_nodemask() during memory demotion, which runs in reclaim context.
If direct reclaim attempts to acquire the already held lock, will it cause a self-deadlock?
Quoted 2 lines
mm/memory-tiers.c +2
-0+if (!new) +return ;
[ ... ]
Quoted 14 lines
mm/memory-tiers.c +14
-0+static int bind_node_to_package (int nid) +{ +int package_id, pkg_id; +struct memory_package *mp; +nodemask_t nodes, cpu, mem; + +mutex_lock (&memory_package_lock); +if (!mpns[nid]) { +mutex_unlock (&memory_package_lock); +return -EINVAL ; + } + package_id = mpns[nid]->package_id; +mutex_unlock (&memory_package_lock); +
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1382
Quoted 10 lines
mm/memory-tiers.c +10
-0+ mp =find_create_memory_package (package_id); +if (IS_ERR (mp)) +return PTR_ERR (mp); + +mutex_lock (&memory_package_lock); +if (!mpns[nid]) { +mutex_unlock (&memory_package_lock); +return -ENOENT ; + } + mpns[nid]->package = mp;
[Severity: High]
Is there a race condition when the lock is dropped and reacquired?
If a concurrent driver probe calls mp_add_package_node_by_initiator() while the lock is dropped, it might destroy the old mpns[nid] and create a new one with a different package_id.
When the lock is reacquired, mpns[nid] is not NULL, but could we end up binding the new node (which wants the new package ID) to the old package struct that we just fetched?
Quoted 1 line
mm/memory-tiers.c +1
-0+node_set (mpns[nid]->nid, mp->nodes);
[ ... ]
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1414
Quoted 9 lines
mm/memory-tiers.c +9
-0+static void unbind_node_to_package (struct memory_package *mp,int nid) +{ +lockdep_assert_held (&memory_package_lock); + +node_clear (nid, mp->nodes); +if (node_state (nid,N_CPU )) +node_clear (nid, mp->cpu_nodes); +else +node_clear (nid, mp->memory_only_nodes);
[Severity: High]
Does this clear the node from the correct nodemask if its state changed?
If a memory-only node was initially added to mp->memory_only_nodes, but CPUs were later hot-added to it, node_state(nid, N_CPU) will now evaluate to true.
During a subsequent hot-remove, this will clear the bit from mp->cpu_nodes instead of mp->memory_only_nodes, leaving the bit permanently set and potentially leaking the kobject.
Quoted 19 lines
mm/memory-tiers.c +19
-0+ +if (mpns[nid]) +list_del (&mpns[nid]->package_entry); + +update_package_preferred (mp); +} + +static struct memory_package_node *create_package_node (int nid,int initiator_nid) +{ +int cpu_nid, package_id; +int source_flags; +struct memory_package_node *mpn; + +if (node_state (nid,N_CPU )) { + cpu_nid = nid; + source_flags =MPN_SRC_CPU ; + }else { +if (initiator_nid >=0 ) { + cpu_nid = initiator_nid;
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1443
Quoted 10 lines
mm/memory-tiers.c +10
-0+ source_flags =MPN_SRC_INITIATOR ; + }else { +/* +* No driver-supplied initiator: fall back to the +* nearest CPU node (via SLIT/numa_distance). +*/ + cpu_nid =numa_nearest_node (nid,N_CPU ); + source_flags =MPN_SRC_SLIT ; + } + }
[Severity: Medium]
Are we missing a call to the exported package notifier chain here?
The register_mp_package_notifier() and mp_probe_package_id() APIs are provided so subsystems can supply package hints, but mp_probe_package_id() is never called in the node creation flow.
If a node is created without an explicit initiator, shouldn't we invoke the notifier before falling back directly to numa_nearest_node()?
Quoted 2 lines
mm/memory-tiers.c +2
-0+ + package_id =mp_node_to_package_id (cpu_nid);
[ ... ]
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1522
Quoted 7 lines
mm/memory-tiers.c +7
-0+static int find_package_node (int nid,int initiator_nid) +{ +struct memory_package *unreg_mp =NULL ; +int ret = nid; + +mutex_lock (&memory_package_lock); +if (!mpns[nid]) {
[Severity: Medium]
Is it safe to index the mpns array with nid here?
The nid is passed directly from mp_add_package_node_by_initiator(), which is an exported API. If a driver processes malformed or malicious firmware tables, could an unvalidated nid cause an out-of-bounds array access?
Quoted 7 lines
mm/memory-tiers.c +7
-0+ ret =NUMA_NO_NODE ; + }else if (mpns[nid]->source_flags ==MPN_SRC_SLIT && initiator_nid >=0 ) { +/* +* SLIT-derived entries are provisional; if a driver later +* provides an explicit initiator, drop the provisional +* entry and rebuild with the stronger hint. +*/
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1539
Quoted 10 lines
mm/memory-tiers.c +10
-0+ unreg_mp =__destroy_package_node (nid); + ret =NUMA_NO_NODE ; + } +mutex_unlock (&memory_package_lock); + +if (unreg_mp) +device_unregister (&unreg_mp->dev); + +return ret; +}
[Severity: Medium]
Should we recalculate the global topology symmetry state here?
When an existing provisional SLIT-derived node is dropped to make way for an explicit driver initiator, __destroy_package_node() modifies the package node counts. However, validate_topology_symmetry() is not called before returning.
Will the system's symmetry verdict remain stale until another completely unrelated hotplug event triggers a recalculation?
[ ... ]
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1601
Quoted 11 lines
mm/memory-tiers.c +11
-0+int mp_add_package_node_by_initiator (int nid,int initiator_nid) +{ +int ret; + + ret =find_create_package_node (nid, initiator_nid); +if (ret <0 ) +return ret; + +return 0 ; +} +EXPORT_SYMBOL_GPL (mp_add_package_node_by_initiator);
[Severity: High]
Does upgrading a provisional SLIT entry permanently drop it from the topology?
If a driver calls this function to supply an initiator for a node that was already initialized at boot, find_create_package_node() destroys the old entry and creates a new mpns[nid].
However, we simply return 0 here without calling bind_node_to_package(). Since the node is already online, no hotplug event will fire to bind it, potentially leaving mpn->package as NULL and orphaning the node.
[ ... ]
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 1671
Quoted 12 lines
mm/memory-tiers.c +12
-0+static int __mp_get_preferred_nodemask (int nid,enum mp_nodes_type node_type, +nodemask_t *out) +{ +int ret =0 ; + +/* No hot-path callers: the mutex is fine here. */ +guard (mutex)(&memory_package_lock); + +if (!out) { + ret = -EINVAL ; + goto out; + }
[Severity: Medium]
Does this mix goto-based error handling with scope-based guard() blocks?
The kernel's cleanup subsystem guidelines in include/linux/cleanup.h explicitly forbid mixing goto jumps with guard() cleanup declarations in the same function, as it can create unsafe ownership semantics.
[ ... ]
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 2004
Quoted 7 lines
mm/memory-tiers.c +7
-0+static int __init memory_package_init (void ) +{ +int ret =0 , nid; + +for_each_online_node (nid) { +if (!node_state (nid,N_MEMORY )) +continue ;
[Severity: High]
Are CPU nodes without local memory completely excluded from the topology?
If a CPU node evaluates to false for N_MEMORY, it will be skipped entirely. This would cause update_package_preferred() to find an empty CPU mask for memory-only nodes in that package, potentially breaking memory promotion by leaving a memory-only node to set itself as its preferred promotion target.
mm/memory-tiers.c static int __init numa_init_sysfs(void) · line 2008
Quoted 4 lines
mm/memory-tiers.c +4
-0+ + ret =create_node_with_package (nid); +if (ret) + goto out;
[Severity: Medium]
Does this leak prior successfully initialized nodes on failure?
If an allocation or registration fails inside create_node_with_package(), the code jumps directly to out.
Without a centralized rollback loop to individually clean up the successfully established memory_package devices and kobjects, will this result in a permanent unrecoverable memory leak?
Quoted 10 lines
mm/memory-tiers.c +10
-0+ } + +hotplug_node_notifier (mp_hotplug_callback,MEMTIER_HOTPLUG_PRI ); + +validate_topology_symmetry (); + +out: +return ret; +} +late_initcall (memory_package_init);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Rakie Kim
reviewerPATCH 3/4 mm/memory-tiers: register CXL nodes to memory packages via initiator
In reply to Rakie KimA CXL memory node comes online without an explicit package association, and plain NUMA distance does not convey which physical package it belongs to. Without that association a CXL node cannot be grouped with the CPUs that front it.
Register a package notifier per CXL region. When the region's memory node comes online, the notifier resolves an initiator CPU node - the NUMA node of the first memdev backing the region - and binds the memory node to that initiator's package. This gives the topology layer the CPU-side association that plain NUMA distance does not carry.
The initiator nid comes from the firmware and driver description of the region's endpoint, so the association is only as accurate as that description; it gives a more direct host-side grouping than flat distance values.
--- drivers/cxl/core/region.c | 54 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 1 + drivers/dax/kmem.c | 3 +++ 3 files changed, 58 insertions(+)
drivers/cxl/core/region.c +54 -0
@@ -2673,6 +2673,55 @@ static int cxl_region_calculate_adistance(struct notifier_block *nb,return NOTIFY_STOP ; } +/* +* Find a NUMA node to act as the initiator for this region: scan the +* region's endpoint targets and return the first one that resolves to a +* valid NUMA node. +*/ +static int cxl_region_find_nearest_node (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +struct cxl_endpoint_decoder *cxled =NULL ; +struct cxl_memdev *cxlmd =NULL ; +int i, numa_node; + +for (i =0 ; i < p->nr_targets; i++) { + cxled = p->targets[i]; + cxlmd =cxled_to_memdev (cxled); + numa_node =dev_to_node (&cxlmd->dev); +if (numa_node !=NUMA_NO_NODE ) +return numa_node; + } +return NUMA_NO_NODE ; +} + +/* +* Package notifier callback: when a new memory node is onlined via dax +* kmem, bind the node this CXL region backs to its memory package, using +* the nearest region target as the initiator. Notifications for other +* nodes are ignored. +*/ +static int cxl_region_add_package_node (struct notifier_block *nb, +unsigned long dax_nid,void *data) +{ +int region_nid, nearest_nid, ret; + struct cxl_region *cxlr = container_of(nb, struct cxl_region, package_notifier); + + region_nid =phys_to_target_node (cxlr->params.res->start); +if (region_nid != dax_nid) +return NOTIFY_DONE ; + + nearest_nid =cxl_region_find_nearest_node (cxlr); +if (nearest_nid ==NUMA_NO_NODE ) +return NOTIFY_DONE ; + + ret =mp_add_package_node_by_initiator (dax_nid, nearest_nid); +if (ret) +return NOTIFY_DONE ; + +return NOTIFY_OK ; +} +/** * devm_cxl_add_region - Adds a region to a decoder * @cxlrd: root decoder
@@ -3852,6 +3901,7 @@ static void shutdown_notifiers(void *_cxlr)unregister_node_notifier (&cxlr->node_notifier);unregister_mt_adistance_algorithm (&cxlr->adist_notifier); +unregister_mp_package_notifier (&cxlr->package_notifier); }static void remove_debugfs (void *dentry)
@@ -4066,6 +4116,10 @@ static int cxl_region_probe(struct device *dev) cxlr->adist_notifier.priority =100 ;register_mt_adistance_algorithm (&cxlr->adist_notifier); + cxlr->package_notifier.notifier_call = cxl_region_add_package_node; + cxlr->package_notifier.priority =100 ; +register_mp_package_notifier (&cxlr->package_notifier); + rc =devm_add_action_or_reset (&cxlr->dev, shutdown_notifiers, cxlr);if (rc)return rc;
drivers/cxl/cxl.h +1 -0
@@ -477,6 +477,7 @@ struct cxl_region {struct access_coordinate coord[ACCESS_COORDINATE_MAX ];struct notifier_block node_notifier;struct notifier_block adist_notifier; +struct notifier_block package_notifier; };struct cxl_nvdimm_bridge {
drivers/dax/kmem.c +3 -0
@@ -94,6 +94,9 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)if (IS_ERR (mtype))return PTR_ERR (mtype); +/* Resolve the memory package for this newly onlined kmem node. */ +mp_probe_package_id (numa_node); +for (i =0 ; i < dev_dax->nr_range; i++) {struct range range;
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH 3/4] mm/memory-tiers: register CXL nodes to memory packages via initiator
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] cxl_region_find_nearest_node() incorrectly uses p->nr_targets as an upper bound and assumes a dense array, causing a NULL pointer dereference when accessing sparse targets.
- [High] The package notifier callback cxl_region_add_package_node accesses region parameters and targets without holding the required cxl_rwsem.region lock, allowing race conditions with concurrent region teardown.
Pre-existing issues:
- [High] Preexisting loops iterating over p->targets up to p->nr_targets fail to check for NULL pointers, leading to potential crashes when the array is sparse. --
--- Patch [3]: [PATCH 3/4] mm/memory-tiers: register CXL nodes to memory packages via initiator --- commit dff9dccb7111817b944d1f03a5ff003c16d488a5
Author: Rakie Kim <[email protected]>
mm/memory-tiers: register CXL nodes to memory packages via initiator
A CXL memory node comes online without an explicit package association, and plain NUMA distance does not convey which physical package it belongs to. Without that association a CXL node cannot be grouped with the CPUs that front it.
Register a package notifier per CXL region. When the region's memory node comes online, the notifier resolves an initiator CPU node - the NUMA node of the first memdev backing the region - and binds the memory node to that initiator's package. This gives the topology layer the CPU-side association that plain NUMA distance does not carry.
Quoted 13 lines
drivers/cxl/core/region.c +5
-0@@ -2673,6 +2673,55 @@ static int cxl_region_calculate_adistance(struct notifier_block *nb,return NOTIFY_STOP ; } +/* +* Find a NUMA node to act as the initiator for this region: scan the +* region's endpoint targets and return the first one that resolves to a +* valid NUMA node. +*/
drivers/cxl/core/region.c static int cxl_region_calculate_adistance(struct notifier_block *nb, · line 2690
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+static int cxl_region_find_nearest_node (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +struct cxl_endpoint_decoder *cxled =NULL ; +struct cxl_memdev *cxlmd =NULL ; +int i, numa_node; + +for (i =0 ; i < p->nr_targets; i++) { + cxled = p->targets[i]; + cxlmd =cxled_to_memdev (cxled);
[Severity: High]
Does this code handle sparse target arrays correctly?
If __cxl_decoder_detach() clears elements in p->targets[] and decrements p->nr_targets when a target is detached, the array can become sparse. When iterating using p->nr_targets as an upper bound, could p->targets[i] be NULL for detached targets?
Passing a NULL cxled to cxled_to_memdev() will immediately dereference cxled->cxld.dev.parent, potentially causing a kernel panic.
[Severity: High]
This isn't a bug introduced by this patch, but the same missing NULL check appears to be a pre-existing issue in other functions iterating p->targets.
For example, in cxl_dpa_to_hpa():
drivers/cxl/core/region.c:cxl_dpa_to_hpa() {
...
for (int i = 0; i < p->nr_targets; i++) {
if (cxlmd == cxled_to_memdev(p->targets[i])) {
...
}And in region_offset_to_dpa_result():
drivers/cxl/core/region.c:region_offset_to_dpa_result() {
...
for (int i = 0; i < p->nr_targets; i++) {
cxled = p->targets[i];
if (cxled->pos != pos)
...
}Should these loops also check if p->targets[i] is NULL before dereferencing it?
Quoted 14 lines
drivers/cxl/core/region.c +14
-0+ numa_node =dev_to_node (&cxlmd->dev); +if (numa_node !=NUMA_NO_NODE ) +return numa_node; + } +return NUMA_NO_NODE ; +} + +/* +* Package notifier callback: when a new memory node is onlined via dax +* kmem, bind the node this CXL region backs to its memory package, using +* the nearest region target as the initiator. Notifications for other +* nodes are ignored. +*/ +static int cxl_region_add_package_node(struct notifier_block *nb,
drivers/cxl/core/region.c static int cxl_region_calculate_adistance(struct notifier_block *nb, · line 2714
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+ unsigned long dax_nid, void *data) +{ + int region_nid, nearest_nid, ret; + struct cxl_region *cxlr = container_of(nb, struct cxl_region, package_notifier); + + region_nid =phys_to_target_node (cxlr->params.res->start); +if (region_nid != dax_nid) +return NOTIFY_DONE ; + + nearest_nid =cxl_region_find_nearest_node (cxlr);
[Severity: High]
Does this callback need to hold the cxl_rwsem.region lock when accessing shared region parameters?
This notifier can be called asynchronously when a DAX kmem node is probed. It accesses cxlr->params.res->start and p->targets without holding the topology lock.
Concurrently, cxl_decoder_detach() could modify p->targets, or teardown logic could free p->res under the cxl_rwsem.region write lock. Could this race condition result in a use-after-free or NULL pointer dereference?
Quoted 9 lines
drivers/cxl/core/region.c +9
-0+if (nearest_nid ==NUMA_NO_NODE ) +return NOTIFY_DONE ; + + ret =mp_add_package_node_by_initiator (dax_nid, nearest_nid); +if (ret) +return NOTIFY_DONE ; + +return NOTIFY_OK ; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Rakie Kim
reviewerPATCH 4/4 mm/mempolicy: enhance weighted interleave with package-aware locality
In reply to Rakie KimWeighted interleave places pages on nodes in proportion to per-node weights derived from each node's bandwidth. Within one package the weight given to a node matches the bandwidth a task sees from it; across packages it does not. The weights are set once from device bandwidth and applied the same way wherever the task runs, but memory reached over the interconnect to another package is slower than the same memory reached locally, so a node in another package is given a weight higher than the bandwidth it can deliver to the task. Flat weighted interleave then steers allocations onto the interconnect even when local capacity exists, degrading effective bandwidth.
node0 node1
+-------+ +-------+
| CPU 0 |---------| CPU 1 |
+-------+ +-------+
| DRAM0 | | DRAM1 |
+---+---+ +---+---+
| |
+---+---+ +---+---+
| CXL 0 | | CXL 1 |
+-------+ +-------+
node2 node3The numbers below are illustrative single-stream bandwidths (GB/s). Local DRAM sustains 300 and local CXL 150; any path that crosses to another package, over the interconnect, is capped at 100, so a node in another package delivers 100 whether it is DRAM or CXL. Local CXL (150) is still faster than any node in another package (100). The effective bandwidth each CPU sees is:
node0 node1 node2 node3
from CPU 0: 300 100 150 100 from CPU 1: 100 300 100 150
Since a single per-node weight cannot encode the interconnect penalty, a reasonable set of global weights is taken from local device bandwidth (local DRAM : local CXL = 300 : 150 = 2 : 1): node0=2 node1=2 node2=1 node3=1.
node0 node1 node2 node3
global: 2 2 1 1 (same wherever the task runs)
A task on CPU 0 gives node1 - remote DRAM, effective 100 - the same weight 2 as its own local node0 at 300. Worse, node1 is weighted above node2, the task's local CXL at effective 150, even though node2 is the faster of the two. The flat weights rank a slower interconnect-bound node above a faster local one, which is exactly backwards.
Make weighted interleave package-aware. When enabled, node selection is restricted to the nodes of the task's current package, intersected with the policy nodemask: the task's pages are spread by weight across the package's nodes, and nodes outside the package are not part of the selection.
The only mask-level fallback is the empty-intersection case - if the policy nodemask excludes every node of the current package, selection falls back to the package spanned by the policy's own nodes, so a misconfiguration never yields an empty candidate set. There is no spill to a remote package as a placement preference.
Availability is still preferred over containment at allocation time: the resolved mask constrains node selection only, and the page allocator is invoked without a package nodemask, so when the selected node is exhausted the allocation is served from another node - exactly as plain weighted interleave already behaves - rather than forcing reclaim on the local package.
The resolved mask is by construction a subset of the policy nodemask, which mempolicy already restricts to the task's cpuset; package mode can only narrow that set, never widen it, so cpusets and the task nodemask remain authoritative.
node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1
Tasks on CPU 0 place pages on DRAM0(2) and CXL0(1) at 2:1, which matches their effective bandwidth of 300:150; tasks on CPU 1 place on DRAM1(2) and CXL1(1) the same way. This aligns allocation with per-package bandwidth, preserves NUMA locality, and keeps interleave traffic off the saturable cross-socket interconnect.
The behavior is opt-in and off by default. A sysfs toggle at /sys/kernel/mm/mempolicy/weighted_interleave/package_mode turns it on or off at runtime; reading it reports the current setting.
Enabling is refused on a topology that is not symmetric (see /sys/devices/system/package/), and if the topology stops being symmetric while the mode is on - for example after node hotplug - weighted interleave transparently degrades to its flat behavior while the configured value is preserved and takes effect again once the topology is symmetric.
The following are the results with package-aware weighted interleave applied:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)
1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)
2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)
--- ...fs-kernel-mm-mempolicy-weighted-interleave | 17 ++ mm/mempolicy.c | 159 +++++++++++++++++- 2 files changed, 172 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-kernel-mm-mempolicy-weighted-interleave +17 -0
@@ -52,3 +52,20 @@ Description: Auto-weighting configuration interface Writing a new weight to a node directly via the nodeN interface will also automatically switch the system to manual mode. + +What: /sys/kernel/mm/mempolicy/weighted_interleave/package_mode +Date: August 2026 +Contact: Linux memory management mailing list <[email protected]> +Description: Package-aware weighted interleave toggle + + 'true' restricts weighted interleave node selection to the + NUMA nodes of the package (CPU socket) the allocating task + is running on. 'false' (the default) uses the existing + weighted interleave behavior. + + Enabling is rejected with -EINVAL while the package topology + is not symmetric. + + Writing any true value string (e.g. Y or 1) enables the + restriction, any false value string (e.g. N or 0) disables + it. All other strings return -EINVAL.
mm/mempolicy.c +155 -4
223 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH 4/4] mm/mempolicy: enhance weighted interleave with package-aware locality
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Package-aware weighted interleave silently degrades to flat mode on memoryless CPU nodes because they are not registered in the package topology.
- [Medium] Unstabilized TOCTOU access of policy->nodes in policy_resolve_package_nodes() can cause torn reads and inconsistent node intersection if the policy is concurrently modified.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the function alloc_pages_bulk_weighted_interleave unconditionally uses GFP_KERNEL for a kzalloc call, which can cause a sleep-in-atomic bug if invoked with a non-blocking gfp mask. --
--- Patch [4]: [PATCH 4/4] mm/mempolicy: enhance weighted interleave with package-aware locality --- commit 9bf854e133ba0fbe547595b9d47a304b6f619169
Author: Rakie Kim <[email protected]>
mm/mempolicy: enhance weighted interleave with package-aware locality
This commit introduces a package-aware mode for weighted interleave, aiming to prioritize local nodes within the same package over remote nodes to preserve bandwidth. The mode is opt-in via sysfs and restricts allocations to the NUMA nodes of the task's current package.
Quoted 4 lines
mm/mempolicy.c +0
-0
[ ... ]
Quoted 6 lines
mm/mempolicy.c +2
-0@@ -2138,17 +2146,97 @@ bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone)return zone >= dynamic_policy_zone; } +/** +* policy_resolve_package_nodes - Restrict policy nodes to the current package
[ ... ]
mm/mempolicy.c bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone) · line 2198
Quoted 13 lines
+ */
mm/mempolicy.c +12
-0+static int policy_resolve_package_nodes (struct mempolicy *policy,nodemask_t *mask) +{ +nodemask_t package_mask; +int node, ret; + +if (!policy || !mask) +return -EINVAL ; + +nodes_clear (*mask); + + node =numa_node_id (); + ret =mp_get_package_nodes (node, &package_mask);
[Severity: High]
Will mp_get_package_nodes() fail and return an error for memoryless CPU nodes?
Since memoryless CPU nodes are excluded from being registered into memory packages by memory_package_init() because they lack N_MEMORY, it appears this lookup will fail. Does this cause the package-aware interleave feature to silently degrade and fall back to the unconstrained flat mode when a task executes on a CPU node with no local memory (such as a compute die accessing separate CXL memory)?
mm/mempolicy.c bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone) · line 2202
Quoted 4 lines
mm/mempolicy.c +4
-0+if (ret) +return ret; + +nodes_and (*mask, package_mask, policy->nodes);
[Severity: Medium]
Is it safe to directly read policy->nodes multiple times here without first stabilizing it into a local copy?
If policy->nodes is concurrently modified (for example, via sys_mbind() on a shared VMA policy), a modification occurring between this first nodes_and() check and the fallback first_node() or nodes_and() calls below might cause the logic to observe mixed states.
Could this result in an inconsistent node intersection or an incorrect fallback node being selected?
Quoted 18 lines
mm/mempolicy.c +18
-0+if (!nodes_empty (*mask)) +return 0 ; + +/* +* The user's nodemask excludes every node of the current package; +* fall back to the package spanned by the user's own first node. +*/ + node =first_node (policy->nodes); + ret =mp_get_package_nodes (node, &package_mask); +if (ret) +return ret; + +nodes_and (*mask, package_mask, policy->nodes); +if (nodes_empty (*mask)) +return -ENOENT ; + +return 0 ; +}
[ ... ]
mm/mempolicy.c static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp, · line 2813
Quoted 9 lines
mm/mempolicy.c +1
-1@@ -2695,7 +2807,7 @@ static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp,/* read the nodes onto the stack, retry if done during rebind */ do { cpuset_mems_cookie =read_mems_allowed_begin (); - nnodes =read_once_policy_nodemask (pol, &nodes); + nnodes =read_once_policy_package_nodemask (pol, &nodes); }while (read_mems_allowed_retry (cpuset_mems_cookie));/* if the nodemask has become invalid, we cannot do anything */
[Severity: High]
This isn't a bug introduced by this patch, but does this function safely handle atomic allocations?
Further down in alloc_pages_bulk_weighted_interleave(), the weights array is allocated unconditionally with GFP_KERNEL:
weights = kzalloc(nr_node_ids, GFP_KERNEL);
if (!weights)
return total_allocated;If alloc_pages_bulk() is called from an atomic context with a non-blocking mask like GFP_ATOMIC or GFP_NOWAIT, will ignoring the passed gfp argument and using GFP_KERNEL here cause a 'scheduling while atomic' panic or deadlock?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Andrew Morton
maintainerQuoted 7 lines · On Thu, 6 Aug 2026 17:09:31 +0900 Rakie Kim <[email protected]> wrote:
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
"package" is not a familiar term in MM. It would be helpful if the [0/N] were to carefully and fully define/describe the new term before using it 40 times!
Quoted 12 lines
Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)
Quoted 5 lines
2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)
Well that sounds nice.
Quoted 9 lines
.../ABI/testing/sysfs-devices-system-package | 35 + ...fs-kernel-mm-mempolicy-weighted-interleave | 17 + drivers/cxl/core/region.c | 54 + drivers/cxl/cxl.h | 1 + drivers/dax/kmem.c | 3 + include/linux/memory-tiers.h | 113 ++ include/linux/numa.h | 11 + mm/memory-tiers.c | 1009 +++++++++++++++++ mm/mempolicy.c | 200 +++-
Are some user-facing Documentation/ updates appropriate?
The Documentation/ABI things are rather dry and information-free. How about some documentation for the operator who is wondering "should I use this and if so why and how"?
The runtime sysfs on/off tunable is interesting. I hear from google operations people that every new feature should have such an "off" switch so that if development send them a new thing and they think it's problematic, they can disable it in order to quickly get back to the old regime. Perhaps that was your motivation, perhaps not. Can you please describe?
I see you've been emailed the Sashiko report, which appears substantial.
https://sashiko.dev/#/patchset/[email protected]
Rakie Kim
reviewerQuoted 2 lines · On Thu, 6 Aug 2026 14:38:39 -0700 Andrew Morton <[email protected]>…
On Thu, 6 Aug 2026 17:09:31 +0900 Rakie Kim <[email protected]> wrote:
Hello Andrew,
Thank you for taking the time to review this series.
Quoted 8 lines
Quoted 7 lines
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
Quoted 4 lines
"package" is not a familiar term in MM. It would be helpful if the [0/N] were to carefully and fully define/describe the new term before using it 40 times!
You are right. I think my explanation was not sufficient. When I prepared this series, I went back and forth between "socket" and other candidate terms, and settled on "package" because modern processors can contain multiple NUMA nodes and dies within a single physical socket, so "socket" felt misleading. I did not explain this reasoning in the cover letter. In the next version, I will define the term at the top of the cover letter before it is used.
Quoted 12 lines
Quoted 12 lines
Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)
Quoted 8 lines
Quoted 5 lines
2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)Well that sounds nice.
Thank you.
Quoted 10 lines
Quoted 9 lines
.../ABI/testing/sysfs-devices-system-package | 35 + ...fs-kernel-mm-mempolicy-weighted-interleave | 17 + drivers/cxl/core/region.c | 54 + drivers/cxl/cxl.h | 1 + drivers/dax/kmem.c | 3 + include/linux/memory-tiers.h | 113 ++ include/linux/numa.h | 11 + mm/memory-tiers.c | 1009 +++++++++++++++++ mm/mempolicy.c | 200 +++-
Quoted 6 lines
Are some user-facing
Documentation/updates appropriate?The
Documentation/ABIthings are rather dry and information-free. How about some documentation for the operator who is wondering "should I use this and if so why and how"?
I agree with your point. The current ABI entries only describe the sysfs files themselves. In the next version, I will strengthen the documentation content so that it answers exactly those questions for an operator: whether this feature fits their system, why it helps, and how to enable and verify it.
Quoted 8 lines
The runtime sysfs on/off tunable is interesting. I hear from google operations people that every new feature should have such an "off" switch so that if development send them a new thing and they think it's problematic, they can disable it in order to quickly get back to the old regime. Perhaps that was your motivation, perhaps not. Can you please describe?
You are right that this was one of the purposes. The switch was provided with two goals in mind. First, as you describe, it is an "off" switch for the new feature: if it behaves unexpectedly in production, the operator can disable it at runtime and immediately return to the old behavior, without a reboot. Second, it is for users who want to keep using the existing weighted interleave as it
is: the feature is off by default, and nothing changes for them unless they explicitly turn it on. I will describe this motivation in the documentation as well.
Quoted 4 lines
I see you've been emailed the Sashiko report, which appears substantial.
https://sashiko.dev/#/patchset/[email protected]
Yes, I have received the report, and it seems to provide a lot of good information. I am reviewing each finding against the code, and I plan to reflect it in the next version as much as possible.
Thanks again for your time and review.
Rakie Kim
Joshua Hahn
reviewerQuoted 8 lines · On Thu, 6 Aug 2026 17:09:31 +0900 Rakie Kim <[email protected]> wrote:
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
Quoted 7 lines
Changes from RFC:
https://lore.kernel.org/all/[email protected]/
- Added an opt-in sysfs toggle (off by default) and a read-only sysfs view of the package topology
- Added topology validation with a clean fallback to plain weighted interleave on unsupported topologies
- Hardened the allocation, device-teardown, and node-hotplug paths
Hello Rakie,
I hope you are doing well! Sorry for the late repsonse.
I have a few thoughts, some of which are carry-overs from the RFC discussion we had before! I think there are still some open questions, and I wanted to get your opinion on some of them.
My first question is whether we want cross-socket allocations at all. The examples you gave seem to line up with node-restricted interleave, as opposed to cross-socket interleave. I think the wording that you use to describe the feature in 4/4 (which I will copy below)
Quoted 4 lines
The resolved mask is by construction a subset of the policy nodemask, which mempolicy already restricts to the task's cpuset; package mode can only narrow that set, never widen it, so cpusets and the task nodemask remain authoritative.
is 100% the right way to treat these package-aware (socket-aware) interleaving allocations, but the example below
[...snip...]
Quoted 4 lines
Applied the same way to every source, these weights give the map:
node0 node1 node2 node3
global: 2 2 1 1
[...snip...]
Quoted 3 lines
node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1
Is essentially the existing weighted interleave mechanism with a nodemask/cpuset applied. With that said, I think a more interesting and illustrative example would be if the user truly would want to allow some allocations to go through cross-socket, but be able to control the ratio at which these slip through.
node0 node1 node2 node3
from CPU 0: 3 1 2 0 from CPU 1: 0 3 1 2
Maybe even more illustrative of the true capabilities of this series would be if you have an asymmetric system where you bind some host-level monitoring / logging workloads to one node (say, node0) and want that to be able to cross through to the other socket, but not the other way around:
node0 node1 node2 node3
from CPU 0: 3 1 2 0 from CPU 1: 0 2 0 1
Anyways, these are just super hypothetical scenarios and I don't even know if the configuration that I'm listing would really be beneficial for the system. I think that coming up with some illustrative usecases which are now made possible by this series could help motivate why we would want to interleave across sockets.
Quoted 18 lines
A task on CPU 0 now places pages on node0 (weight 2) and node2 (weight 1) at 2:1, which matches their effective bandwidth of 300:150; a task on CPU 1 places on node1 and node3 the same way. Placement follows the bandwidth each task actually sees, NUMA locality is preserved, and interleave traffic stays off the interconnect.
To make this possible the kernel needs a notion of which nodes share a package. The NUMA distance model offers only relative latencies and no structural grouping, which is especially limiting for CXL memory nodes that come online without an explicit package association.
The series adds a package-aware topology layer that groups CPU and memory-only nodes into a "memory package", built from the physical package ids firmware reports and, for a memory-only node, an initiator CPU node or SLIT distances. A package can contain more than one CPU node or more than one memory-only node, so the layer maps a package to a set of nodes rather than to a single node or a single CXL device.
Quoted 7 lines
The feature is off by default and opt-in through a sysfs toggle. The package topology itself is exposed read-only under
/sys/devices/system/package/; there is deliberately no writable override, since a machine whose firmware describes its topology incorrectly should be fixed in firmware. On a topology that does not have the symmetric shape the placement relies on, enabling is refused and any active mode degrades cleanly to the original flat behavior.
I was also hoping to see what this interface looks like and maybe discuss how we should relay the information to the users, since this seems to be a new addition from the RFC.
Quoted 4 lines
Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)
I think a description of this system's topology would help me understand the results below a bit better : -)
Quoted 7 lines
1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)
Quoted 5 lines
2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)
Really awesome results!
Quoted 8 lines
A small CXL driver change registers a CXL memory node into its package as the node comes online, using the initiator the driver resolves for the region; this is where the package layer gets the CPU-side association that plain NUMA distance does not carry.
The
memory_packagelayer offers a broader interface for grouping and querying package topology - usable by memory tiering as well - and package-aware weighted interleave uses the subset it needs.
I was hoping you could expand on this a bit more. Aside from the alloction-time placement strategy, did you have other ideas in mind for who could ingest the package information to make tiering decisions?
I definitely think this series makes a lot of sense and I am hoping to hear more about it. Thank you, I hope you have a great day!
Joshua
Rakie Kim
reviewerQuoted 18 lines · On Tue, 11 Aug 2026 08:29:51 -0700 Joshua Hahn <[email protected]> wrote:
Quoted 8 lines · On Thu, 6 Aug 2026 17:09:31 +0900 Rakie Kim <[email protected]> wrote:
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
Quoted 7 lines
Changes from RFC:
https://lore.kernel.org/all/[email protected]/
- Added an opt-in sysfs toggle (off by default) and a read-only sysfs view of the package topology
- Added topology validation with a clean fallback to plain weighted interleave on unsupported topologies
- Hardened the allocation, device-teardown, and node-hotplug paths
Quoted 8 lines
Hello Rakie,
I hope you are doing well! Sorry for the late repsonse.
I have a few thoughts, some of which are carry-overs from the RFC discussion we had before! I think there are still some open questions, and I wanted to get your opinion on some of them.
Hello Joshua,
I am doing well, thank you, and I hope you are too. Thank you for taking the time to review this series and for following up on the questions from the RFC discussion.
Quoted 20 lines
My first question is whether we want cross-socket allocations at all. The examples you gave seem to line up with node-restricted interleave, as opposed to cross-socket interleave. I think the wording that you use to describe the feature in 4/4 (which I will copy below)
Quoted 4 lines
The resolved mask is by construction a subset of the policy nodemask, which mempolicy already restricts to the task's cpuset; package mode can only narrow that set, never widen it, so cpusets and the task nodemask remain authoritative.
is 100% the right way to treat these package-aware (socket-aware) interleaving allocations, but the example below
[...snip...]
Quoted 4 lines
Applied the same way to every source, these weights give the map:
node0 node1 node2 node3
global: 2 2 1 1
Quoted 8 lines
[...snip...]
Quoted 3 lines
node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1Is essentially the existing weighted interleave mechanism with a nodemask/cpuset applied.
The example I gave was not explained well enough, and I can see how it reads as a manually applied nodemask.
A nodemask or a cpuset names a fixed set of nodes, while package mode expresses a rule: use the nodes of the package the allocation is requested from. The mask is resolved per allocation from the requesting CPU, so a single policy gives {0,2} to a thread on package 0 and {1,3} to a thread on package 1 at the same time. One nodemask cannot do that, since it is the same set for everyone who uses the policy.
There is also the question of how a user would build such a nodemask. The package a CXL node belongs to is not visible today: on the systems I tested, the firmware reports node1 as the initiator for both CXL nodes. The topology layer in this series is what makes that association available, and the read-only view under /sys/devices/system/package/ lets the user check it.
Quoted 16 lines
With that said, I think a more interesting and
illustrative example would be if the user truly would want to allow some allocations to go through cross-socket, but be able to control the ratio at which these slip through.node0 node1 node2 node3
from CPU 0: 3 1 2 0 from CPU 1: 0 3 1 2Maybe even more illustrative of the true capabilities of this series would be if you have an asymmetric system where you bind some host-level monitoring / logging workloads to one node (say, node0) and want that to be able to cross through to the other socket, but not the other way around:
node0 node1 node2 node3
Quoted 9 lines
from CPU 0: 3 1 2 0 from CPU 1: 0 2 0 1Anyways, these are just super hypothetical scenarios and I don't even know if the configuration that I'm listing would really be beneficial for the system. I think that coming up with some illustrative usecases which are now made possible by this series could help motivate why we would want to interleave across sockets.
These maps are an interesting idea, and I would like to look at them with you.
This series only narrows the candidate nodes; the weights themselves stay global, so every source that reaches a node uses the same weight for it. Both of your maps give a node a different weight depending on which package the allocation comes from, so the weight table would have to become per source rather than a single global one.
Encoding the weights that way came up in an earlier stage of this work, and it was mentioned again briefly in the RFC thread. As I recall, the difficulty then was less the placement logic than how a user would drive it: weights would have to be configured for every source, so both the interface and the structure behind it grow considerably.
That does not make your suggestion less interesting to me. I think it could work well once there are clear scenarios for it, and the grouping added here is what such a table would be built on, since a per source weight only has meaning when the kernel knows which package each node belongs to. What I am unsure about is folding it into this series, whose aim is the narrower one of raising effective bandwidth by keeping interleave traffic within a package. Allowing a controlled amount of cross-package traffic points the other way, so I think it is a topic we could discuss separately, with the use cases worked out first.
I agree that such use cases would make the direction much stronger, and I will think about whether there are cases where allowing a controlled amount of cross-package traffic would help.
Quoted 26 lines
Quoted 18 lines
A task on CPU 0 now places pages on node0 (weight 2) and node2 (weight 1) at 2:1, which matches their effective bandwidth of 300:150; a task on CPU 1 places on node1 and node3 the same way. Placement follows the bandwidth each task actually sees, NUMA locality is preserved, and interleave traffic stays off the interconnect.
To make this possible the kernel needs a notion of which nodes share a package. The NUMA distance model offers only relative latencies and no structural grouping, which is especially limiting for CXL memory nodes that come online without an explicit package association.
The series adds a package-aware topology layer that groups CPU and memory-only nodes into a "memory package", built from the physical package ids firmware reports and, for a memory-only node, an initiator CPU node or SLIT distances. A package can contain more than one CPU node or more than one memory-only node, so the layer maps a package to a set of nodes rather than to a single node or a single CXL device.
Quoted 7 lines
The feature is off by default and opt-in through a sysfs toggle. The package topology itself is exposed read-only under
/sys/devices/system/package/; there is deliberately no writable override, since a machine whose firmware describes its topology incorrectly should be fixed in firmware. On a topology that does not have the symmetric shape the placement relies on, enabling is refused and any active mode degrades cleanly to the original flat behavior.
Quoted 4 lines
I was also hoping to see what this interface looks like and maybe discuss how we should relay the information to the users, since this seems to be a new addition from the RFC.
Sure. The toggle lives with the existing weighted interleave knobs. package_mode defaults to false, so nothing changes until the operator explicitly enables it:
/sys/kernel/mm/mempolicy/weighted_interleave
|-- auto |-- node0 |-- node1 |-- node2 |-- node3
`-- package_mode -> true/false
The package topology view is read-only and lives under /sys/devices/system/package/. This is how it looks on the system I am currently using:
/sys/devices/system/package
|-- package0
| |-- package_cpu_nodes -> 0
| |-- package_mem_only_nodes -> 2
| |-- package_nodes -> 0,2
| `-- physical_package_id -> 0
`-- package1
|-- package_cpu_nodes -> 1
|-- package_mem_only_nodes -> 3
|-- package_nodes -> 1,3
`-- physical_package_id -> 1package_nodes shows every node grouped into that package, and the cpu/mem_only files split them by type, so an operator can check how the kernel grouped the topology before turning package_mode on. I will update the documentation in the next version to describe this interface and how to use it.
Quoted 8 lines
Quoted 4 lines
Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)I think a description of this system's topology would help me understand the results below a bit better : -)
That is a fair point. The system used for the measurements is configured as follows:
- Processor: Dual-Socket Intel Xeon 6980P
(Granite Rapids)
- Local memory (per socket): 12 channels, DDR5-6400
- CXL memory (per socket): 8 channels, DDR5-6400
It boots as two CPU+DRAM nodes and two CXL memory-only nodes, which is the topology shown in the sysfs output above. I will add this description to the measured results in the next version.
Quoted 7 lines
Quoted 7 lines
1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)
Quoted 8 lines
Quoted 5 lines
2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)Really awesome results!
Thank you.
Quoted 5 lines
Quoted 5 lines
A small CXL driver change registers a CXL memory node into its package as the node comes online, using the initiator the driver resolves for the region; this is where the package layer gets the CPU-side association that plain NUMA distance does not carry.
Quoted 8 lines
Quoted 3 lines
The
memory_packagelayer offers a broader interface for grouping and querying package topology - usable by memory tiering as well - and package-aware weighted interleave uses the subset it needs.I was hoping you could expand on this a bit more. Aside from the alloction-time placement strategy, did you have other ideas in mind for who could ingest the package information to make tiering decisions?
The case I had in mind is demotion and promotion target selection. With the package information, tiering could keep those decisions within a package: choosing the memory-only nodes of the task's package as demotion targets, and symmetrically preferring the package's CPU nodes when promoting, so that both hot and cold pages stay close to the CPUs that use them.
To support this, the layer already exposes per-node "preferred" node
queries: for a CPU node it reports the nearest memory-only nodes in the same package, and for a memory-only node the nearest CPU nodes. Nothing consumes them yet; I kept them out of the placement path so that tiering can adopt them separately when there is a real user.
Quoted 4 lines
I definitely think this series makes a lot of sense and I am hoping to hear more about it. Thank you, I hope you have a great day!
Joshua
Thank you again for the careful review and for the questions; they were a great help in seeing what the cover letter needs to explain better. I hope you have a great day too.
Rakie Kim
Joshua Hahn
reviewerQuoted 38 lines
Hello Joshua,
I am doing well, thank you, and I hope you are too. Thank you for taking the time to review this series and for following up on the questions from the RFC discussion.
Quoted 20 lines
My first question is whether we want cross-socket allocations at all. The examples you gave seem to line up with node-restricted interleave, as opposed to cross-socket interleave. I think the wording that you use to describe the feature in 4/4 (which I will copy below)
Quoted 4 lines
The resolved mask is by construction a subset of the policy nodemask, which mempolicy already restricts to the task's cpuset; package mode can only narrow that set, never widen it, so cpusets and the task nodemask remain authoritative.
is 100% the right way to treat these package-aware (socket-aware) interleaving allocations, but the example below
[...snip...]
Quoted 4 lines
Applied the same way to every source, these weights give the map:
node0 node1 node2 node3
global: 2 2 1 1Quoted 8 lines
[...snip...]
Quoted 3 lines
node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1Is essentially the existing weighted interleave mechanism with a nodemask/cpuset applied.
The example I gave was not explained well enough, and I can see how it reads as a manually applied nodemask.
Quoted 7 lines
A nodemask or a cpuset names a fixed set of nodes, while package mode expresses a rule: use the nodes of the package the allocation is requested from. The mask is resolved per allocation from the requesting CPU, so a single policy gives {0,2} to a thread on package 0 and {1,3} to a thread on package 1 at the same time. One nodemask cannot do that, since it is the same set for everyone who uses the policy.
Ah! I'm sorry. It seems I totally misunderstood the intent of the series. I think that my brain short-circuted to the discussion at LSFMMBPF from 2025, where I think we discussed having a real 2-D grid with weights per-node, per-CPU. I think my confusion is responsible for the examples below, which as I understand it now, are not the intent of the series.
Quoted 6 lines
There is also the question of how a user would build such a nodemask. The package a CXL node belongs to is not visible today: on the systems I tested, the firmware reports node1 as the initiator for both CXL nodes. The topology layer in this series is what makes that association available, and the read-only view under
/sys/devices/system/package/lets the user check it.
That makes sense. Now I really see the goal of the series and it makes a lot more sense. Thank you for the clarification.
Quoted 35 lines
Quoted 16 lines
With that said, I think a more interesting and
illustrative example would be if the user truly would want to allow some allocations to go through cross-socket, but be able to control the ratio at which these slip through.node0 node1 node2 node3
from CPU 0: 3 1 2 0 from CPU 1: 0 3 1 2Maybe even more illustrative of the true capabilities of this series would be if you have an asymmetric system where you bind some host-level monitoring / logging workloads to one node (say, node0) and want that to be able to cross through to the other socket, but not the other way around:
node0 node1 node2 node3
Quoted 9 lines
from CPU 0: 3 1 2 0 from CPU 1: 0 2 0 1Anyways, these are just super hypothetical scenarios and I don't even know if the configuration that I'm listing would really be beneficial for the system. I think that coming up with some illustrative usecases which are now made possible by this series could help motivate why we would want to interleave across sockets.
These maps are an interesting idea, and I would like to look at them with you.
This series only narrows the candidate nodes; the weights themselves stay global, so every source that reaches a node uses the same weight for it. Both of your maps give a node a different weight depending on which package the allocation comes from, so the weight table would have to become per source rather than a single global one.
Quoted 6 lines
Encoding the weights that way came up in an earlier stage of this work, and it was mentioned again briefly in the RFC thread. As I recall, the difficulty then was less the placement logic than how a user would drive it: weights would have to be configured for every source, so both the interface and the structure behind it grow considerably.
Yeah, I can imagine it is quite a lot of tuning that users have to do. So I'm 100% on board for the goal of this series to make the existing weighted interleave mechanism respect the initiator's POV. Sorry for making you explain all of this, this confusion is just due to my misunderstanding.
Quoted 10 lines
That does not make your suggestion less interesting to me. I think it could work well once there are clear scenarios for it, and the grouping added here is what such a table would be built on, since a per source weight only has meaning when the kernel knows which package each node belongs to. What I am unsure about is folding it into this series, whose aim is the narrower one of raising effective bandwidth by keeping interleave traffic within a package. Allowing a controlled amount of cross-package traffic points the other way, so I think it is a topic we could discuss separately, with the use cases worked out first.
Thanks! Actually I think we can wait on this until we have real usecases where we prefer to make cross-socket allocations.
Quoted 33 lines
Quoted 4 lines
I was also hoping to see what this interface looks like and maybe discuss how we should relay the information to the users, since this seems to be a new addition from the RFC.
Sure. The toggle lives with the existing weighted interleave knobs.
package_modedefaults to false, so nothing changes until the operator explicitly enables it:
/sys/kernel/mm/mempolicy/weighted_interleave|-- auto |-- node0 |-- node1 |-- node2 |-- node3`--
package_mode-> true/falseThe package topology view is read-only and lives under
/sys/devices/system/package/. This is how it looks on the system I am currently using:
/sys/devices/system/package|-- package0 | |-- package_cpu_nodes -> 0 | |-- package_mem_only_nodes -> 2 | |-- package_nodes -> 0,2 | `-- physical_package_id -> 0 `-- package1 |-- package_cpu_nodes -> 1 |-- package_mem_only_nodes -> 3 |-- package_nodes -> 1,3 `-- physical_package_id -> 1
Quoted 5 lines
package_nodesshows every node grouped into that package, and the cpu/mem_only files split them by type, so an operator can check how the kernel grouped the topology before turningpackage_modeon. I will update the documentation in the next version to describe this interface and how to use it.
Great, I think this would be a great addition to add to the cover letter and also add as documentation, since it is user-facing.
Quoted 12 lines
Quoted 8 lines
Quoted 4 lines
Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)I think a description of this system's topology would help me understand the results below a bit better : -)
That is a fair point. The system used for the measurements is configured as follows:
Quoted 8 lines
- Processor: Dual-Socket Intel Xeon 6980P
(Granite Rapids)
- Local memory (per socket): 12 channels, DDR5-6400
- CXL memory (per socket): 8 channels, DDR5-6400It boots as two CPU+DRAM nodes and two CXL memory-only nodes, which is the topology shown in the sysfs output above. I will add this description to the measured results in the next version.
Thanks. Notably I wanted to see if the DDR generation was the same across DRAM and CXL.
Quoted 6 lines
The case I had in mind is demotion and promotion target selection. With the package information, tiering could keep those decisions within a package: choosing the memory-only nodes of the task's package as demotion targets, and symmetrically preferring the package's CPU nodes when promoting, so that both hot and cold pages stay close to the CPUs that use them.
Yeah, I like this idea a lot.
For demotion, we would just chnage the fallback zonelist based on the sockets.
I think we actually get promotions for free, since if this series is doing a good job of allocating memory close to the consuming CPU, and the demotions prevent the memory from moving cross-socket, initiators should only promote (NUMAB2 promotion) memory that is socket-local.
Quoted 6 lines
To support this, the layer already exposes per-node "preferred" node
queries: for a CPU node it reports the nearest memory-only nodes in the same package, and for a memory-only node the nearest CPU nodes. Nothing consumes them yet; I kept them out of the placement path so that tiering can adopt them separately when there is a real user.
Quoted 8 lines
Quoted 4 lines
I definitely think this series makes a lot of sense and I am hoping to hear more about it. Thank you, I hope you have a great day!
Joshua
Thank you again for the careful review and for the questions; they were a great help in seeing what the cover letter needs to explain better. I hope you have a great day too.
Thank you Rakie. I don't think the cover letter was misleading, it was just my fault for short-circuiting and thinking the series was about adding per-socket per-node weights, as opposed to the restriction that you're adding to the existing weights.
If I may add one more comment, I think 2/4 is a bit hard to review. A 1k line patch is not so easy to see the full picture, I think it would make it less intimidating to review if it could be split up into smaller patches. Just my 2c : -)
Thanks again. I hope you have a great day!
Joshua
Rakie Kim
reviewerOn Wed, 12 Aug 2026 07:49:55 -0700 Joshua Hahn <[email protected]> wrote:
Hello Joshua,
Thank you for coming back to this so quickly.
Quoted 46 lines
Quoted 38 lines
Hello Joshua,
I am doing well, thank you, and I hope you are too. Thank you for taking the time to review this series and for following up on the questions from the RFC discussion.
Quoted 20 lines
My first question is whether we want cross-socket allocations at all. The examples you gave seem to line up with node-restricted interleave, as opposed to cross-socket interleave. I think the wording that you use to describe the feature in 4/4 (which I will copy below)
Quoted 4 lines
The resolved mask is by construction a subset of the policy nodemask, which mempolicy already restricts to the task's cpuset; package mode can only narrow that set, never widen it, so cpusets and the task nodemask remain authoritative.
is 100% the right way to treat these package-aware (socket-aware) interleaving allocations, but the example below
[...snip...]
Quoted 4 lines
Applied the same way to every source, these weights give the map:
node0 node1 node2 node3
global: 2 2 1 1Quoted 8 lines
[...snip...]
Quoted 3 lines
node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1Is essentially the existing weighted interleave mechanism with a nodemask/cpuset applied.
The example I gave was not explained well enough, and I can see how it reads as a manually applied nodemask.
Quoted 7 lines
A nodemask or a cpuset names a fixed set of nodes, while package mode expresses a rule: use the nodes of the package the allocation is requested from. The mask is resolved per allocation from the requesting CPU, so a single policy gives {0,2} to a thread on package 0 and {1,3} to a thread on package 1 at the same time. One nodemask cannot do that, since it is the same set for everyone who uses the policy.
Quoted 7 lines
Ah! I'm sorry. It seems I totally misunderstood the intent of the series. I think that my brain short-circuted to the discussion at LSFMMBPF from 2025, where I think we discussed having a real 2-D grid with weights per-node, per-CPU. I think my confusion is responsible for the examples below, which as I understand it now, are not the intent of the series.
My explanation was not enough and that is what caused the confusion. The 2-D grid is close enough to this work that the two are easy to place together, and thanks to your questions I could fill in a good deal of what the cover letter was missing.
Quoted 10 lines
Quoted 6 lines
There is also the question of how a user would build such a nodemask. The package a CXL node belongs to is not visible today: on the systems I tested, the firmware reports node1 as the initiator for both CXL nodes. The topology layer in this series is what makes that association available, and the read-only view under
/sys/devices/system/package/lets the user check it.That makes sense. Now I really see the goal of the series and it makes a lot more sense. Thank you for the clarification.
Thank you.
Quoted 42 lines
Quoted 35 lines
Quoted 16 lines
With that said, I think a more interesting and
illustrative example would be if the user truly would want to allow some allocations to go through cross-socket, but be able to control the ratio at which these slip through.node0 node1 node2 node3
from CPU 0: 3 1 2 0 from CPU 1: 0 3 1 2Maybe even more illustrative of the true capabilities of this series would be if you have an asymmetric system where you bind some host-level monitoring / logging workloads to one node (say, node0) and want that to be able to cross through to the other socket, but not the other way around:
node0 node1 node2 node3
Quoted 9 lines
from CPU 0: 3 1 2 0 from CPU 1: 0 2 0 1Anyways, these are just super hypothetical scenarios and I don't even know if the configuration that I'm listing would really be beneficial for the system. I think that coming up with some illustrative usecases which are now made possible by this series could help motivate why we would want to interleave across sockets.
These maps are an interesting idea, and I would like to look at them with you.
This series only narrows the candidate nodes; the weights themselves stay global, so every source that reaches a node uses the same weight for it. Both of your maps give a node a different weight depending on which package the allocation comes from, so the weight table would have to become per source rather than a single global one.
Quoted 6 lines
Encoding the weights that way came up in an earlier stage of this work, and it was mentioned again briefly in the RFC thread. As I recall, the difficulty then was less the placement logic than how a user would drive it: weights would have to be configured for every source, so both the interface and the structure behind it grow considerably.
Quoted 6 lines
Yeah, I can imagine it is quite a lot of tuning that users have to do. So I'm 100% on board for the goal of this series to make the existing weighted interleave mechanism respect the initiator's POV. Sorry for making you explain all of this, this confusion is just due to my misunderstanding.
Thank you. "Respect the initiator's point of view" describes the goal better than what I wrote, so I would like to use that framing in the next cover letter.
Quoted 11 lines
Quoted 10 lines
That does not make your suggestion less interesting to me. I think it could work well once there are clear scenarios for it, and the grouping added here is what such a table would be built on, since a per source weight only has meaning when the kernel knows which package each node belongs to. What I am unsure about is folding it into this series, whose aim is the narrower one of raising effective bandwidth by keeping interleave traffic within a package. Allowing a controlled amount of cross-package traffic points the other way, so I think it is a topic we could discuss separately, with the use cases worked out first.
Quoted 3 lines
Thanks! Actually I think we can wait on this until we have real usecases where we prefer to make cross-socket allocations.
Agreed. I will also keep thinking about what such use cases would look like.
Quoted 33 lines
Quoted 33 lines
Quoted 4 lines
I was also hoping to see what this interface looks like and maybe discuss how we should relay the information to the users, since this seems to be a new addition from the RFC.
Sure. The toggle lives with the existing weighted interleave knobs.
package_modedefaults to false, so nothing changes until the operator explicitly enables it:
/sys/kernel/mm/mempolicy/weighted_interleave|-- auto |-- node0 |-- node1 |-- node2 |-- node3`--
package_mode-> true/falseThe package topology view is read-only and lives under
/sys/devices/system/package/. This is how it looks on the system I am currently using:
/sys/devices/system/package|-- package0 | |-- package_cpu_nodes -> 0 | |-- package_mem_only_nodes -> 2 | |-- package_nodes -> 0,2 | `-- physical_package_id -> 0 `-- package1 |-- package_cpu_nodes -> 1 |-- package_mem_only_nodes -> 3 |-- package_nodes -> 1,3 `-- physical_package_id -> 1
Quoted 9 lines
Quoted 5 lines
package_nodesshows every node grouped into that package, and the cpu/mem_only files split them by type, so an operator can check how the kernel grouped the topology before turningpackage_modeon. I will update the documentation in the next version to describe this interface and how to use it.Great, I think this would be a great addition to add to the cover letter and also add as documentation, since it is user-facing.
I will put it in both. Andrew also asked for documentation aimed at the operator, so the next version will describe this interface and how to use it there as well.
Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines
Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)I think a description of this system's topology would help me understand the results below a bit better : -)
That is a fair point. The system used for the measurements is configured as follows:
- Processor: Dual-Socket Intel Xeon 6980P
(Granite Rapids)
- Local memory (per socket): 12 channels, DDR5-6400
- CXL memory (per socket): 8 channels, DDR5-6400
Quoted 7 lines
Quoted 3 lines
It boots as two CPU+DRAM nodes and two CXL memory-only nodes, which is the topology shown in the sysfs output above. I will add this description to the measured results in the next version.
Thanks. Notably I wanted to see if the DDR generation was the same across DRAM and CXL.
Both sides are DDR5-6400, so the difference in the results comes from the path rather than from the memory itself. I will make that clear when I describe the system in the next version.
Quoted 9 lines
Quoted 6 lines
The case I had in mind is demotion and promotion target selection. With the package information, tiering could keep those decisions within a package: choosing the memory-only nodes of the task's package as demotion targets, and symmetrically preferring the package's CPU nodes when promoting, so that both hot and cold pages stay close to the CPUs that use them.
Yeah, I like this idea a lot.
Quoted 8 lines
For demotion, we would just chnage the fallback zonelist based on the sockets.
I think we actually get promotions for free, since if this series is doing a good job of allocating memory close to the consuming CPU, and the demotions prevent the memory from moving cross-socket, initiators should only promote (NUMAB2 promotion) memory that is socket-local.
Thank you for the suggestion. Changing the demotion order by package sounds like the natural first step, and I will look into it once the placement side has settled.
Quoted 11 lines
Quoted 11 lines
To support this, the layer already exposes per-node "preferred" node
queries: for a CPU node it reports the nearest memory-only nodes in the same package, and for a memory-only node the nearest CPU nodes. Nothing consumes them yet; I kept them out of the placement path so that tiering can adopt them separately when there is a real user.Quoted 4 lines
I definitely think this series makes a lot of sense and I am hoping to hear more about it. Thank you, I hope you have a great day!
Joshua
Quoted 9 lines
Quoted 3 lines
Thank you again for the careful review and for the questions; they were a great help in seeing what the cover letter needs to explain better. I hope you have a great day too.
Thank you Rakie. I don't think the cover letter was misleading, it was just my fault for short-circuiting and thinking the series was about adding per-socket per-node weights, as opposed to the restriction that you're adding to the existing weights.
Thank you for saying so. Either way, your questions gave me a chance to look again at what the cover letter was not saying clearly.
Quoted 5 lines
If I may add one more comment, I think 2/4 is a bit hard to review. A 1k line patch is not so easy to see the full picture, I think it would make it less intimidating to review if it could be split up into smaller patches. Just my 2c : -)
You are right, it is too much to take in at once. The patch became large and complex because several features ended up in a single commit. I will separate them as much as I can in the next version.
Quoted 2 lines
Thanks again. I hope you have a great day!
Joshua
Thank you again for the review and for the discussion. I hope you have a great day too.
Rakie Kim
Lorenzo Stoakes (ARM)
reviewerQuoted 8 lines · Rakie Kim
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
Quoted 7 lines
Changes from RFC:
https://lore.kernel.org/all/[email protected]/
- Added an opt-in sysfs toggle (off by default) and a read-only sysfs view of the package topology
- Added topology validation with a clean fallback to plain weighted interleave on unsupported topologies
- Hardened the allocation, device-teardown, and node-hotplug paths
Please put change logs under the cover letter :) in mm we put the cover letter in the actual upstream commit so it's better to keep separate for reviewers.
I see the RFC was from march and tied to an LSF session I think?
While I don't want to be too pedantic, I think you should only really un-RFC in a situation where you have a good sense that the relevant maintainers are happy with the _concept_.
Looking at the RFC thread it's not clear that David was OK with this on the mm side, though I see you got some feedback from Jonathan on the CXL driver side.
So I wonder whether next respin this should be re-RFC'd unless you get clear feedback that we want to go in this direction?
Quoted 14 lines
Weighted interleave places pages on nodes in proportion to per-node weights that are set from each node's bandwidth. Within one package the weight given to a node matches the bandwidth a task sees from it. Across packages it no longer does: a memory node's physical bandwidth is fixed, but the bandwidth a task effectively sees depends on which package its CPU is in, because memory reached from another package, over the interconnect between them, is slower than the same memory reached within the package. The weights are set once from device bandwidth and applied the same way wherever the task runs, so a node in another package is given a weight higher than the bandwidth it can deliver to that task. The kernel has no package abstraction and does not record which package a node belongs to, so it cannot tell which node pairs are separated by the interconnect.
Please please - break up huge paragraphs like this :)
It's 2026 so I have to mention that if you've used AI to assist with writing it (which is fine) please do a pass over it manually to curb AI's tendency to be overly verbose + definitely try to break up paragraphs into smaller charts at least :)
Quoted 12 lines
node0 node1
+-------+ +-------+
| CPU 0 |---------| CPU 1 |
+-------+ +-------+
| DRAM0 | | DRAM1 |
+---+---+ +---+---+
| |
+---+---+ +---+---+
| CXL 0 | | CXL 1 |
+-------+ +-------+
node2 node3...though I _love_ ASCII diagrams so this is great ;)
Quoted 8 lines
The numbers below are illustrative single-stream bandwidths (GB/s). Local DRAM sustains 300 and local CXL 150; any path that crosses to another package, over the interconnect, is capped at 100, so a node in another package delivers 100 whether it is DRAM or CXL. Note that local CXL (150) is still faster than any node in another package (100). The effective bandwidth each CPU sees is therefore:
Quoted 8 lines
node0 node1 node2 node3
from CPU 0: 300 100 150 100 from CPU 1: 100 300 100 150Since a single per-node weight cannot encode the interconnect penalty, a reasonable set of global weights is taken from local device bandwidth (local DRAM : local CXL = 300 : 150 = 2 : 1): node0=2 node1=2 node2=1 node3=1.
Also great that you provide the receipts on actual observed real-world numbers that's great.
NUMA isn't my area so I can't comment here on the technical details but thanks for providing this :)
Quoted 117 lines
Applied the same way to every source, these weights give the map:
node0 node1 node2 node3
global: 2 2 1 1A task on CPU 0 gives node1 - remote DRAM, effective 100 - the same weight 2 as its own local node0 at 300. Worse, node1 is weighted above node2, the task's local CXL at effective 150, even though node2 is the faster of the two. The flat weights rank a slower interconnect-bound node above a faster local one, which is exactly backwards.
This series makes weighted interleave package-aware. When it is on, weighted interleave prefers the task's current package: while the package's nodes have room, the task's pages are spread across them by weight, so allocations stay off the interconnect. The rest of the policy nodemask is used when the local package cannot serve the request
- when a node in it is under pressure and the page allocator falls back along the zonelist, or when the policy nodemask happens to exclude every node of the current package, in which case the package spanned by the policy's own nodes is used instead. The nodes considered are always within the policy nodemask, which mempolicy already narrows to the task's cpuset, so cpusets and the task nodemask stay in control.node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1A task on CPU 0 now places pages on node0 (weight 2) and node2 (weight 1) at 2:1, which matches their effective bandwidth of 300:150; a task on CPU 1 places on node1 and node3 the same way. Placement follows the bandwidth each task actually sees, NUMA locality is preserved, and interleave traffic stays off the interconnect.
To make this possible the kernel needs a notion of which nodes share a package. The NUMA distance model offers only relative latencies and no structural grouping, which is especially limiting for CXL memory nodes that come online without an explicit package association.
The series adds a package-aware topology layer that groups CPU and memory-only nodes into a "memory package", built from the physical package ids firmware reports and, for a memory-only node, an initiator CPU node or SLIT distances. A package can contain more than one CPU node or more than one memory-only node, so the layer maps a package to a set of nodes rather than to a single node or a single CXL device.
The feature is off by default and opt-in through a sysfs toggle. The package topology itself is exposed read-only under
/sys/devices/system/package/; there is deliberately no writable override, since a machine whose firmware describes its topology incorrectly should be fixed in firmware. On a topology that does not have the symmetric shape the placement relies on, enabling is refused and any active mode degrades cleanly to the original flat behavior.Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)A small CXL driver change registers a CXL memory node into its package as the node comes online, using the initiator the driver resolves for the region; this is where the package layer gets the CPU-side association that plain NUMA distance does not carry.
The
memory_packagelayer offers a broader interface for grouping and querying package topology - usable by memory tiering as well - and package-aware weighted interleave uses the subset it needs.[PATCH 1/4] mm/numa: introduce
nearest_nodes_nodemask()
Add a NUMA helper that returns every node sharing the minimum distance from a source node.[PATCH 2/4]
mm/memory-tiers: package-aware topology management
Group NUMA nodes into memory packages from firmware topology data, expose the grouping read-only under/sys/devices/system/package/, and validate the symmetric shape that package-aware placement relies on.[PATCH 3/4]
mm/memory-tiers: register CXL nodes to packages
Bind a CXL memory node to a package using an initiator CPU node.[PATCH 4/4] mm/mempolicy: package-aware weighted interleave
Prefer the current package for weighted interleave node selection, behind an opt-inpackage_modesysfs toggle that is off by default.Rakie Kim (4):
mm/numa: introducenearest_nodes_nodemask()mm/memory-tiers: introduce package-aware topology management for NUMA
nodes
mm/memory-tiers: register CXL nodes to memory packages via initiator mm/mempolicy: enhance weighted interleave with package-aware locality.../ABI/testing/sysfs-devices-system-package | 35 + ...fs-kernel-mm-mempolicy-weighted-interleave | 17 + drivers/cxl/core/region.c | 54 + drivers/cxl/cxl.h | 1 + drivers/dax/kmem.c | 3 + include/linux/memory-tiers.h | 113 ++ include/linux/numa.h | 11 + mm/memory-tiers.c | 1009 +++++++++++++++++ mm/mempolicy.c | 200 +++- 9 files changed, 1439 insertions(+), 4 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-system-package
Quoted 4 lines
base-commit:
8cd9520d35a6c38db6567e97dd93b1f11f185dc6--
2.25.1
--
Cheers, Lorenzo
Rakie Kim
reviewerOn Wed, 12 Aug 2026 08:16:23 +0100 "Lorenzo Stoakes (ARM)" <[email protected]> wrote:
Hello Lorenzo,
Thank you for taking the time to review this series and for the advice on how to submit it.
Quoted 17 lines · Rakie Kim
Quoted 8 lines
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
Quoted 7 lines
Changes from RFC:
https://lore.kernel.org/all/[email protected]/
- Added an opt-in sysfs toggle (off by default) and a read-only sysfs view of the package topology
- Added topology validation with a clean fallback to plain weighted interleave on unsupported topologies
- Hardened the allocation, device-teardown, and node-hotplug paths
Quoted 4 lines
Please put change logs under the cover letter :) in mm we put the cover letter in the actual upstream commit so it's better to keep separate for reviewers.
Thank you, I did not know that. I will keep the change log out of the cover letter body from the next version.
Quoted 6 lines
I see the RFC was from march and tied to an LSF session I think?
While I don't want to be too pedantic, I think you should only really un-RFC in a situation where you have a good sense that the relevant maintainers are happy with the _concept_.
Quoted 7 lines
Looking at the RFC thread it's not clear that David was OK with this on the mm side, though I see you got some feedback from Jonathan on the CXL driver side.
So I wonder whether next respin this should be re-RFC'd unless you get clear feedback that we want to go in this direction?
You are right about the LSF session: the RFC was posted with that proposal in mind, but I could not attend for personal reasons, so the discussion I had hoped for there did not happen.
Your point about the concept is fair as well, so I will post the next version as an RFC again.
Quoted 15 lines
Quoted 14 lines
Weighted interleave places pages on nodes in proportion to per-node weights that are set from each node's bandwidth. Within one package the weight given to a node matches the bandwidth a task sees from it. Across packages it no longer does: a memory node's physical bandwidth is fixed, but the bandwidth a task effectively sees depends on which package its CPU is in, because memory reached from another package, over the interconnect between them, is slower than the same memory reached within the package. The weights are set once from device bandwidth and applied the same way wherever the task runs, so a node in another package is given a weight higher than the bandwidth it can deliver to that task. The kernel has no package abstraction and does not record which package a node belongs to, so it cannot tell which node pairs are separated by the interconnect.
Quoted 7 lines
Please please - break up huge paragraphs like this :)
It's 2026 so I have to mention that if you've used AI to assist with writing it (which is fine) please do a pass over it manually to curb AI's tendency to be overly verbose + definitely try to break up paragraphs into smaller charts at least :)
I agree. Reading it again, my sentences are too long and the explanation is more verbose than it needs to be, which makes the cover letter hard to read. This needs to be fixed.
I will rewrite the cover letter for the next version in a form that is easier to read.
Quoted 13 lines
Quoted 12 lines
node0 node1 +-------+ +-------+ | CPU 0 |---------| CPU 1 | +-------+ +-------+ | DRAM0 | | DRAM1 | +---+---+ +---+---+ | | +---+---+ +---+---+ | CXL 0 | | CXL 1 | +-------+ +-------+ node2 node3
Quoted 2 lines
...though I _love_ ASCII diagrams so this is great ;)
Thank you.
Quoted 17 lines
Quoted 8 lines
The numbers below are illustrative single-stream bandwidths (GB/s). Local DRAM sustains 300 and local CXL 150; any path that crosses to another package, over the interconnect, is capped at 100, so a node in another package delivers 100 whether it is DRAM or CXL. Note that local CXL (150) is still faster than any node in another package (100). The effective bandwidth each CPU sees is therefore:
Quoted 8 lines
node0 node1 node2 node3
from CPU 0: 300 100 150 100 from CPU 1: 100 300 100 150Since a single per-node weight cannot encode the interconnect penalty, a reasonable set of global weights is taken from local device bandwidth (local DRAM : local CXL = 300 : 150 = 2 : 1): node0=2 node1=2 node2=1 node3=1.
Quoted 6 lines
Also great that you provide the receipts on actual observed real-world numbers that's great.
NUMA isn't my area so I can't comment here on the technical details but thanks for providing this :)
Thank you. I will keep reporting measured results with the next versions.
Quoted 118 lines
Quoted 118 lines
Applied the same way to every source, these weights give the map:
node0 node1 node2 node3
global: 2 2 1 1A task on CPU 0 gives node1 - remote DRAM, effective 100 - the same weight 2 as its own local node0 at 300. Worse, node1 is weighted above node2, the task's local CXL at effective 150, even though node2 is the faster of the two. The flat weights rank a slower interconnect-bound node above a faster local one, which is exactly backwards.
This series makes weighted interleave package-aware. When it is on, weighted interleave prefers the task's current package: while the package's nodes have room, the task's pages are spread across them by weight, so allocations stay off the interconnect. The rest of the policy nodemask is used when the local package cannot serve the request
- when a node in it is under pressure and the page allocator falls back along the zonelist, or when the policy nodemask happens to exclude every node of the current package, in which case the package spanned by the policy's own nodes is used instead. The nodes considered are always within the policy nodemask, which mempolicy already narrows to the task's cpuset, so cpusets and the task nodemask stay in control.node0 node1 node2 node3
from CPU 0: 2 0 1 0 from CPU 1: 0 2 0 1A task on CPU 0 now places pages on node0 (weight 2) and node2 (weight 1) at 2:1, which matches their effective bandwidth of 300:150; a task on CPU 1 places on node1 and node3 the same way. Placement follows the bandwidth each task actually sees, NUMA locality is preserved, and interleave traffic stays off the interconnect.
To make this possible the kernel needs a notion of which nodes share a package. The NUMA distance model offers only relative latencies and no structural grouping, which is especially limiting for CXL memory nodes that come online without an explicit package association.
The series adds a package-aware topology layer that groups CPU and memory-only nodes into a "memory package", built from the physical package ids firmware reports and, for a memory-only node, an initiator CPU node or SLIT distances. A package can contain more than one CPU node or more than one memory-only node, so the layer maps a package to a set of nodes rather than to a single node or a single CXL device.
The feature is off by default and opt-in through a sysfs toggle. The package topology itself is exposed read-only under
/sys/devices/system/package/; there is deliberately no writable override, since a machine whose firmware describes its topology incorrectly should be fixed in firmware. On a topology that does not have the symmetric shape the placement relies on, enabling is refused and any active mode degrades cleanly to the original flat behavior.Measured results:
System Configuration:
- Processor: Dual-Socket Intel Xeon 6980P (Granite Rapids)1) Throughput (System Bandwidth)
- DRAM Only: 966 GB/s
- Weighted Interleave: 903 GB/s (7% decrease compared to DRAM Only)
- Package-Aware Weighted Interleave: 1329 GB/s (1.33 TB/s) (38% increase compared to DRAM Only,
47% increase compared to Weighted Interleave)2) Loaded Latency (Under High Bandwidth)
- DRAM Only: 544 ns
- Weighted Interleave: 545 ns
- Package-Aware Weighted Interleave: 436 ns
(20% reduction compared to both)A small CXL driver change registers a CXL memory node into its package as the node comes online, using the initiator the driver resolves for the region; this is where the package layer gets the CPU-side association that plain NUMA distance does not carry.
The
memory_packagelayer offers a broader interface for grouping and querying package topology - usable by memory tiering as well - and package-aware weighted interleave uses the subset it needs.[PATCH 1/4] mm/numa: introduce
nearest_nodes_nodemask()
Add a NUMA helper that returns every node sharing the minimum distance from a source node.[PATCH 2/4]
mm/memory-tiers: package-aware topology management
Group NUMA nodes into memory packages from firmware topology data, expose the grouping read-only under/sys/devices/system/package/, and validate the symmetric shape that package-aware placement relies on.[PATCH 3/4]
mm/memory-tiers: register CXL nodes to packages
Bind a CXL memory node to a package using an initiator CPU node.[PATCH 4/4] mm/mempolicy: package-aware weighted interleave
Prefer the current package for weighted interleave node selection, behind an opt-inpackage_modesysfs toggle that is off by default.Rakie Kim (4):
mm/numa: introducenearest_nodes_nodemask()mm/memory-tiers: introduce package-aware topology management for NUMA
nodes
mm/memory-tiers: register CXL nodes to memory packages via initiator mm/mempolicy: enhance weighted interleave with package-aware locality.../ABI/testing/sysfs-devices-system-package | 35 + ...fs-kernel-mm-mempolicy-weighted-interleave | 17 + drivers/cxl/core/region.c | 54 + drivers/cxl/cxl.h | 1 + drivers/dax/kmem.c | 3 + include/linux/memory-tiers.h | 113 ++ include/linux/numa.h | 11 + mm/memory-tiers.c | 1009 +++++++++++++++++ mm/mempolicy.c | 200 +++- 9 files changed, 1439 insertions(+), 4 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-system-package
Quoted 7 lines
Quoted 4 lines
base-commit:
8cd9520d35a6c38db6567e97dd93b1f11f185dc6--
2.25.1--
Cheers, Lorenzo
Thank you again for the excellent advice. What you pointed out matters for how a patch is delivered, so I will keep it in mind for the next version and the ones after it.
Thanks again for your time and review.
Rakie Kim
Gregory Price
maintainerQuoted 8 lines · Rakie Kim
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
The only major question I have before I dig into the actual patches is whether you actually need this on a *per-task* basis, rather than simply a *per-process* basis - because that's all this really buys you.
You can already do what is described here by simply using a combination of cpuset and mempolicy
cpuset.mems = 0,2
mempolicy = weighted interleave --all
If this is actually required on a per-task basis, then I agree this concept is reasonable. I just want to make we're grounded on a real use case before we go adding this complexity.
~Gregory
Rakie Kim
reviewerQuoted 17 lines · On Wed, 12 Aug 2026 22:37:06 -0400 Gregory Price <[email protected]> wrote:
Quoted 8 lines · Rakie Kim
Package-aware weighted interleave places a task's weighted-interleave pages on the NUMA nodes of its local package, so that interleave traffic does not have to cross the interconnect to another package. This keeps each node's weight aligned with the bandwidth the task actually gets from it, so effective bandwidth holds up on a system that has more than one package. (A package is a CPU socket together with the memory attached to it.)
The only major question I have before I dig into the actual patches is whether you actually need this on a *per-task* basis, rather than simply a *per-process* basis - because that's all this really buys you.
You can already do what is described here by simply using a combination of cpuset and mempolicy
Quoted 8 lines
cpuset.mems = 0,2
mempolicy = weighted interleave --allIf this is actually required on a per-task basis, then I agree this concept is reasonable. I just want to make we're grounded on a real use case before we go adding this complexity.
~Gregory
Hello Gregory,
Thank you for reviewing this series. My description was not precise enough, and it seems to have confused several people. Let me go over the example again.
I labelled the rows "from CPU 0" and "from CPU 1", which reads as two separate tasks, each pinned to one place. What the rows were meant to show is which package the allocation is requested from:
node0 node1 node2 node3
from package 0: 2 0 1 0 from package 1: 0 2 0 1
Both rows come from one policy at the same time. Which row applies is decided per allocation, by the package the requesting CPU is in.
The cpuset.mems = 0,2 you describe is the node set of package 0, so the tasks in that cgroup use node0 and node2 wherever they run.
The feature I am proposing does not fix a package that way. It uses the nodes of the package the request comes from.
To build the feature I am proposing with cpuset, I think you would need a cgroup per package and would have to place each thread in the one matching the package its CPU is in.
cpuset.mems does not follow the CPU, so unless cpuset.cpus is set alongside it, a thread running on a CPU of package 1 would use node0 and node2. For a program with tens or hundreds of threads, keeping that placement right does not look easy.
To put it plainly, what this series aims for is that when a process with many threads runs across several packages, each thread's allocations are weighted-interleaved within the nodes of the package that thread is on.
There is one process and one policy, but the nodes actually used differ with where each thread sits. That is why I think this has to be per task rather than per process.
The workloads I had in mind are memory-intensive server workloads:
vector databases as used in AI applications, or in-memory key-value caching services that sit in front of large services and keep their data in memory.
They run with a great many threads, spread across several packages and running at the same time, and they want as much memory bandwidth as they can get.
That is also why the numbers were measured with MLC. It produces high bandwidth from many threads, much like those workloads, while still giving a quantitative result.
The runs used "numactl -w all mlc" with no CPU binding, so the threads were spread over both packages, and in that configuration the bandwidth was higher than with the existing weighted interleave.
That is the reasoning behind my thinking that this belongs at the task level. In the next version I will strengthen the documentation, including why this feature is needed.
Thank you for taking the time to review this and for the question. It made it much clearer to me what the cover letter still needs to explain.
Rakie Kim
Gregory Price
maintainerQuoted 5 lines · Rakie Kim
On Wed, 12 Aug 2026 22:37:06 -0400 Gregory Price <[email protected]> wrote:
The cpuset.mems = 0,2 you describe is the node set of package 0, so the tasks in that cgroup use node0 and node2 wherever they run.
I think you are over-complicating the explanation and that's making it hard for folks to reason about this.
My best understanding here is for multi-socket systems, weighted interleave as-designed is inherently sub-optimal for scaled workloads that utilize multi-socket ("package") memory resources (DRAM, CXL...)
I think there is also an assumption that total memory utilization is less than the total capacity - otherwise some of the assumptions here break, but that comes with the general weighted interleave story.
I'm getting back from vacation, I will take a closer look this week.
~Gregory
Joshua Hahn
reviewerQuoted 7 lines · On Sun, 16 Aug 2026 20:46:16 -0400 Gregory Price <[email protected]> wrote:
Quoted 5 lines · Rakie Kim
On Wed, 12 Aug 2026 22:37:06 -0400 Gregory Price <[email protected]> wrote:
The cpuset.mems = 0,2 you describe is the node set of package 0, so the tasks in that cgroup use node0 and node2 wherever they run.
Quoted 6 lines
I think you are over-complicating the explanation and that's making it hard for folks to reason about this.
My best understanding here is for multi-socket systems, weighted interleave as-designed is inherently sub-optimal for scaled workloads that utilize multi-socket ("package") memory resources (DRAM, CXL...)
I was thinking about this and I think Gregory is right here.
I wonder how much of the framing around this series can be preserved / simplified if we just say "prevent tasks from allocating memory cross-socket".
I also wonder if instead of limiting this to weighted interleave, this can sit on top of other mpols and just nodemasks against cross-socket nodes.
Quoted 5 lines
I think there is also an assumption that total memory utilization is less than the total capacity - otherwise some of the assumptions here break, but that comes with the general weighted interleave story.
I'm getting back from vacation, I will take a closer look this week.
I am also out on vacation this week : -)
I'll take a closer look along with the code next week as well.
Thanks, Rakie and Gregory!
Joshua
Rakie Kim
reviewerOn Sun, 16 Aug 2026 21:52:24 -0700 Joshua Hahn <[email protected]> wrote:
Hello Joshua,
Thanks for your feedback.
Quoted 10 lines · On Sun, 16 Aug 2026 20:46:16 -0400 Gregory Price <[email protected]> wrote:
Quoted 7 lines
I think you are over-complicating the explanation and that's making it hard for folks to reason about this.
My best understanding here is for multi-socket systems, weighted interleave as-designed is inherently sub-optimal for scaled workloads that utilize multi-socket ("package") memory resources (DRAM, CXL...)
I was thinking about this and I think Gregory is right here.
I agree. From now on I will keep my explanations focused on the key points.
Quoted 3 lines
I wonder how much of the framing around this series can be preserved / simplified if we just say "prevent tasks from allocating memory cross-socket".
I think this is a good suggestion. Even if it is not this exact wording, I will look for a shorter and better description that includes your idea.
Quoted 3 lines
I also wonder if instead of limiting this to weighted interleave, this can sit on top of other mpols and just nodemasks against cross-socket nodes.
It does not have to apply only to weighted interleave. Patch 2 simply groups NUMA nodes by the package they belong to. So the same grouping can also be used for interleave, not just weighted interleave. I have not applied it to interleave because I could not find a clear use case for it yet.
Quoted 2 lines
I am also out on vacation this week : -)
I'll take a closer look along with the code next week as well.
Thank you. I look forward to your comments.
Thanks again for your time and review.
Rakie Kim
Rakie Kim
reviewerOn Sun, 16 Aug 2026 20:46:16 -0400 Gregory Price <[email protected]> wrote:
Hello Gregory,
Thanks for your review and feedback.
Quoted 2 lines
I think you are over-complicating the explanation and that's making it hard for folks to reason about this.
You are right. I will keep my explanations focused on the key points from here on, and the next cover letter will be written that way as well.
Quoted 3 lines
My best understanding here is for multi-socket systems, weighted interleave as-designed is inherently sub-optimal for scaled workloads that utilize multi-socket ("package") memory resources (DRAM, CXL...)
Your summary is correct. That is the problem this series addresses.
Quoted 3 lines
I think there is also an assumption that total memory utilization is less than the total capacity - otherwise some of the assumptions here break, but that comes with the general weighted interleave story.
Your assumption is correct. It is the same as the existing weighted
interleave: when the nodes are full, memory is allocated from other nodes.
Quoted 1 line
I'm getting back from vacation, I will take a closer look this week.
Thank you. I look forward to your comments.
Thanks again for your time and review.
Rakie Kim
Gregory Price
maintainerQuoted 6 lines · Rakie Kim
To make this possible the kernel needs a notion of which nodes share a package. The NUMA distance model offers only relative latencies and no structural grouping, which is especially limiting for CXL memory nodes that come online without an explicit package association.
The original attempt to handle cross-socket interleave tried to deal with this with a matrix for weights, but this was deemed too invasive.
This brings back that matrix, but not for per-node weights - we're basically just adding an addition weighting to filter on.
I have some concerns with the now additional filtering mechanism introdced into the allocation stack, but fundamentally I think this is a *better* solution than a straight weight-matrix.
I will need to chew on this for a bit. It seems there's non-trivial sashiko bug reports here to address anyway.
Quoted 7 lines
The series adds a package-aware topology layer that groups CPU and memory-only nodes into a "memory package", built from the physical package ids firmware reports and, for a memory-only node, an initiator CPU node or SLIT distances. A package can contain more than one CPU node or more than one memory-only node, so the layer maps a package to a set of nodes rather than to a single node or a single CXL device.
When worded this way, "Package" sounds completely arbitrary and not a useful distinction. This really just sounds like an extention for the existing fallback lists to take interconnects into account.
I wonder if abstract distance either:
1) already gives you what you want (the secondary weight)
2) can be twiddled in BIOS to give you what you want.
Quoted 7 lines
The feature is off by default and opt-in through a sysfs toggle. The package topology itself is exposed read-only under
/sys/devices/system/package/; there is deliberately no writable override, since a machine whose firmware describes its topology incorrectly should be fixed in firmware. On a topology that does not have the symmetric shape the placement relies on, enabling is refused and any active mode degrades cleanly to the original flat behavior.
The way this is written it sounds to me like this should just be the default weighted interleave behavior. We already know weighted interleave does not jive well with multi-socket systems - this just fixes that (in a more general sense, Socket => Package).
~Gregory
Rakie Kim
reviewerQuoted 5 lines · On Mon, 17 Aug 2026 12:19:51 -0400 Gregory Price <[email protected]> wrote:
The original attempt to handle cross-socket interleave tried to deal with this with a matrix for weights, but this was deemed too invasive.
This brings back that matrix, but not for per-node weights - we're basically just adding an addition weighting to filter on.
Yes. It uses additional information to filter the nodes weighted interleave selects from.
Quoted 3 lines
I have some concerns with the now additional filtering mechanism introdced into the allocation stack, but fundamentally I think this is a *better* solution than a straight weight-matrix.
About the cost of the filter: when the toggle is off, the filter does not run. When it is on, node selection needs a nodemask filtering step, but in my tests the overhead was negligible. I will look at this part further and check whether there is more room to optimize.
Quoted 2 lines
I will need to chew on this for a bit. It seems there's non-trivial sashiko bug reports here to address anyway.
I am working on the sashiko findings now. The valid ones will be fixed in the next version.
Quoted 3 lines
When worded this way, "Package" sounds completely arbitrary and not a useful distinction. This really just sounds like an extention for the existing fallback lists to take interconnects into account.
Other reviewers also pointed out that the "package" / "socket" terminology is ambiguous. I think the description needs a full rework so that it explains the current state better, and I plan to do that in the next version.
Quoted 3 lines
I wonder if abstract distance either:
1) already gives you what you want (the secondary weight)
2) can be twiddled in BIOS to give you what you want.
I thought about abstract distance a lot as well. My conclusion was that adistance alone cannot tell whether nodes are in the same package. This is an area I am still thinking about, and it needs more thought.
About the BIOS information: as I reported before, on the two-package server I tested, each package had its own CXL device, but the HMAT reported one CPU node as the initiator of both CXL nodes:
https://lore.kernel.org/all/[email protected]/
I will post an update on that issue as well. What this series uses is, in the end, BIOS information too. But some of that information has errors and some of it looks reliable, so I think we also need to sort out which is which, and understand why.
Quoted 4 lines
The way this is written it sounds to me like this should just be the default weighted interleave behavior. We already know weighted interleave does not jive well with multi-socket systems - this just fixes that (in a more general sense, Socket => Package).
I agree with your point. The default is off because it was requested during the v1 review; Jonathan asked for it:
https://lore.kernel.org/all/[email protected]/
Enabling is also not unconditional. I added a few constraints, so it turns on only in a specific situation: when the packages have the same node structure. I think the definition of these on/off conditions is open, and it needs more discussion.
Thanks again for your time and review.
Rakie Kim
Gregory Price
maintainerQuoted 11 lines · Rakie Kim
Quoted 3 lines · On Mon, 17 Aug 2026 12:19:51 -0400 Gregory Price <[email protected]> wrote:
I have some concerns with the now additional filtering mechanism introdced into the allocation stack, but fundamentally I think this is a *better* solution than a straight weight-matrix.
About the cost of the filter: when the toggle is off, the filter does not run. When it is on, node selection needs a nodemask filtering step, but in my tests the overhead was negligible. I will look at this part further and check whether there is more room to optimize.
Not concerned about the performance, concerned about how complicated the mempolicy - cgroup - zonelist - page_alloc interaction already is, and then adding another filtering mechanism on top.
Today we have:
1) cpuset constrains mempolicy (nodemask remaps)
2) cpuset constrains zonelist walks
3) mempolicy nodemask constrains zonelist walks
4) memory-tiers.c nodemask constrains zonelist walks for demotion
5) zonelist membership constrains allocation access
6) a bunch of corner conditions that violate 1-3 for the sake of forward progress
now we're adding:
7) memory-tiers.c nodemask constrains mempolicy nodemask except when it doesn't, because fallbacks occurred hard enough
It's already un-intuitive how and when memory lands on certain nodes.
To be clear, I'm not saying this idea is bad - either as-is or in some other form - just that adding another nodemask filtering path is making it harder and harder to understand what lands where.
Mostly starting to wonder if we're reaching the point where the page allocator needs to take something a little more descriptive than a nodemask to dictate placement.
~Gregory
Rakie Kim
reviewerQuoted 16 lines · On Tue, 18 Aug 2026 09:30:36 -0400 Gregory Price <[email protected]> wrote:
Not concerned about the performance, concerned about how complicated the mempolicy - cgroup - zonelist -
page_allocinteraction already is, and then adding another filtering mechanism on top.Today we have:
1) cpuset constrains mempolicy (nodemask remaps)
2) cpuset constrains zonelist walks
3) mempolicy nodemask constrains zonelist walks
4)memory-tiers.cnodemask constrains zonelist walks for demotion
5) zonelist membership constrains allocation access
6) a bunch of corner conditions that violate 1-3 for the sake of forward progressnow we're adding:
Quoted 8 lines
7)
memory-tiers.cnodemask constrains mempolicy nodemask except when it doesn't, because fallbacks occurred hard enoughIt's already un-intuitive how and when memory lands on certain nodes.
To be clear, I'm not saying this idea is bad - either as-is or in some other form - just that adding another nodemask filtering path is making it harder and harder to understand what lands where.
I understand what you are concerned about, and I share the concern.
I tried to keep the addition minimal and to make it act only in the intended situation: the filter runs in weighted interleave node selection, only while the toggle is on. It does not change cpusets, the zonelist, or the allocator fallback. Still, it is true that this adds one more filtering layer to the constraints you listed.
I will try to organize this part so that it is as easy to follow as possible, and reinforce the documentation as well. I am not sure that will be enough, though - it needs more thought.
Quoted 3 lines
Mostly starting to wonder if we're reaching the point where the page allocator needs to take something a little more descriptive than a nodemask to dictate placement.
This is something I think about a lot as well. Many users simply let the policy use all nodes, and in the situation this series targets, that is exactly what costs performance. To fix it, the kernel needs more information than a nodemask carries. But as you pointed out, adding that information also adds complexity. This is my concern as well, and I think how to handle it needs a discussion.
Thanks again for your time and review.
Rakie Kim