diff mbox series

[v4,06/32] mm: Convert virt_to_cache() to use struct slab

Message ID 20220104001046.12263-7-vbabka@suse.cz (mailing list archive)
State New
Headers show
Series Separate struct slab from struct page | expand

Commit Message

Vlastimil Babka Jan. 4, 2022, 12:10 a.m. UTC
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>

This function is entirely self-contained, so can be converted from page
to slab.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Roman Gushchin <guro@fb.com>
---
 mm/slab.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Hyeonggon Yoo Jan. 6, 2022, 6:44 a.m. UTC | #1
On Tue, Jan 04, 2022 at 01:10:20AM +0100, Vlastimil Babka wrote:
> From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> 
> This function is entirely self-contained, so can be converted from page
> to slab.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Reviewed-by: Roman Gushchin <guro@fb.com>
> ---
>  mm/slab.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/slab.h b/mm/slab.h
> index dd3f72fddff6..1408ada9ff72 100644
> --- a/mm/slab.h
> +++ b/mm/slab.h
> @@ -574,13 +574,13 @@ static inline void memcg_slab_free_hook(struct kmem_cache *s,
>  
>  static inline struct kmem_cache *virt_to_cache(const void *obj)
>  {
> -	struct page *page;
> +	struct slab *slab;
>  
> -	page = virt_to_head_page(obj);
> -	if (WARN_ONCE(!PageSlab(page), "%s: Object is not a Slab page!\n",
> +	slab = virt_to_slab(obj);
> +	if (WARN_ONCE(!slab, "%s: Object is not a Slab page!\n",
>  					__func__))
>  		return NULL;
> -	return page->slab_cache;
> +	return slab->slab_cache;
>  }
>  

Looks good,
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>

>  static __always_inline void account_slab(struct slab *slab, int order,
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/mm/slab.h b/mm/slab.h
index dd3f72fddff6..1408ada9ff72 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -574,13 +574,13 @@  static inline void memcg_slab_free_hook(struct kmem_cache *s,
 
 static inline struct kmem_cache *virt_to_cache(const void *obj)
 {
-	struct page *page;
+	struct slab *slab;
 
-	page = virt_to_head_page(obj);
-	if (WARN_ONCE(!PageSlab(page), "%s: Object is not a Slab page!\n",
+	slab = virt_to_slab(obj);
+	if (WARN_ONCE(!slab, "%s: Object is not a Slab page!\n",
 					__func__))
 		return NULL;
-	return page->slab_cache;
+	return slab->slab_cache;
 }
 
 static __always_inline void account_slab(struct slab *slab, int order,