Re: [PATCH] mm: Introduce free_folio_and_swap_cache() to replace free_page_and_swap_cache()

From: Matthew Wilcox
Date: Thu Apr 10 2025 - 14:11:39 EST


On Thu, Apr 10, 2025 at 11:00:31AM -0700, nifan.cxl@xxxxxxxxx wrote:
> @@ -522,8 +522,12 @@ static inline void put_swap_device(struct swap_info_struct *si)
> do { (val)->freeswap = (val)->totalswap = 0; } while (0)
> /* only sparc can not include linux/pagemap.h in this file
> * so leave put_page and release_pages undeclared... */
> -#define free_page_and_swap_cache(page) \
> - put_page(page)
> +#define free_folio_and_swap_cache(folio) \
> + do { \
> + if (!folio_test_slab(folio)) \
> + folio_put(folio); \
> + } while (0)

We don't need to test for slab. Unlike put_page(), we know that slab
cannot be passed this way.