Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
From: Mike Rapoport
Date: Tue Sep 01 2026 - 12:36:52 EST
On Tue, Sep 01, 2026 at 12:17:02PM +0200, Vlastimil Babka (SUSE) wrote:
> On 8/31/26 17:13, Mike Rapoport (Microsoft) wrote:
> > Since v7.0 the most used memory allocation function is kzalloc_obj().
> >
> > Update hte memory-allocation guide to describe k[mz]alloc_obj() family
> > and make kzalloc_obj() the first answer to "How should I allocate
> > memory?" question.
> >
> > While on it, clarify description of kmalloc() size limitations.
> >
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
>
> Acked-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
Thanks!
> Suggestion below:
>
> > ---
> > Documentation/core-api/memory-allocation.rst | 30 +++++++++++++++++++++-------
> > 1 file changed, 23 insertions(+), 7 deletions(-)
> >
> > -For large allocations you can use vmalloc() and vzalloc(), or directly
> > -request pages from the page allocator. The memory allocated by `vmalloc`
> > -and related functions is not physically contiguous.
> > +`kmalloc` always allocates physically contiguous memory and the maximal size of
> > +a chunk that can be allocated with `kmalloc` is limited by `MAX_ORDER`, the
> > +same limit also applies to the page allocator.
>
> Would it be better to say the maximal size is KMALLOC_MAX_SIZE which is
> derived from page allocator's MAX_PAGE_ORDER?
My point was that whenever you allocate with kmalloc() the limit is
MAX_PAGE_ORDER, not necessarily for actual slab allocations.
> (Also `MAX_ORDER` doesn't exist anymore)
Will fix.
> > +Internally, slab allocator differentiates allocations of different orders and
> > +delegates larger allocations to the page allocator, but for the users of
> > +`kmalloc` family it is entirely transparent.
> > +
> > +For large allocations that do not require physically contiguous memory you can
> > +use vmalloc() and vzalloc() family.
> >
> > If you are not sure whether the allocation size is too large for
> > `kmalloc`, it is possible to use kvmalloc() and its derivatives. It will
> >
>
--
Sincerely yours,
Mike.