Re: [PATCH v11 03/13] lib/group_cpus: Add group_mask_cpus_evenly()

From: Aaron Tomlin

Date: Wed Apr 22 2026 - 13:48:11 EST


On Mon, Apr 20, 2026 at 03:11:52PM +0200, Marco Crivellari wrote:
> Without it, I guess the kmalloc() in `group_mask_cpus_evenly()` will
> return ZERO_SIZE_PTR:

Hi Marco,

Thank you for reviewing the patch.

You are correct. If numgrps is 0, __do_kmalloc_node() will
return ZERO_SIZE_PTR.

> Should this check be added or it is not needed? Or maybe rely on `ZERO_OR_NULL_PTR()` ?

- File: mm/slub.c

5275 static __always_inline
5276 void *__do_kmalloc_node(size_t size, kmem_buckets *b, gfp_t flags, int node,
5277 unsigned long caller)
5278 {
5279 struct kmem_cache *s;
5280 void *ret;
:
5289 if (unlikely(!size))
5290 return ZERO_SIZE_PTR;
:
5298 }

Regarding your suggestion: rather than relying on ZERO_OR_NULL_PTR() after
the fact, I think it is much cleaner to just add the early exit at the very
beginning of the function, exactly as group_cpus_evenly() does. It avoids
the allocator path entirely.


Kind regards,
--
Aaron Tomlin

Attachment: signature.asc
Description: PGP signature