Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mm: Replace nodes_weight() with nodes_empty() where appropriate

Various mm code calls nodes_weight() to check if any bit of a given
nodemask is set.

This can be done more efficiently with nodes_empty() because nodes_empty()
stops traversing the nodemask as soon as it finds first set bit, while
nodes_weight() counts all bits unconditionally.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20220210224933.379149-26-yury.norov@gmail.com

authored by

Yury Norov and committed by
Thomas Gleixner
c2a911d3 3a5ff1f6

+3 -3
+1 -1
arch/x86/mm/amdtopology.c
··· 154 154 node_set(nodeid, numa_nodes_parsed); 155 155 } 156 156 157 - if (!nodes_weight(numa_nodes_parsed)) 157 + if (nodes_empty(numa_nodes_parsed)) 158 158 return -ENOENT; 159 159 160 160 /*
+2 -2
arch/x86/mm/numa_emulation.c
··· 123 123 * Continue to fill physical nodes with fake nodes until there is no 124 124 * memory left on any of them. 125 125 */ 126 - while (nodes_weight(physnode_mask)) { 126 + while (!nodes_empty(physnode_mask)) { 127 127 for_each_node_mask(i, physnode_mask) { 128 128 u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN); 129 129 u64 start, limit, end; ··· 270 270 * Fill physical nodes with fake nodes of size until there is no memory 271 271 * left on any of them. 272 272 */ 273 - while (nodes_weight(physnode_mask)) { 273 + while (!nodes_empty(physnode_mask)) { 274 274 for_each_node_mask(i, physnode_mask) { 275 275 u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN); 276 276 u64 start, limit, end;