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

vmalloc: use for_each_vmap_node() in purge-vmap-area

Update a __purge_vmap_area_lazy() to use introduced helper. This is last
place in vmalloc code. Also this patch introduces an extra function which
is node_to_id() that converts a vmap_node pointer to an index in array.

__purge_vmap_area_lazy() requires that extra function.

Link: https://lkml.kernel.org/r/20250408151549.77937-3-urezki@gmail.com
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Christop Hellwig <hch@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Uladzislau Rezki (Sony) and committed by
Andrew Morton
24c76f37 ce906d76

+15 -4
+15 -4
mm/vmalloc.c
··· 923 923 return &vmap_nodes[id % nr_vmap_nodes]; 924 924 } 925 925 926 + static inline unsigned int 927 + node_to_id(struct vmap_node *node) 928 + { 929 + /* Pointer arithmetic. */ 930 + unsigned int id = node - vmap_nodes; 931 + 932 + if (likely(id < nr_vmap_nodes)) 933 + return id; 934 + 935 + WARN_ONCE(1, "An address 0x%p is out-of-bounds.\n", node); 936 + return 0; 937 + } 938 + 926 939 /* 927 940 * We use the value 0 to represent "no node", that is why 928 941 * an encoded value will be the node-id incremented by 1. ··· 2272 2259 */ 2273 2260 purge_nodes = CPU_MASK_NONE; 2274 2261 2275 - for (i = 0; i < nr_vmap_nodes; i++) { 2276 - vn = &vmap_nodes[i]; 2277 - 2262 + for_each_vmap_node(vn) { 2278 2263 INIT_LIST_HEAD(&vn->purge_list); 2279 2264 vn->skip_populate = full_pool_decay; 2280 2265 decay_va_pool_node(vn, full_pool_decay); ··· 2291 2280 end = max(end, list_last_entry(&vn->purge_list, 2292 2281 struct vmap_area, list)->va_end); 2293 2282 2294 - cpumask_set_cpu(i, &purge_nodes); 2283 + cpumask_set_cpu(node_to_id(vn), &purge_nodes); 2295 2284 } 2296 2285 2297 2286 nr_purge_nodes = cpumask_weight(&purge_nodes);