From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Lorenzo Stoakes <ljs@kernel.org>, Michal Hocko <mhocko@suse.com>,
Randy Dunlap <rdunlap@infradead.org>,
Shuah Khan <skhan@linuxfoundation.org>,
Suren Baghdasaryan <surenb@google.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
Date: Wed, 2 Sep 2026 09:50:42 +0200 [thread overview]
Message-ID: <f0b194b4-6f41-455f-b807-de7c24fa8184@kernel.org> (raw)
In-Reply-To: <apb47Rsnz1H36SOy@kernel.org>
On 9/1/26 18:10, Mike Rapoport wrote:
> 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@kernel.org>
>>
>> Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
>
> 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.
The actual slab allocations limit is KMALLOC_MAX_CACHE_SIZE and that's
indeed not the point and hence I wouldn't mention it here. KMALLOC_MAX_SIZE
is literally a conversion of MAX_PAGE_ORDER to bytes, and since kmalloc()
takes bytes and not order as an argument, it seems more natural to me, e.g.:
`kmalloc` always allocates physically contiguous memory and the maximal size
of a chunk that can be allocated with `kmalloc` is limited by
`KMALLOC_MAX_SIZE`, which matches the page allocator's MAX_PAGE_ORDER limit.
>> (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
>> >
>>
>
next prev parent reply other threads:[~2026-09-02 7:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 15:13 [PATCH 0/2] " Mike Rapoport (Microsoft)
2026-08-31 15:13 ` [PATCH 1/2] " Mike Rapoport (Microsoft)
2026-08-31 15:26 ` Suren Baghdasaryan
2026-08-31 17:20 ` Randy Dunlap
2026-09-01 3:39 ` SJ Park
2026-09-01 10:17 ` Vlastimil Babka (SUSE)
2026-09-01 16:10 ` Mike Rapoport
2026-09-02 7:50 ` Vlastimil Babka (SUSE) [this message]
2026-08-31 15:13 ` [PATCH 2/2] MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section Mike Rapoport (Microsoft)
2026-08-31 15:17 ` Lorenzo Stoakes (ARM)
2026-09-01 3:42 ` SJ Park
2026-09-01 10:18 ` Vlastimil Babka (SUSE)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f0b194b4-6f41-455f-b807-de7c24fa8184@kernel.org \
--to=vbabka@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=liam@infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®