Re: [PATCH 04/10] slab: Add SL_pfmemalloc flag

Harry Yoo
2025-06-09T02:28:03Z

On Fri, Jun 06, 2025 at 11:22:06PM +0100, Matthew Wilcox (Oracle) wrote:
> Give slab its own name for this flag. Move the implementation from
> slab.h to slub.c since it's only used inside slub.c.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---

Acked-by: Harry Yoo <harry.yoo@oracle.com>

--
Cheers,
Harry / Hyeonggon

> mm/slab.h | 26 ++------------------------
> mm/slub.c | 19 +++++++++++++++++++
> 2 files changed, 21 insertions(+), 24 deletions(-)
>
> diff --git a/mm/slab.h b/mm/slab.h
> index fca818011f7d..aa991b1b059d 100644
> --- a/mm/slab.h
> +++ b/mm/slab.h
> @@ -117,6 +117,7 @@ static_assert(IS_ALIGNED(offsetof(struct slab, freelist), sizeof(freelist_aba_t)
> * enum slab_flags - How the slab flags bits are used.
> * @SL_locked: Is locked with slab_lock()
> * @SL_partial: On the per-node partial list
> + * @SL_pfmemalloc: Was allocated from PF_MEMALLOC reserves
> *
> * The slab flags share space with the page flags but some bits have
> * different interpretations. The high bits are used for information
> @@ -125,6 +126,7 @@ static_assert(IS_ALIGNED(offsetof(struct slab, freelist), sizeof(freelist_aba_t)
> enum slab_flags {
> SL_locked,
> SL_partial = PG_workingset, /* Historical reasons for this bit */
> + SL_pfmemalloc = PG_active, /* Historical reasons for this bit */
> };
>
> /**
> @@ -181,30 +183,6 @@ enum slab_flags {
> */
> #define slab_page(s) folio_page(slab_folio(s), 0)
>
> -/*
> - * If network-based swap is enabled, sl*b must keep track of whether pages
> - * were allocated from pfmemalloc reserves.
> - */
> -static inline bool slab_test_pfmemalloc(const struct slab *slab)
> -{
> - return folio_test_active(slab_folio(slab));
> -}
> -
> -static inline void slab_set_pfmemalloc(struct slab *slab)
> -{
> - folio_set_active(slab_folio(slab));
> -}
> -
> -static inline void slab_clear_pfmemalloc(struct slab *slab)
> -{
> - folio_clear_active(slab_folio(slab));
> -}
> -
> -static inline void __slab_clear_pfmemalloc(struct slab *slab)
> -{
> - __folio_clear_active(slab_folio(slab));
> -}
> -
> static inline void *slab_address(const struct slab *slab)
> {
> return folio_address(slab_folio(slab));
> diff --git a/mm/slub.c b/mm/slub.c
> index 804b39d06fa0..bbd96431a50a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -634,6 +634,25 @@ static inline unsigned int slub_get_cpu_partial(struct kmem_cache *s)
> }
> #endif /* CONFIG_SLUB_CPU_PARTIAL */
>
> +/*
> + * If network-based swap is enabled, slub must keep track of whether memory
> + * were allocated from pfmemalloc reserves.
> + */
> +static inline bool slab_test_pfmemalloc(const struct slab *slab)
> +{
> + return test_bit(SL_pfmemalloc, &slab->flags);
> +}
> +
> +static inline void slab_set_pfmemalloc(struct slab *slab)
> +{
> + set_bit(SL_pfmemalloc, &slab->flags);
> +}
> +
> +static inline void __slab_clear_pfmemalloc(struct slab *slab)
> +{
> + __clear_bit(SL_pfmemalloc, &slab->flags);
> +}
> +
> /*
> * Per slab locking using the pagelock
> */
> --
> 2.47.2
>
>