mm/slab: add is_kmalloc_cache() helper macro
Subsystems (3)
PATCH 1/2 mm/slab: add is_kmalloc_cache() helper macro
commit 6edf2576a6cc ("mm/slub: enable debugging memory wasting of kmalloc") introduces 'SLAB_KMALLOC' bit specifying whether a kmem_cache is a kmalloc cache for slab/slub (slob doesn't have dedicated kmalloc caches).
Add a helper macro for other components like kasan to simplify code.
--- include/linux/slab.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/slab.h +6 -0
@@ -758,6 +758,12 @@ extern void kvfree_sensitive(const void *addr, size_t len);unsigned int kmem_cache_size (struct kmem_cache *s); +#ifndef CONFIG_SLOB +#define is_kmalloc_cache (s) ((s)->flags & SLAB_KMALLOC) +#else +#define is_kmalloc_cache (s) (false) +#endif +/** * kmalloc_size_roundup - Report allocation bucket size for the given size *
Signature · 1 line
2.34.1
PATCH 2/2 mm/kasan: simplify is_kmalloc check
Use new is_kmalloc_cache() to simplify the code of checking whether a kmem_cache is a kmalloc cache.
--- include/linux/kasan.h | 9 --------- mm/kasan/common.c | 9 ++------- mm/slab_common.c | 1 - 3 files changed, 2 insertions(+), 17 deletions(-)
include/linux/kasan.h +0 -9
@@ -102,7 +102,6 @@ struct kasan_cache {int alloc_meta_offset;int free_meta_offset;#endif -bool is_kmalloc; };void __kasan_unpoison_range (const void *addr,size_t size);
@@ -129,13 +128,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page,return false; } -void __kasan_cache_create_kmalloc (struct kmem_cache *cache); -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) -{ -if (kasan_enabled ()) -__kasan_cache_create_kmalloc (cache); -} -void __kasan_poison_slab (struct slab *slab); static __always_inline void kasan_poison_slab(struct slab *slab) {
@@ -252,7 +244,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order, bool init) {}static inline bool kasan_unpoison_pages (struct page *page,unsigned int order,bool init) {return false; } -static inline void kasan_cache_create_kmalloc (struct kmem_cache *cache) {}static inline void kasan_poison_slab (struct slab *slab) {}static inline void kasan_unpoison_object_data (struct kmem_cache *cache,void *object) {}
mm/kasan/common.c +2 -7
@@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init) KASAN_PAGE_FREE, init); } -void __kasan_cache_create_kmalloc (struct kmem_cache *cache) -{ - cache->kasan_info.is_kmalloc = true; -} -void __kasan_poison_slab (struct slab *slab) {struct page *page =slab_page (slab);
@@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache,kasan_unpoison (tagged_object, cache->object_size, init);/* Save alloc info (if possible) for non-kmalloc() allocations. */ -if (kasan_stack_collection_enabled () && !cache->kasan_info.is_kmalloc) +if (kasan_stack_collection_enabled () &&is_kmalloc_cache (cache))kasan_save_alloc_info (cache, tagged_object, flags);return tagged_object;
@@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache,* Save alloc info (if possible) for kmalloc() allocations. * This also rewrites the alloc info when called from kasan_krealloc(). */ -if (kasan_stack_collection_enabled () && cache->kasan_info.is_kmalloc) +if (kasan_stack_collection_enabled () &&is_kmalloc_cache (cache))kasan_save_alloc_info (cache, (void *)object, flags);/* Keep the tag that was set by kasan_slab_alloc(). */
mm/slab_common.c +0 -1
@@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name,create_boot_cache (s, name, size, flags |SLAB_KMALLOC , useroffset, usersize); -kasan_cache_create_kmalloc (s);list_add (&s->list, &slab_caches); s->refcount =1 ;return s;
Signature · 1 line
2.34.1
Re: [PATCH -next 2/2] mm/kasan: simplify is_kmalloc check
Quoted 61 lines · Feng
Use new
is_kmalloc_cache()to simplify the code of checking whether akmem_cacheis a kmalloc cache.Signed-off-by Feng Tang <[email protected]>--- include/linux/kasan.h | 9 --------- mm/kasan/common.c | 9 ++------- mm/slab_common.c | 1 - 3 files changed, 2 insertions(+), 17 deletions(-)include/linux/kasan.h +0
-9@@ -102,7 +102,6 @@ struct kasan_cache {int alloc_meta_offset;int free_meta_offset;#endif -bool is_kmalloc; };void __kasan_unpoison_range (const void *addr,size_t size);@@ -129,13 +128,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page,return false; } -void __kasan_cache_create_kmalloc (struct kmem_cache *cache); -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) -{ -if (kasan_enabled ()) -__kasan_cache_create_kmalloc (cache); -} -void __kasan_poison_slab (struct slab *slab); static __always_inline void kasan_poison_slab(struct slab *slab) {@@ -252,7 +244,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order, bool init) {}static inline bool kasan_unpoison_pages (struct page *page,unsigned int order,bool init) {return false; } -static inline void kasan_cache_create_kmalloc (struct kmem_cache *cache) {}static inline void kasan_poison_slab (struct slab *slab) {}static inline void kasan_unpoison_object_data (struct kmem_cache *cache,void *object) {}mm/kasan/common.c +0
-5@@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init) KASAN_PAGE_FREE, init); } -void __kasan_cache_create_kmalloc (struct kmem_cache *cache) -{ - cache->kasan_info.is_kmalloc = true; -} -void __kasan_poison_slab (struct slab *slab) {struct page *page =slab_page (slab);
mm/kasan/common.c void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, · line 324
Quoted 5 lines
mm/kasan/common.c +1
-1@@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache,kasan_unpoison (tagged_object, cache->object_size, init);/* Save alloc info (if possible) for non-kmalloc() allocations. */ -if (kasan_stack_collection_enabled () && !cache->kasan_info.is_kmalloc) +if (kasan_stack_collection_enabled () &&is_kmalloc_cache (cache))
Sorry, it should be:
- if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc)
+ if (kasan_stack_collection_enabled() && !is_kmalloc_cache(cache))
Thanks,
Feng
Quoted 27 lines
mm/kasan/common.c +1
-1kasan_save_alloc_info (cache, tagged_object, flags);return tagged_object;@@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache,* Save alloc info (if possible) for kmalloc() allocations. * This also rewrites the alloc info when called from kasan_krealloc(). */ -if (kasan_stack_collection_enabled () && cache->kasan_info.is_kmalloc) +if (kasan_stack_collection_enabled () &&is_kmalloc_cache (cache))kasan_save_alloc_info (cache, (void *)object, flags);/* Keep the tag that was set by kasan_slab_alloc(). */ mm/slab_common.c +0
-1@@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name,create_boot_cache (s, name, size, flags |SLAB_KMALLOC , useroffset, usersize); -kasan_cache_create_kmalloc (s);list_add (&s->list, &slab_caches); s->refcount =1 ;return s;Signature · 1 line
2.34.1
Andrey Konovalov
reviewerRe: [PATCH -next 2/2] mm/kasan: simplify is_kmalloc check
In reply to Feng TangQuoted 5 lines · Feng Tang
Use new
is_kmalloc_cache()to simplify the code of checking whether akmem_cacheis a kmalloc cache.Signed-off-by Feng Tang <[email protected]>
Hi Feng,
Nice simplification!
Quoted 11 lines
--- include/linux/kasan.h | 9 --------- mm/kasan/common.c | 9 ++------- mm/slab_common.c | 1 - 3 files changed, 2 insertions(+), 17 deletions(-)include/linux/kasan.h +0
-0
include/linux/kasan.h struct kasan_cache { · line 105
Quoted 5 lines
include/linux/kasan.h +0
-1@@ -102,7 +102,6 @@ struct kasan_cache {int alloc_meta_offset;int free_meta_offset;#endif -bool is_kmalloc; };
We can go even further here, and only define the kasan_cache struct and add the kasan_info field to kmem_cache when CONFIG_KASAN_GENERIC is enabled.
Quoted 73 lines
include/linux/kasan.h +0
-8void __kasan_unpoison_range (const void *addr,size_t size);@@ -129,13 +128,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page,return false; } -void __kasan_cache_create_kmalloc (struct kmem_cache *cache); -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) -{ -if (kasan_enabled ()) -__kasan_cache_create_kmalloc (cache); -} -void __kasan_poison_slab (struct slab *slab); static __always_inline void kasan_poison_slab(struct slab *slab) {@@ -252,7 +244,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order, bool init) {}static inline bool kasan_unpoison_pages (struct page *page,unsigned int order,bool init) {return false; } -static inline void kasan_cache_create_kmalloc (struct kmem_cache *cache) {}static inline void kasan_poison_slab (struct slab *slab) {}static inline void kasan_unpoison_object_data (struct kmem_cache *cache,void *object) {}mm/kasan/common.c +2
-7@@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init) KASAN_PAGE_FREE, init); } -void __kasan_cache_create_kmalloc (struct kmem_cache *cache) -{ - cache->kasan_info.is_kmalloc = true; -} -void __kasan_poison_slab (struct slab *slab) {struct page *page =slab_page (slab);@@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache,kasan_unpoison (tagged_object, cache->object_size, init);/* Save alloc info (if possible) for non-kmalloc() allocations. */ -if (kasan_stack_collection_enabled () && !cache->kasan_info.is_kmalloc) +if (kasan_stack_collection_enabled () &&is_kmalloc_cache (cache))kasan_save_alloc_info (cache, tagged_object, flags);return tagged_object;@@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache,* Save alloc info (if possible) for kmalloc() allocations. * This also rewrites the alloc info when called from kasan_krealloc(). */ -if (kasan_stack_collection_enabled () && cache->kasan_info.is_kmalloc) +if (kasan_stack_collection_enabled () &&is_kmalloc_cache (cache))kasan_save_alloc_info (cache, (void *)object, flags);/* Keep the tag that was set by kasan_slab_alloc(). */ mm/slab_common.c +0
-2@@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name,create_boot_cache (s, name, size, flags |SLAB_KMALLOC , useroffset, usersize); -kasan_cache_create_kmalloc (s);list_add (&s->list, &slab_caches); s->refcount =1 ;return s; --2.34.1
Re: [PATCH -next 2/2] mm/kasan: simplify is_kmalloc check
Quoted 17 lines · Andrey Konovalov
Quoted 5 lines · Feng Tang
Use new
is_kmalloc_cache()to simplify the code of checking whether akmem_cacheis a kmalloc cache.Signed-off-by Feng Tang <[email protected]>Hi Feng,
Nice simplification!
Quoted 6 lines
--- include/linux/kasan.h | 9 --------- mm/kasan/common.c | 9 ++------- mm/slab_common.c | 1 - 3 files changed, 2 insertions(+), 17 deletions(-)
Quoted 14 lines
include/linux/kasan.h struct kasan_cache { · line 105
Quoted 10 lines
include/linux/kasan.h +0
-1@@ -102,7 +102,6 @@ struct kasan_cache {int alloc_meta_offset;int free_meta_offset;#endif -bool is_kmalloc; };We can go even further here, and only define the
kasan_cachestruct and add thekasan_infofield tokmem_cachewhenCONFIG_KASAN_GENERICis enabled.
Good idea. thanks!
I mainly checked the kasan_cache related code, and make an add-on patch below, please let me know if my understanding is wrong or I missed anything.
Thanks,
Feng
---
include/linux/kasan.h +5 -8
@@ -96,14 +96,6 @@ static inline bool kasan_has_integrated_init(void) }#ifdef CONFIG_KASAN - -struct kasan_cache { -#ifdef CONFIG_KASAN_GENERIC -int alloc_meta_offset; -int free_meta_offset; -#endif -}; -void __kasan_unpoison_range (const void *addr,size_t size); static __always_inline void kasan_unpoison_range(const void *addr, size_t size) {
@@ -293,6 +285,11 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {}#ifdef CONFIG_KASAN_GENERIC +struct kasan_cache { +int alloc_meta_offset; +int free_meta_offset; +}; +size_t kasan_metadata_size (struct kmem_cache *cache,bool in_object);slab_flags_t kasan_never_merge (void ); void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,
include/linux/slab_def.h +1 -1
@@ -72,7 +72,7 @@ struct kmem_cache {int obj_offset;#endif /* CONFIG_DEBUG_SLAB */ -#ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_GENERIC struct kasan_cache kasan_info;#endif
include/linux/slub_def.h +1 -1
@@ -132,7 +132,7 @@ struct kmem_cache {unsigned int *random_seq;#endif -#ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_GENERIC struct kasan_cache kasan_info;#endif
Andrey Konovalov
reviewerRe: [PATCH -next 2/2] mm/kasan: simplify is_kmalloc check
Quoted 93 lines · Feng Tang
Quoted 17 lines · Andrey Konovalov
Quoted 5 lines · Feng Tang
Use new
is_kmalloc_cache()to simplify the code of checking whether akmem_cacheis a kmalloc cache.Signed-off-by Feng Tang <[email protected]>Hi Feng,
Nice simplification!
Quoted 6 lines
--- include/linux/kasan.h | 9 --------- mm/kasan/common.c | 9 ++------- mm/slab_common.c | 1 - 3 files changed, 2 insertions(+), 17 deletions(-)Quoted 14 lines
include/linux/kasan.h struct kasan_cache { · line 105
Quoted 10 lines
include/linux/kasan.h +0
-1@@ -102,7 +102,6 @@ struct kasan_cache {int alloc_meta_offset;int free_meta_offset;#endif -bool is_kmalloc; };We can go even further here, and only define the
kasan_cachestruct and add thekasan_infofield tokmem_cachewhenCONFIG_KASAN_GENERICis enabled.Good idea. thanks!
I mainly checked the
kasan_cacherelated code, and make an add-on patch below, please let me know if my understanding is wrong or I missed anything.Thanks,
Feng---
include/linux/kasan.h +5
-8@@ -96,14 +96,6 @@ static inline bool kasan_has_integrated_init(void) }#ifdef CONFIG_KASAN - -struct kasan_cache { -#ifdef CONFIG_KASAN_GENERIC -int alloc_meta_offset; -int free_meta_offset; -#endif -}; -void __kasan_unpoison_range (const void *addr,size_t size); static __always_inline void kasan_unpoison_range(const void *addr, size_t size) {@@ -293,6 +285,11 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {}#ifdef CONFIG_KASAN_GENERIC +struct kasan_cache { +int alloc_meta_offset; +int free_meta_offset; +}; +size_t kasan_metadata_size (struct kmem_cache *cache,bool in_object);slab_flags_t kasan_never_merge (void ); void kasan_cache_create(struct kmem_cache *cache, unsigned int *size,include/linux/slab_def.h +1
-1@@ -72,7 +72,7 @@ struct kmem_cache {int obj_offset;#endif /* CONFIG_DEBUG_SLAB */ -#ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_GENERIC struct kasan_cache kasan_info;#endif include/linux/slub_def.h +0
-0
include/linux/slub_def.h struct kmem_cache { · line 137
Quoted 7 lines
include/linux/slub_def.h +1
-1@@ -132,7 +132,7 @@ struct kmem_cache {unsigned int *random_seq;#endif -#ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_GENERIC struct kasan_cache kasan_info;#endif
Yes, this looks good.
Please resend as a v2 and I'll give a Reviewed-by.
Thanks!
Andrew Morton
maintainerinclude/linux/slab.h extern void kvfree_sensitive(const void *addr, size_t len); · line 765
Quoted 5 lines · On Mon, 21 Nov 2022 21:50:23 +0800 Feng Tang <[email protected]> wrote:
include/linux/slab.h +5
-0+#ifndef CONFIG_SLOB +#define is_kmalloc_cache (s) ((s)->flags & SLAB_KMALLOC) +#else +#define is_kmalloc_cache (s) (false) +#endif
Could be implemented as a static inline C function, yes?
If so, that's always best. For (silly) example, consider the behaviour of
x = is_kmalloc_cache(s++);
with and without CONFIG_SLOB.
Quoted 9 lines · Andrew Morton
Review
Quoted 5 lines · On Mon, 21 Nov 2022 21:50:23 +0800 Feng Tang <[email protected]> wrote:
(quoted diff) +5
-0+#ifndef CONFIG_SLOB +#define is_kmalloc_cache(s) ((s)->flags & SLAB_KMALLOC) +#else +#define is_kmalloc_cache(s) (false) +#endifCould be implemented as a static inline C function, yes?
Right, I also did try inline function first, and met compilation error:
"./include/linux/slab.h: In function ‘is_kmalloc_cache’:./include/linux/slab.h:159:18: error: invalid use of undefined type ‘struct kmem_cache’
159 | return (s->flags & SLAB_KMALLOC);
| ^~
"
The reason is 'struct kmem_cache' definition for slab/slub/slob sit separately in slab_def.h, slub_def.h and mm/slab.h, and they are not included in this 'include/linux/slab.h'. So I chose the macro way.
Btw, I've worked on some patches related with sl[auo]b recently, and really felt the pain when dealing with 3 allocators, on both reading code and writing patches. And I really like the idea of fading away SLOB as the first step :)
Quoted 6 lines
If so, that's always best. For (silly) example, consider the behaviour of
x = is_kmalloc_cache(s++);with and without
CONFIG_SLOB.
Another solution I can think of is putting the implementation into slab_common.c, like the below?
Thanks,
Feng
---
include/linux/slab.h +10 -0
@@ -149,6 +149,17 @@struct list_lru ;struct mem_cgroup ; + +#ifndef CONFIG_SLOB +extern bool is_kmalloc_cache (struct kmem_cache *s); +#else +static inline bool is_kmalloc_cache (struct kmem_cache *s) +{ +return false; +} +#endif +/* * struct kmem_cache related prototypes */
mm/slab_common.c +7 -0
@@ -77,6 +77,13 @@ __setup_param("slub_merge", slub_merge, setup_slab_merge, 0);__setup ("slab_nomerge" , setup_slab_nomerge);__setup ("slab_merge" , setup_slab_merge); +#ifndef CONFIG_SLOB +bool is_kmalloc_cache (struct kmem_cache *s) +{ +return (s->flags &SLAB_KMALLOC ); +} +#endif +/* * Determine the size of a slab object */
Andrew Morton
maintainerQuoted 9 lines · On Tue, 22 Nov 2022 13:30:19 +0800 Feng Tang <[email protected]> wrote:
Quoted 6 lines
If so, that's always best. For (silly) example, consider the behaviour of
x = is_kmalloc_cache(s++);with and without
CONFIG_SLOB.Another solution I can think of is putting the implementation into
slab_common.c, like the below?
I'm not sure that's much of an improvement on the macro :(
How about we go with the macro and avoid the expression-with-side-effects gotcha (and the potential CONFIG_SLOB=n unused-variable gotcha)? That would involve evaluating the arg within the CONFIG_SLOB=y version of the macro.
Quoted 20 lines · Feng Tang
Quoted 9 lines · Andrew Morton
include/linux/slab.h line 160
Quoted 5 lines · On Mon, 21 Nov 2022 21:50:23 +0800 Feng Tang <[email protected]> wrote:
include/linux/slab.h +5
-0+#ifndef CONFIG_SLOB +#define is_kmalloc_cache (s) ((s)->flags & SLAB_KMALLOC) +#else +#define is_kmalloc_cache (s) (false) +#endif Could be implemented as a static inline C function, yes?
Right, I also did try inline function first, and met compilation error:
"
./include/linux/slab.h: In function ‘is_kmalloc_cache’:./include/linux/slab.h:159:18: error: invalid use of undefined type ‘struct kmem_cache’
159 | return (s->flags&SLAB_KMALLOC);
| ^~
"
Quoted 3 lines
The reason is 'struct
kmem_cache' definition for slab/slub/slob sit separately inslab_def.h,slub_def.handmm/slab.h, and they are not included in this 'include/linux/slab.h'. So I chose the macro way.
You could try mm/slab.h instead, below the slub_def.h includes there. is_kmalloc_cache(s) shouldn't have random consumers in the kernel anyway. It's fine if kasan includes it, as it's intertwined with slab a lot anyway.
Quoted 4 lines
Btw, I've worked on some patches related with sl[auo]b recently, and really felt the pain when dealing with 3 allocators, on both reading code and writing patches. And I really like the idea of fading away SLOB as the first step :)
Can't agree more :)
Quoted 9 lines
Quoted 6 lines
If so, that's always best. For (silly) example, consider the behaviour of
x = is_kmalloc_cache(s++);with and without
CONFIG_SLOB.Another solution I can think of is putting the implementation into
slab_common.c, like the below?
The overhead of function call between compilation units (sans LTO) is not worth it.
Quoted 43 lines
Thanks,
Feng---
include/linux/slab.h +10
-0@@ -149,6 +149,17 @@struct list_lru ;struct mem_cgroup ; + +#ifndef CONFIG_SLOB +extern bool is_kmalloc_cache (struct kmem_cache *s); +#else +static inline bool is_kmalloc_cache (struct kmem_cache *s) +{ +return false; +} +#endif +/* * struct kmem_cache related prototypes */ mm/slab_common.c +7
-0@@ -77,6 +77,13 @@ __setup_param("slub_merge", slub_merge, setup_slab_merge, 0);__setup ("slab_nomerge" , setup_slab_nomerge);__setup ("slab_merge" , setup_slab_merge); +#ifndef CONFIG_SLOB +bool is_kmalloc_cache (struct kmem_cache *s) +{ +return (s->flags &SLAB_KMALLOC ); +} +#endif +/* * Determine the size of a slab object */
Quoted 21 lines · Vlastimil Babka
Quoted 20 lines · Feng Tang
Quoted 9 lines · Andrew Morton
include/linux/slab.h line 160
Quoted 5 lines · On Mon, 21 Nov 2022 21:50:23 +0800 Feng Tang <[email protected]> wrote:
include/linux/slab.h +5
-0+#ifndef CONFIG_SLOB +#define is_kmalloc_cache (s) ((s)->flags & SLAB_KMALLOC) +#else +#define is_kmalloc_cache (s) (false) +#endif Could be implemented as a static inline C function, yes?
Right, I also did try inline function first, and met compilation error:
"
./include/linux/slab.h: In function ‘is_kmalloc_cache’:./include/linux/slab.h:159:18: error: invalid use of undefined type ‘struct kmem_cache’
159 | return (s->flags&SLAB_KMALLOC);
| ^~
"
Quoted 7 lines
Quoted 3 lines
The reason is 'struct
kmem_cache' definition for slab/slub/slob sit separately inslab_def.h,slub_def.handmm/slab.h, and they are not included in this 'include/linux/slab.h'. So I chose the macro way.You could try
mm/slab.hinstead, below theslub_def.hincludes there.is_kmalloc_cache(s)shouldn't have random consumers in the kernel anyway. It's fine if kasan includes it, as it's intertwined with slab a lot anyway.
Good suggestion! thanks! This can address Andrew's concern and also avoid extra cost.
And yes, besides sanity code like kasan/kfence, rare code will care whether other kmem_cache is a kmalloc cache or not. And kasan code already includes "../slab.h".
Quoted 12 lines
Quoted 4 lines
Btw, I've worked on some patches related with sl[auo]b recently, and really felt the pain when dealing with 3 allocators, on both reading code and writing patches. And I really like the idea of fading away SLOB as the first step :)
Can't agree more :)
Quoted 5 lines
Quoted 5 lines
If so, that's always best. For (silly) example, consider the behaviour of
x = is_kmalloc_cache(s++);
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
with and without
CONFIG_SLOB.Another solution I can think of is putting the implementation into
slab_common.c, like the below?The overhead of function call between compilation units (sans LTO) is not worth it.
Yes. Will send out the v2 patches.
Thanks,
Feng