[PATCH v2] mm/vmscan.c: only adjust related kswapd cpu affinity when online cpu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When onlining a cpu, kswapd_cpu_online() is called to adjust kswapd cpu
affinity.

Current routine does like this:

  a) Iterate all the numa node
  b) Adjust cpu affinity when node has an online cpu

For a) this is not necessary, since the particular online cpu belongs to
a particular numa node. So it is not necessary to iterate on every nodes
on the system. This new onlined cpu just affect kswapd cpu affinity of
this particular node.

For b) several cpumask operation is used to check whether the node has
an online CPU. Since at this point we are sure one of our CPU onlined,
we can set the cpu affinity directly to current cpumask_of_node().

This patch simplifies the logic by set cpu affinity of the affected
kswapd.

---
v2:
  * rephrase the changelog

Signed-off-by: Wei Yang <richardw.yang@xxxxxxxxxxxxxxx>
---
 mm/vmscan.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 665f33258cd7..acc5af82b6ed 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4029,18 +4029,19 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
    restore their cpu bindings. */
 static int kswapd_cpu_online(unsigned int cpu)
 {
-	int nid;
+	int nid = cpu_to_node(cpu);
+	pg_data_t *pgdat;
+	const struct cpumask *mask;
 
-	for_each_node_state(nid, N_MEMORY) {
-		pg_data_t *pgdat = NODE_DATA(nid);
-		const struct cpumask *mask;
+	if (!node_state(nid, N_MEMORY))
+		return 0;
 
-		mask = cpumask_of_node(pgdat->node_id);
+	pgdat = NODE_DATA(nid);
+	mask = cpumask_of_node(nid);
+
+	/* One of our CPUs online: restore mask */
+	set_cpus_allowed_ptr(pgdat->kswapd, mask);
 
-		if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
-			/* One of our CPUs online: restore mask */
-			set_cpus_allowed_ptr(pgdat->kswapd, mask);
-	}
 	return 0;
 }
 
-- 
2.17.1





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux