Skip to contentSkip to conversation

mm/swap_state.c:481 __swap_cache_alloc() warn: use 'gfp' here instead of GFP_KERNEL?

PATCH New Dan Carpenter 1 participant 1 message Sep 14

lore
Share & tools
lore
#0 lore raw

PATCH 41/84 mm/swap_state.c:481 __swap_cache_alloc() warn: use 'gfp' here instead of GFP_KERNEL?

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/kas/linux.git collapse/rfc-wip
head:   36226b1e4970c52a3c0d491dcf17800eb800958a
commit: 1e7fc9164723073d7b48f251446ae662becf45e2 [41/84] mm/huge_memory: let the caller pick the gfp for the deferred-split heads
config: mips-randconfig-r072-20260913 (https://download.01.org/0day-ci/archive/20260914/[email protected]/config)
compiler: mips64-linux-gcc (GCC) 16.1.0
smatch: v0.5.0-9187-g5189e3fb

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
mm/swap_state.c:481 __swap_cache_alloc() warn: use 'gfp' here instead of GFP_KERNEL?

vim +/gfp +481 mm/swap_state.c

e1e6750df3b473 Kairui Song            2026-05-17  416  static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
e1e6750df3b473 Kairui Song            2026-05-17  417  					swp_entry_t targ_entry, gfp_t gfp,
e1e6750df3b473 Kairui Song            2026-05-17  418  					unsigned int order, struct vm_fault *vmf,
e1e6750df3b473 Kairui Song            2026-05-17  419  					struct mempolicy *mpol, pgoff_t ilx)
e1e6750df3b473 Kairui Song            2026-05-17  420  {
e1e6750df3b473 Kairui Song            2026-05-17  421  	int err;
e1e6750df3b473 Kairui Song            2026-05-17  422  	swp_entry_t entry;
e1e6750df3b473 Kairui Song            2026-05-17  423  	struct folio *folio;
e1e6750df3b473 Kairui Song            2026-05-17  424  	void *shadow = NULL;
bc34e87a51d9e5 Kairui Song            2026-05-17  425  	unsigned short memcg_id;
e1e6750df3b473 Kairui Song            2026-05-17  426  	unsigned long address, nr_pages = 1UL << order;
e1e6750df3b473 Kairui Song            2026-05-17  427  	struct vm_area_struct *vma = vmf ? vmf->vma : NULL;
e1e6750df3b473 Kairui Song            2026-05-17  428  
e1e6750df3b473 Kairui Song            2026-05-17  429  	VM_WARN_ON_ONCE(nr_pages > SWAPFILE_CLUSTER);
e1e6750df3b473 Kairui Song            2026-05-17  430  	entry.val = round_down(targ_entry.val, nr_pages);
e1e6750df3b473 Kairui Song            2026-05-17  431  
e1e6750df3b473 Kairui Song            2026-05-17  432  	/* Check if the slot and range are available, skip allocation if not */
e1e6750df3b473 Kairui Song            2026-05-17  433  	spin_lock(&ci->lock);
bc34e87a51d9e5 Kairui Song            2026-05-17  434  	err = __swap_cache_add_check(ci, targ_entry, nr_pages, NULL, NULL);
e1e6750df3b473 Kairui Song            2026-05-17  435  	spin_unlock(&ci->lock);
e1e6750df3b473 Kairui Song            2026-05-17  436  	if (unlikely(err))
e1e6750df3b473 Kairui Song            2026-05-17  437  		return ERR_PTR(err);
e1e6750df3b473 Kairui Song            2026-05-17  438  
e1e6750df3b473 Kairui Song            2026-05-17  439  	/*
e1e6750df3b473 Kairui Song            2026-05-17  440  	 * Limit THP gfp. The limitation is a no-op for typical
e1e6750df3b473 Kairui Song            2026-05-17  441  	 * GFP_HIGHUSER_MOVABLE but matters for shmem.
                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Comment here which mentions gfp but is too advanced for my small brain.

e1e6750df3b473 Kairui Song            2026-05-17  442  	 */
e1e6750df3b473 Kairui Song            2026-05-17  443  	if (order)
e1e6750df3b473 Kairui Song            2026-05-17  444  		gfp = thp_shmem_limit_gfp_mask(vma_thp_gfp_mask(vma), gfp);
e1e6750df3b473 Kairui Song            2026-05-17  445  
e1e6750df3b473 Kairui Song            2026-05-17  446  	if (mpol || !vmf) {
e1e6750df3b473 Kairui Song            2026-05-17  447  		folio = folio_alloc_mpol(gfp, order, mpol, ilx, numa_node_id());
e1e6750df3b473 Kairui Song            2026-05-17  448  	} else {
e1e6750df3b473 Kairui Song            2026-05-17  449  		address = round_down(vmf->address, PAGE_SIZE << order);
e1e6750df3b473 Kairui Song            2026-05-17  450  		folio = vma_alloc_folio(gfp, order, vmf->vma, address);
e1e6750df3b473 Kairui Song            2026-05-17  451  	}
e1e6750df3b473 Kairui Song            2026-05-17  452  	if (unlikely(!folio))
e1e6750df3b473 Kairui Song            2026-05-17  453  		return ERR_PTR(-ENOMEM);
e1e6750df3b473 Kairui Song            2026-05-17  454  
e1e6750df3b473 Kairui Song            2026-05-17  455  	/* Double check the range is still not in conflict */
e1e6750df3b473 Kairui Song            2026-05-17  456  	spin_lock(&ci->lock);
bc34e87a51d9e5 Kairui Song            2026-05-17  457  	err = __swap_cache_add_check(ci, targ_entry, nr_pages, &shadow, &memcg_id);
e1e6750df3b473 Kairui Song            2026-05-17  458  	if (unlikely(err)) {
e1e6750df3b473 Kairui Song            2026-05-17  459  		spin_unlock(&ci->lock);
e1e6750df3b473 Kairui Song            2026-05-17  460  		folio_put(folio);
e1e6750df3b473 Kairui Song            2026-05-17  461  		return ERR_PTR(err);
e1e6750df3b473 Kairui Song            2026-05-17  462  	}
e1e6750df3b473 Kairui Song            2026-05-17  463  
e1e6750df3b473 Kairui Song            2026-05-17  464  	__folio_set_locked(folio);
e1e6750df3b473 Kairui Song            2026-05-17  465  	__folio_set_swapbacked(folio);
e1e6750df3b473 Kairui Song            2026-05-17  466  	__swap_cache_do_add_folio(ci, folio, entry);
e1e6750df3b473 Kairui Song            2026-05-17  467  	spin_unlock(&ci->lock);
e1e6750df3b473 Kairui Song            2026-05-17  468  
bc34e87a51d9e5 Kairui Song            2026-05-17  469  	if (mem_cgroup_swapin_charge_folio(folio, memcg_id,
bc34e87a51d9e5 Kairui Song            2026-05-17  470  					   vmf ? vmf->vma->vm_mm : NULL, gfp)) {
e1e6750df3b473 Kairui Song            2026-05-17  471  		spin_lock(&ci->lock);
e1e6750df3b473 Kairui Song            2026-05-17  472  		__swap_cache_do_del_folio(ci, folio, entry, shadow);
e1e6750df3b473 Kairui Song            2026-05-17  473  		spin_unlock(&ci->lock);
e1e6750df3b473 Kairui Song            2026-05-17  474  		folio_unlock(folio);
e1e6750df3b473 Kairui Song            2026-05-17  475  		/* nr_pages refs from swap cache, 1 from allocation */
e1e6750df3b473 Kairui Song            2026-05-17  476  		folio_put_refs(folio, nr_pages + 1);
e1e6750df3b473 Kairui Song            2026-05-17  477  		count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK_CHARGE);
e1e6750df3b473 Kairui Song            2026-05-17  478  		return ERR_PTR(-ENOMEM);
e1e6750df3b473 Kairui Song            2026-05-17  479  	}
e1e6750df3b473 Kairui Song            2026-05-17  480  
1e7fc916472307 Kiryl Shutsemau (Meta  2026-08-24 @481) 	if (order > 1 && folio_memcg_alloc_deferred(folio, GFP_KERNEL)) {

Should this be gfp instead of GFP_KERNEL?

fafaeceb89a5e2 Johannes Weiner        2026-05-27  482  		spin_lock(&ci->lock);
fafaeceb89a5e2 Johannes Weiner        2026-05-27  483  		__swap_cache_do_del_folio(ci, folio, entry, shadow);
fafaeceb89a5e2 Johannes Weiner        2026-05-27  484  		spin_unlock(&ci->lock);
fafaeceb89a5e2 Johannes Weiner        2026-05-27  485  		folio_unlock(folio);
fafaeceb89a5e2 Johannes Weiner        2026-05-27  486  		/* nr_pages refs from swap cache, 1 from allocation */
fafaeceb89a5e2 Johannes Weiner        2026-05-27  487  		folio_put_refs(folio, nr_pages + 1);
fafaeceb89a5e2 Johannes Weiner        2026-05-27  488  		return ERR_PTR(-ENOMEM);
fafaeceb89a5e2 Johannes Weiner        2026-05-27  489  	}
fafaeceb89a5e2 Johannes Weiner        2026-05-27  490  
945578fee2ec17 Kairui Song            2026-05-17  491  	/* memsw uncharges swap when folio is added to swap cache */
945578fee2ec17 Kairui Song            2026-05-17  492  	memcg1_swapin(folio);
e1e6750df3b473 Kairui Song            2026-05-17  493  	if (shadow)
e1e6750df3b473 Kairui Song            2026-05-17  494  		workingset_refault(folio, shadow);
e1e6750df3b473 Kairui Song            2026-05-17  495  
e1e6750df3b473 Kairui Song            2026-05-17  496  	node_stat_mod_folio(folio, NR_FILE_PAGES, nr_pages);
e1e6750df3b473 Kairui Song            2026-05-17  497  	lruvec_stat_mod_folio(folio, NR_SWAPCACHE, nr_pages);
e1e6750df3b473 Kairui Song            2026-05-17  498  
e1e6750df3b473 Kairui Song            2026-05-17  499  	/* Caller will initiate read into locked new_folio */
e1e6750df3b473 Kairui Song            2026-05-17  500  	folio_add_lru(folio);
e1e6750df3b473 Kairui Song            2026-05-17  501  	return folio;
e1e6750df3b473 Kairui Song            2026-05-17  502  }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki