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

Configure Feed

Select the types of activity you want to include in your feed.

mm, swap: remove redundant arguments and locking for enabling a device

There is no need to repeatedly pass zero map and priority values. zeromap
is similar to cluster info and swap_map, which are only used once the swap
device is exposed. And the prio values are currently read only once set,
and only used for the list insertion upon expose or swap info display.

Link: https://lkml.kernel.org/r/20260218-swap-table-p3-v3-3-f4e34be021a7@tencent.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: kernel test robot <lkp@intel.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
50f8c419 451c6326

+18 -30
+18 -30
mm/swapfile.c
··· 2663 2663 return generic_swapfile_activate(sis, swap_file, span); 2664 2664 } 2665 2665 2666 - static void setup_swap_info(struct swap_info_struct *si, int prio, 2667 - unsigned long *zeromap) 2668 - { 2669 - si->prio = prio; 2670 - /* 2671 - * the plist prio is negated because plist ordering is 2672 - * low-to-high, while swap ordering is high-to-low 2673 - */ 2674 - si->list.prio = -si->prio; 2675 - si->avail_list.prio = -si->prio; 2676 - si->zeromap = zeromap; 2677 - } 2678 - 2679 2666 static void _enable_swap_info(struct swap_info_struct *si) 2680 2667 { 2681 2668 atomic_long_add(si->pages, &nr_swap_pages); ··· 2676 2689 add_to_avail_list(si, true); 2677 2690 } 2678 2691 2679 - static void enable_swap_info(struct swap_info_struct *si, int prio, 2680 - unsigned long *zeromap) 2692 + /* 2693 + * Called after the swap device is ready, resurrect its percpu ref, it's now 2694 + * safe to reference it. Add it to the list to expose it to the allocator. 2695 + */ 2696 + static void enable_swap_info(struct swap_info_struct *si) 2681 2697 { 2682 - spin_lock(&swap_lock); 2683 - spin_lock(&si->lock); 2684 - setup_swap_info(si, prio, zeromap); 2685 - spin_unlock(&si->lock); 2686 - spin_unlock(&swap_lock); 2687 - /* 2688 - * Finished initializing swap device, now it's safe to reference it. 2689 - */ 2690 2698 percpu_ref_resurrect(&si->users); 2691 2699 spin_lock(&swap_lock); 2692 2700 spin_lock(&si->lock); ··· 2694 2712 { 2695 2713 spin_lock(&swap_lock); 2696 2714 spin_lock(&si->lock); 2697 - setup_swap_info(si, si->prio, si->zeromap); 2698 2715 _enable_swap_info(si); 2699 2716 spin_unlock(&si->lock); 2700 2717 spin_unlock(&swap_lock); ··· 3337 3356 int nr_extents; 3338 3357 sector_t span; 3339 3358 unsigned long maxpages; 3340 - unsigned long *zeromap = NULL; 3341 3359 struct folio *folio = NULL; 3342 3360 struct inode *inode = NULL; 3343 3361 bool inced_nr_rotate_swap = false; ··· 3447 3467 * Use kvmalloc_array instead of bitmap_zalloc as the allocation order might 3448 3468 * be above MAX_PAGE_ORDER incase of a large swap file. 3449 3469 */ 3450 - zeromap = kvmalloc_array(BITS_TO_LONGS(maxpages), sizeof(long), 3451 - GFP_KERNEL | __GFP_ZERO); 3452 - if (!zeromap) { 3470 + si->zeromap = kvmalloc_array(BITS_TO_LONGS(maxpages), sizeof(long), 3471 + GFP_KERNEL | __GFP_ZERO); 3472 + if (!si->zeromap) { 3453 3473 error = -ENOMEM; 3454 3474 goto bad_swap_unlock_inode; 3455 3475 } ··· 3518 3538 if (swap_flags & SWAP_FLAG_PREFER) 3519 3539 prio = swap_flags & SWAP_FLAG_PRIO_MASK; 3520 3540 3541 + /* 3542 + * The plist prio is negated because plist ordering is 3543 + * low-to-high, while swap ordering is high-to-low 3544 + */ 3545 + si->prio = prio; 3546 + si->list.prio = -si->prio; 3547 + si->avail_list.prio = -si->prio; 3521 3548 si->swap_file = swap_file; 3522 3549 3523 3550 /* Sets SWP_WRITEOK, resurrect the percpu ref, expose the swap device */ 3524 - enable_swap_info(si, prio, zeromap); 3551 + enable_swap_info(si); 3525 3552 3526 3553 pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s\n", 3527 3554 K(si->pages), name->name, si->prio, nr_extents, ··· 3558 3571 si->swap_map = NULL; 3559 3572 free_swap_cluster_info(si->cluster_info, si->max); 3560 3573 si->cluster_info = NULL; 3574 + kvfree(si->zeromap); 3575 + si->zeromap = NULL; 3561 3576 /* 3562 3577 * Clear the SWP_USED flag after all resources are freed so 3563 3578 * alloc_swap_info can reuse this si safely. ··· 3567 3578 spin_lock(&swap_lock); 3568 3579 si->flags = 0; 3569 3580 spin_unlock(&swap_lock); 3570 - kvfree(zeromap); 3571 3581 if (inced_nr_rotate_swap) 3572 3582 atomic_dec(&nr_rotate_swap); 3573 3583 if (swap_file)