# Re: \[PATCH v2 22/33\] mm: Convert struct page to struct slab in functions used by other subsystems

- From: Johannes Weiner \<hidden\>
- Date: 2021-12-14 14:31:50 
- List: cgroups
- Page: https://ratatoskr.run/cgroups/2021/12/6512921
- Thread: https://ratatoskr.run/linux-mm/2021/12/6512664/t.md

```text
On Wed, Dec 01, 2021 at 07:14:59PM +0100, Vlastimil Babka wrote:
> KASAN, KFENCE and memcg interact with SLAB or SLUB internals through functions
> nearest_obj(), obj_to_index() and objs_per_slab() that use struct page as
> parameter. This patch converts it to struct slab including all callers, through
> a coccinelle semantic patch.
> 
> // Options: --include-headers --no-includes --smpl-spacing include/linux/slab_def.h include/linux/slub_def.h mm/slab.h mm/kasan/*.c mm/kfence/kfence_test.c mm/memcontrol.c mm/slab.c mm/slub.c
> // Note: needs coccinelle 1.1.1 to avoid breaking whitespace
> 
> @@
> @@
> 
> -objs_per_slab_page(
> +objs_per_slab(
>  ...
>  )
>  { ... }
> 
> @@
> @@
> 
> -objs_per_slab_page(
> +objs_per_slab(
>  ...
>  )
> 
> @@
> identifier fn =~ "obj_to_index|objs_per_slab";
> @@
> 
>  fn(...,
> -   const struct page *page
> +   const struct slab *slab
>     ,...)
>  {
> <...
> (
> - page_address(page)
> + slab_address(slab)
> |
> - page
> + slab
> )
> ...>
>  }
> 
> @@
> identifier fn =~ "nearest_obj";
> @@
> 
>  fn(...,
> -   struct page *page
> +   const struct slab *slab
>     ,...)
>  {
> <...
> (
> - page_address(page)
> + slab_address(slab)
> |
> - page
> + slab
> )
> ...>
>  }
> 
> @@
> identifier fn =~ "nearest_obj|obj_to_index|objs_per_slab";
> expression E;
> @@
> 
>  fn(...,
> (
> - slab_page(E)
> + E
> |
> - virt_to_page(E)
> + virt_to_slab(E)
> |
> - virt_to_head_page(E)
> + virt_to_slab(E)
> |
> - page
> + page_slab(page)
> )
>   ,...)
> 
> Signed-off-by: Vlastimil Babka <redacted>
> Cc: Julia Lawall <redacted>
> Cc: Luis Chamberlain <redacted>
> Cc: Andrey Ryabinin <redacted>
> Cc: Alexander Potapenko <redacted>
> Cc: Andrey Konovalov <redacted>
> Cc: Dmitry Vyukov <redacted>
> Cc: Marco Elver <redacted>
> Cc: Johannes Weiner <redacted>
> Cc: Michal Hocko <redacted>
> Cc: Vladimir Davydov <redacted>
> Cc: <redacted>
> Cc: <redacted>

LGTM.

Acked-by: Johannes Weiner <redacted>
```
