Skip to content

Commit 54880b5

Browse files
author
Frederic Weisbecker
committed
mm: Create/affine kcompactd to its preferred node
Kcompactd is dedicated to a specific node. As such it wants to be preferrably affine to it, memory and CPUs-wise. Use the proper kthread API to achieve that. As a bonus it takes care of CPU-hotplug events and CPU-isolation on its behalf. Acked-by: Vlastimil Babka <[email protected]> Acked-by: Michal Hocko <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent d1a8919 commit 54880b5

File tree

1 file changed

+3
-40
lines changed

1 file changed

+3
-40
lines changed

mm/compaction.c

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,15 +3154,9 @@ void wakeup_kcompactd(pg_data_t *pgdat, int order, int highest_zoneidx)
31543154
static int kcompactd(void *p)
31553155
{
31563156
pg_data_t *pgdat = (pg_data_t *)p;
3157-
struct task_struct *tsk = current;
31583157
long default_timeout = msecs_to_jiffies(HPAGE_FRAG_CHECK_INTERVAL_MSEC);
31593158
long timeout = default_timeout;
31603159

3161-
const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id);
3162-
3163-
if (!cpumask_empty(cpumask))
3164-
set_cpus_allowed_ptr(tsk, cpumask);
3165-
31663160
set_freezable();
31673161

31683162
pgdat->kcompactd_max_order = 0;
@@ -3233,10 +3227,12 @@ void __meminit kcompactd_run(int nid)
32333227
if (pgdat->kcompactd)
32343228
return;
32353229

3236-
pgdat->kcompactd = kthread_run(kcompactd, pgdat, "kcompactd%d", nid);
3230+
pgdat->kcompactd = kthread_create_on_node(kcompactd, pgdat, nid, "kcompactd%d", nid);
32373231
if (IS_ERR(pgdat->kcompactd)) {
32383232
pr_err("Failed to start kcompactd on node %d\n", nid);
32393233
pgdat->kcompactd = NULL;
3234+
} else {
3235+
wake_up_process(pgdat->kcompactd);
32403236
}
32413237
}
32423238

@@ -3254,30 +3250,6 @@ void __meminit kcompactd_stop(int nid)
32543250
}
32553251
}
32563252

3257-
/*
3258-
* It's optimal to keep kcompactd on the same CPUs as their memory, but
3259-
* not required for correctness. So if the last cpu in a node goes
3260-
* away, we get changed to run anywhere: as the first one comes back,
3261-
* restore their cpu bindings.
3262-
*/
3263-
static int kcompactd_cpu_online(unsigned int cpu)
3264-
{
3265-
int nid;
3266-
3267-
for_each_node_state(nid, N_MEMORY) {
3268-
pg_data_t *pgdat = NODE_DATA(nid);
3269-
const struct cpumask *mask;
3270-
3271-
mask = cpumask_of_node(pgdat->node_id);
3272-
3273-
if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
3274-
/* One of our CPUs online: restore mask */
3275-
if (pgdat->kcompactd)
3276-
set_cpus_allowed_ptr(pgdat->kcompactd, mask);
3277-
}
3278-
return 0;
3279-
}
3280-
32813253
static int proc_dointvec_minmax_warn_RT_change(const struct ctl_table *table,
32823254
int write, void *buffer, size_t *lenp, loff_t *ppos)
32833255
{
@@ -3337,15 +3309,6 @@ static struct ctl_table vm_compaction[] = {
33373309
static int __init kcompactd_init(void)
33383310
{
33393311
int nid;
3340-
int ret;
3341-
3342-
ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
3343-
"mm/compaction:online",
3344-
kcompactd_cpu_online, NULL);
3345-
if (ret < 0) {
3346-
pr_err("kcompactd: failed to register hotplug callbacks.\n");
3347-
return ret;
3348-
}
33493312

33503313
for_each_node_state(nid, N_MEMORY)
33513314
kcompactd_run(nid);

0 commit comments

Comments
 (0)