[gmprice:weighted_interleave-next 3/3] mm/mempolicy.c:2415:34: warning: variable 'next_node' is uninitialized when used here

kernel test robot
2024-01-31T04:40:22Z

tree: https://github.com/gmprice/linux weighted_interleave-next
head: 8b894625fd0b7f702c0aa6e14bb673c59f42effc
commit: 8b894625fd0b7f702c0aa6e14bb673c59f42effc [3/3] mm/mempolicy: introduce MPOL_WEIGHTED_INTERLEAVE for weighted interleaving
config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20240131/202401311232.MSZXYoFZ-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project fdac7d0b6f74f919d319b31a0680c77f66732586)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240131/202401311232.MSZXYoFZ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401311232.MSZXYoFZ-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> mm/mempolicy.c:2415:34: warning: variable 'next_node' is uninitialized when used here [-Wuninitialized]
2415 | me->il_weight = get_il_weight(next_node);
| ^~~~~~~~~
mm/mempolicy.c:2385:29: note: initialize the variable 'next_node' to silence this warning
2385 | int nnodes, node, next_node;
| ^
| = 0
1 warning generated.

vim +/next_node +2415 mm/mempolicy.c

2371
2372 static unsigned long alloc_pages_bulk_array_weighted_interleave(gfp_t gfp,
2373 struct mempolicy *pol, unsigned long nr_pages,
2374 struct page **page_array)
2375 {
2376 struct task_struct *me = current;
2377 unsigned long total_allocated = 0;
2378 unsigned long nr_allocated = 0;
2379 unsigned long rounds;
2380 unsigned long node_pages, delta;
2381 u8 __rcu *table, *weights, weight;
2382 unsigned int weight_total = 0;
2383 unsigned long rem_pages = nr_pages;
2384 nodemask_t nodes;
2385 int nnodes, node, next_node;
2386 int resume_node = MAX_NUMNODES - 1;
2387 u8 resume_weight = 0;
2388 int prev_node;
2389 int i;
2390
2391 if (!nr_pages)
2392 return 0;
2393
2394 nnodes = read_once_policy_nodemask(pol, &nodes);
2395 if (!nnodes)
2396 return 0;
2397
2398 /* Continue allocating from most recent node and adjust the nr_pages */
2399 node = me->il_prev;
2400 weight = me->il_weight;
2401 if (weight && node_isset(node, nodes)) {
2402 node_pages = min(rem_pages, weight);
2403 nr_allocated = __alloc_pages_bulk(gfp, node, NULL, node_pages,
2404 NULL, page_array);
2405 page_array += nr_allocated;
2406 total_allocated += nr_allocated;
2407 /* if that's all the pages, no need to interleave */
2408 if (rem_pages < weight) {
2409 /* stay on current node, adjust il_weight */
2410 me->il_weight -= rem_pages;
2411 return total_allocated;
2412 } else if (rem_pages == weight) {
2413 /* move to next node / weight */
2414 me->il_prev = next_node_in(node, nodes);
> 2415 me->il_weight = get_il_weight(next_node);
2416 return total_allocated;
2417 }
2418 /* Otherwise we adjust remaining pages, continue from there */
2419 rem_pages -= weight;
2420 }
2421 /* clear active weight in case of an allocation failure */
2422 me->il_weight = 0;
2423 prev_node = node;
2424
2425 /* create a local copy of node weights to operate on outside rcu */
2426 weights = kzalloc(nr_node_ids, GFP_KERNEL);
2427 if (!weights)
2428 return total_allocated;
2429
2430 rcu_read_lock();
2431 table = rcu_dereference(iw_table);
2432 if (table)
2433 memcpy(weights, table, nr_node_ids);
2434 rcu_read_unlock();
2435
2436 /* calculate total, detect system default usage */
2437 for_each_node_mask(node, nodes) {
2438 if (!weights[node])
2439 weights[node] = 1;
2440 weight_total += weights[node];
2441 }
2442
2443 /*
2444 * Calculate rounds/partial rounds to minimize __alloc_pages_bulk calls.
2445 * Track which node weighted interleave should resume from.
2446 *
2447 * if (rounds > 0) and (delta == 0), resume_node will always be
2448 * the node following prev_node and its weight.
2449 */
2450 rounds = rem_pages / weight_total;
2451 delta = rem_pages % weight_total;
2452 resume_node = next_node_in(prev_node, nodes);
2453 resume_weight = weights[resume_node];
2454 for (i = 0; i < nnodes; i++) {
2455 node = next_node_in(prev_node, nodes);
2456 weight = weights[node];
2457 node_pages = weight * rounds;
2458 /* If a delta exists, add this node's portion of the delta */
2459 if (delta > weight) {
2460 node_pages += weight;
2461 delta -= weight;
2462 } else if (delta) {
2463 node_pages += delta;
2464 /* delta may deplete on a boundary or w/ a remainder */
2465 if (delta == weight) {
2466 /* boundary: resume from next node/weight */
2467 resume_node = next_node_in(node, nodes);
2468 resume_weight = weights[resume_node];
2469 } else {
2470 /* remainder: resume this node w/ remainder */
2471 resume_node = node;
2472 resume_weight = weight - delta;
2473 }
2474 delta = 0;
2475 }
2476 /* node_pages can be 0 if an allocation fails and rounds == 0 */
2477 if (!node_pages)
2478 break;
2479 nr_allocated = __alloc_pages_bulk(gfp, node, NULL, node_pages,
2480 NULL, page_array);
2481 page_array += nr_allocated;
2482 total_allocated += nr_allocated;
2483 if (total_allocated == nr_pages)
2484 break;
2485 prev_node = node;
2486 }
2487 me->il_prev = resume_node;
2488 me->il_weight = resume_weight;
2489 kfree(weights);
2490 return total_allocated;
2491 }
2492

--
0-DAY CI Kernel Test Service