From: Baoquan He The physical range backing a large xswap folio has no folio of its own. Teach the exclusive allocation path to initialise every slot in the range instead of only the first. Existing callers are still order 0. Signed-off-by: Baoquan He --- mm/swapfile.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 195fdc879311..0e4b468ad87b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1173,6 +1173,7 @@ static bool __swap_cluster_alloc_entries(struct swap_info_struct *si, unsigned int ci_off, unsigned int order) { unsigned long nr_pages = 1UL << order; + unsigned long i; lockdep_assert_held(&ci->lock); @@ -1181,29 +1182,23 @@ static bool __swap_cluster_alloc_entries(struct swap_info_struct *si, /* * All mm swap allocation starts with a folio (folio_alloc_swap), - * it's also the only allocation path for large orders allocation. - * Such swap slots starts with count == 0 and will be increased - * upon folio unmap. + * it's also the allocation path for large orders. Such swap slots + * starts with count == 0 and will be increased upon folio unmap. * - * Else, it's an exclusive order 0 allocation for a slot that has - * no folio of its own: hibernation, and the physical slot that - * backs an xswap entry. The slot carries no swap count and is - * freed by its owner. + * Else, it's an exclusive allocation for a range of slots that has no + * folio of its own: hibernation, and the range that backs an xswap + * folio. The slots carry no swap count and are freed by their owner. */ + swap_cluster_assert_empty(ci, ci_off, nr_pages, false); if (likely(folio)) { - swap_cluster_assert_empty(ci, ci_off, nr_pages, false); __swap_cache_add_folio(ci, folio, swp_entry(si->type, ci_off + cluster_offset(si, ci))); } else { - swap_cluster_assert_empty(ci, ci_off, 1, false); /* Owned by hibernation or the xswap backend; never cached. */ - __swap_table_set(ci, ci_off, SWP_TB_HIB); + for (i = 0; i < nr_pages; i++) + __swap_table_set(ci, ci_off + i, SWP_TB_HIB); } - /* - * The first allocation in a cluster makes the - * cluster exclusive to this order - */ if (cluster_is_empty(ci)) ci->order = order; ci->count += nr_pages; @@ -1256,8 +1251,7 @@ static unsigned long alloc_swap_scan_cluster(struct swap_info_struct *si, if (!ret) continue; } - if (!__swap_cluster_alloc_entries(si, ci, folio, - offset % SWAPFILE_CLUSTER, order)) + if (!__swap_cluster_alloc_entries(si, ci, folio, offset % SWAPFILE_CLUSTER, order)) break; found = offset; offset += nr_pages; -- 2.54.0