Skip to content

Commit

Permalink
mm/vmstat: replace cpumask_weight with cpumask_empty where appropriate
Browse files Browse the repository at this point in the history
mm/vmstat.c code calls cpumask_weight() to check if any bit of a given
cpumask is set. We can do it more efficiently with cpumask_empty() because
cpumask_empty() stops traversing the cpumask as soon as it finds first set
bit, while cpumask_weight() counts all bits unconditionally.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
  • Loading branch information
Yury Norov committed Jun 3, 2022
1 parent 95e3a97 commit b55032f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mm/vmstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,7 @@ static void __init init_cpu_node_state(void)
int node;

for_each_online_node(node) {
if (cpumask_weight(cpumask_of_node(node)) > 0)
if (!cpumask_empty(cpumask_of_node(node)))
node_set_state(node, N_CPU);
}
}
Expand Down Expand Up @@ -2074,7 +2074,7 @@ static int vmstat_cpu_dead(unsigned int cpu)

refresh_zone_stat_thresholds();
node_cpus = cpumask_of_node(node);
if (cpumask_weight(node_cpus) > 0)
if (!cpumask_empty(node_cpus))
return 0;

node_clear_state(node, N_CPU);
Expand Down

0 comments on commit b55032f

Please sign in to comment.