On architectures where !SWAP_TABLE_HAS_ZEROFLAG is true, the swap layer allocates a separate bitmap to track zero-filled pages within a swap cluster. If a swap device is activated with the SWAP_FLAG_SKIP_ZERO_CHECK flag, the swap layer no longer checks or tracks zero-filled pages for that specific device. Therefore, allocating the zero_bitmap is unnecessary. Signed-off-by: Youngjun Park --- mm/swapfile.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 35cc33698b78..232cc5f9e06e 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -446,7 +446,8 @@ static void swap_cluster_free_table(struct swap_cluster_info *ci) swap_cluster_free_table_folio_rcu_cb); } -static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp) +static int swap_cluster_alloc_table(struct swap_info_struct *si, + struct swap_cluster_info *ci, gfp_t gfp) { struct swap_table *table = NULL; struct folio *folio; @@ -479,6 +480,8 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp) #endif #if !SWAP_TABLE_HAS_ZEROFLAG + if (si->flags & SWP_SKIP_ZERO_CHECK) + return 0; VM_WARN_ON_ONCE(ci->zero_bitmap); ci->zero_bitmap = bitmap_zalloc(SWAPFILE_CLUSTER, gfp); if (!ci->zero_bitmap) @@ -539,7 +542,7 @@ swap_cluster_populate(struct swap_info_struct *si, lockdep_assert_held(&si->global_cluster_lock); lockdep_assert_held(&ci->lock); - if (!swap_cluster_alloc_table(ci, __GFP_HIGH | __GFP_NOMEMALLOC | + if (!swap_cluster_alloc_table(si, ci, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN)) return ci; @@ -553,7 +556,7 @@ swap_cluster_populate(struct swap_info_struct *si, spin_unlock(&si->global_cluster_lock); local_unlock(&percpu_swap_cluster.lock); - ret = swap_cluster_alloc_table(ci, __GFP_HIGH | __GFP_NOMEMALLOC | + ret = swap_cluster_alloc_table(si, ci, __GFP_HIGH | __GFP_NOMEMALLOC | GFP_KERNEL); /* @@ -813,7 +816,7 @@ static int swap_cluster_setup_bad_slot(struct swap_info_struct *si, ci = cluster_info + idx; /* Need to allocate swap table first for initial bad slot marking. */ - if (!ci->count && swap_cluster_alloc_table(ci, GFP_KERNEL)) + if (!ci->count && swap_cluster_alloc_table(si, ci, GFP_KERNEL)) return -ENOMEM; spin_lock(&ci->lock); /* Check for duplicated bad swap slots. */ -- 2.34.1