The kcompactd threads are affined to housekeeping CPUs (HK_TYPE_DOMAIN)
at boot to avoid interference with isolated workloads. Currently,
these threads do not migrate when the housekeeping boundaries are
reconfigured at runtime.
Implement a housekeeping notifier to synchronize kcompactd affinity.
This ensures that background compaction threads honor the dynamic
isolation boundaries configured via the DHEI sysfs interface.
Signed-off-by: Qiliang Yuan <realwujing@gmail.com>
---
mm/compaction.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/mm/compaction.c b/mm/compaction.c
index 1e8f8eca318c6..574ee3c6dc942 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -24,6 +24,7 @@
#include <linux/page_owner.h>
#include <linux/psi.h>
#include <linux/cpuset.h>
+#include <linux/sched/isolation.h>
#include "internal.h"
#ifdef CONFIG_COMPACTION
@@ -3246,6 +3247,7 @@ void __meminit kcompactd_run(int nid)
pr_err("Failed to start kcompactd on node %d\n", nid);
pgdat->kcompactd = NULL;
} else {
+ housekeeping_affine(pgdat->kcompactd, HK_TYPE_KTHREAD);
wake_up_process(pgdat->kcompactd);
}
}
@@ -3320,6 +3322,30 @@ static const struct ctl_table vm_compaction[] = {
},
};
+static int kcompactd_housekeeping_reconfigure(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct housekeeping_update *upd = data;
+ unsigned int type = upd->type;
+
+ if (action == HK_UPDATE_MASK && type == HK_TYPE_KTHREAD) {
+ int nid;
+
+ for_each_node_state(nid, N_MEMORY) {
+ pg_data_t *pgdat = NODE_DATA(nid);
+
+ if (pgdat->kcompactd)
+ housekeeping_affine(pgdat->kcompactd, HK_TYPE_KTHREAD);
+ }
+ }
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block kcompactd_housekeeping_nb = {
+ .notifier_call = kcompactd_housekeeping_reconfigure,
+};
+
static int __init kcompactd_init(void)
{
int nid;
@@ -3327,6 +3353,7 @@ static int __init kcompactd_init(void)
for_each_node_state(nid, N_MEMORY)
kcompactd_run(nid);
register_sysctl_init("vm", vm_compaction);
+ housekeeping_register_notifier(&kcompactd_housekeeping_nb);
return 0;
}
subsys_initcall(kcompactd_init)
--
2.43.0