Skip to contentSkip to conversation

mm: slab: comment __GFP_ZERO case for kmem_cache_alloc

PATCH Superseded Alexander Aring 3 participants 3 messages Oct 8, 2022 – Oct 10, 2022 Memory management

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: slab: comment __GFP_ZERO case for kmem_cache_alloc

This patch will add a comment for the __GFP_ZERO flag case for kmem_cache_alloc(). As the current comment mentioned that the flags only matters if the cache has no available objects it's different for the __GFP_ZERO flag which will ensure that the returned object is always zeroed in any case.

I have the feeling I run into this question already two times if the user need to zero the object or not, but the user does not need to zero the object afterwards. However another use of __GFP_ZERO and only zero the object if the cache has no available objects would also make no sense.

---
 mm/slab.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/slab.c +2 -1
index 10e96137b44f..7a84c2aae85a 100644
@@ -3482,7 +3482,8 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
  * @flags: See kmalloc().
  *
  * Allocate an object from this cache.  The flags are only relevant
- * if the cache has no available objects.
+ * if the cache has no available objects. Except flag __GFP_ZERO which
+ * will zero the returned object.
  *
  * Return: pointer to the new object or %NULL in case of error
  */
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#1 lore raw
Quoted 34 lines · Alexander Aring

This patch will add a comment for the __GFP_ZERO flag case for kmem_cache_alloc(). As the current comment mentioned that the flags only matters if the cache has no available objects it's different for the __GFP_ZERO flag which will ensure that the returned object is always zeroed in any case.

I have the feeling I run into this question already two times if the user need to zero the object or not, but the user does not need to zero the object afterwards. However another use of __GFP_ZERO and only zero the object if the cache has no available objects would also make no sense.

---
 mm/slab.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/slab.c +2 -1
index 10e96137b44f..7a84c2aae85a 100644
@@ -3482,7 +3482,8 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
  * @flags: See kmalloc().
  *
  * Allocate an object from this cache.  The flags are only relevant
- * if the cache has no available objects.
+ * if the cache has no available objects. Except flag __GFP_ZERO which
+ * will zero the returned object.
  *
  * Return: pointer to the new object or %NULL in case of error
  */
Signature · 1 line
2.31.1

Thanks!

Signature · 2 lines
Thanks,
Hyeonggon
Acked-by on v1 1/1
#2 lore raw
In reply to Alexander Aring

mm/slab.c void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru, · line 3486

Quoted 11 lines · Alexander Aring
mm/slab.c +2 -1
index 10e96137b44f..7a84c2aae85a 100644
@@ -3482,7 +3482,8 @@ void *__kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru,
  * @flags: See kmalloc().
  *
  * Allocate an object from this cache.  The flags are only relevant
- * if the cache has no available objects.
+ * if the cache has no available objects. Except flag __GFP_ZERO which
+ * will zero the returned object.

Minor nit: it's probably better to do "... has no available objects, except flag ..." and not seperate sentences. After that is done, feel free to add