Re: [PATCH v2] mm/slab: reject unsupported kmalloc() sizes
From: Harry Yoo
Date: Wed Sep 02 2026 - 07:43:42 EST
On Sun, Aug 30, 2026 at 10:23:23PM -0400, Zi Yan wrote:
> kmalloc() is used to allocate physically contiguous memory for kernel
> allocations. For requests larger than KMALLOC_MAX_CACHE_SIZE, kmalloc()
> uses the page allocator and can only support up to KMALLOC_MAX_SIZE. For
> request sizes bigger than KMALLOC_MAX_SIZE, the page allocator can emit a
> WARN because kmalloc() allocates an order greater than MAX_PAGE_ORDER. To
> make the KMALLOC_MAX_SIZE limit more explicit instead of relying on the
> page allocator check, add a KMALLOC_MAX_SIZE check inside kmalloc() to emit
> a WARN and return NULL for requested sizes bigger than KMALLOC_MAX_SIZE.
> Like the WARN in the page allocator and kvmalloc(), allow __GFP_NOWARN to
> suppress the WARN.
>
> Suggested-by: "Vlastimil Babka (SUSE)" <vbabka@xxxxxxxxxx>
> Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
> ---
Looks good to me,
Reviewed-by: Harry Yoo (Meta) <harry@xxxxxxxxxx>
--
Cheers,
Harry / Hyeonggon