diff --git a/mm/compaction.c b/mm/compaction.c index 80116210c2e64ec2db3d95c87eabbb052dae072e..509dee7c2f384944ee78f73b5a6415621b85989c 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1926,7 +1926,9 @@ static inline bool is_via_compact_memory(int order) static bool kswapd_is_running(pg_data_t *pgdat) { - return pgdat->kswapd && (pgdat->kswapd->state == TASK_RUNNING); + struct task_struct *t = READ_ONCE(pgdat->kswapd); + + return t && (t->state == TASK_RUNNING); } /* diff --git a/mm/vmscan.c b/mm/vmscan.c index ace42e822aabc40da14c06d62b3a64fd2f27620e..a177de05a1a4c9c2912f44b16767ade56ac84dc4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4331,7 +4331,7 @@ int kswapd_run(int nid) int ret = 0; struct task_struct *t; - if (pgdat->kswapd) + if (READ_ONCE(pgdat->kswapd)) return 0; t = kthread_run(kswapd, pgdat, "kswapd%d", nid); @@ -4341,7 +4341,7 @@ int kswapd_run(int nid) pr_err("Failed to start kswapd on node %d\n", nid); ret = PTR_ERR(t); } else { - pgdat->kswapd = t; + WRITE_ONCE(pgdat->kswapd, t); } return ret; } @@ -4352,11 +4352,11 @@ int kswapd_run(int nid) */ void kswapd_stop(int nid) { - struct task_struct *kswapd = NODE_DATA(nid)->kswapd; + struct task_struct *kswapd = READ_ONCE(NODE_DATA(nid)->kswapd); if (kswapd) { kthread_stop(kswapd); - NODE_DATA(nid)->kswapd = NULL; + WRITE_ONCE(NODE_DATA(nid)->kswapd, NULL); } }