The following patch series enhances the weighted interleave policy in the memory management subsystem by improving sysfs handling, fixing memory leaks, and introducing dynamic sysfs updates for memory hotplug support. ### Background The weighted interleave policy distributes memory allocations across multiple NUMA nodes based on their performance weight, thereby optimizing memory bandwidth utilization. The weight values are configured through sysfs. Previously, sysfs entries for weighted interleave were managed statically at initialization. This led to several issues: - Memory Leaks: Improper `kobject` deallocation caused memory leaks when initialization failed or when nodes were removed. - Lack of Dynamic Updates: Sysfs attributes were created only during initialization, preventing nodes added at runtime from being recognized. - Handling of Unusable Nodes: Sysfs entries were generated for all possible nodes (`N_POSSIBLE`), including memoryless or unavailable nodes, leading to unnecessary sysfs attributes and misconfiguration issues. ### Patch Overview 1. [PATCH 1/3] Fix memory leaks in weighted interleave sysfs - Ensures proper cleanup of `kobject` allocations. - Replaces unnecessary `kfree()` calls with `kobject_put()`, preventing memory leaks and improving system stability. 2. [PATCH 2/3] Enable dynamic updates for weighted interleave sysfs - Restructures sysfs handling to allow runtime updates. - The sysfs attributes are now globally accessible, enabling external modules to manage interleave settings dynamically. 3. [PATCH 3/3] Support memory hotplug in weighted interleave - Modifies sysfs creation logic to restrict entries to nodes that are online and have memory, excluding unusable nodes. - Introduces a memory hotplug mechanism to dynamically add and remove sysfs attributes when nodes transition into or out of the `N_MEMORY` set. - Ensures that sysfs attributes are properly removed when nodes go offline, preventing stale or redundant entries from persisting. These patches have been tested under CXL-based memory configurations, including hotplug scenarios, to ensure proper behavior and stability. mm/mempolicy.c | 191 +++++++++++++++++++++++++++++++------------------ 1 file changed, 123 insertions(+), 68 deletions(-) base-commit: 4701f33a10702d5fc577c32434eb62adde0a1ae1 -- 2.34.1