Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
@ 2026-08-31 15:13 Mike Rapoport (Microsoft)
  2026-08-31 15:13 ` [PATCH 1/2] " Mike Rapoport (Microsoft)
  2026-08-31 15:13 ` [PATCH 2/2] MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section Mike Rapoport (Microsoft)
  0 siblings, 2 replies; 12+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-31 15:13 UTC (permalink / raw)
  To: Jonathan Corbet, Andrew Morton, David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
	Randy Dunlap, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	linux-doc, linux-kernel, linux-mm

Update hte memory-allocation guide to describe k[mz]alloc_obj() and
clarify description of kmalloc() size limitations.

And when I realized that get_maintainers.pl does not list any of mm
people for that patch I added the MAINTAINERS update as well :)

---
Mike Rapoport (Microsoft) (2):
      docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
      MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section

 Documentation/core-api/memory-allocation.rst | 30 +++++++++++++++++++++-------
 MAINTAINERS                                  |  2 ++
 2 files changed, 25 insertions(+), 7 deletions(-)
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260831-docs-memalloc-guide-dc4db94dda96

--
Sincerely yours,
Mike.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
  2026-08-31 15:13 [PATCH 0/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc Mike Rapoport (Microsoft)
@ 2026-08-31 15:13 ` Mike Rapoport (Microsoft)
  2026-08-31 15:26   ` Suren Baghdasaryan
                     ` (3 more replies)
  2026-08-31 15:13 ` [PATCH 2/2] MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section Mike Rapoport (Microsoft)
  1 sibling, 4 replies; 12+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-31 15:13 UTC (permalink / raw)
  To: Jonathan Corbet, Andrew Morton, David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
	Randy Dunlap, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	linux-doc, linux-kernel, linux-mm

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>
---
 Documentation/core-api/memory-allocation.rst | 30 +++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
index 0f19dd5243239..8ecfa4d35f4f5 100644
--- a/Documentation/core-api/memory-allocation.rst
+++ b/Documentation/core-api/memory-allocation.rst
@@ -19,6 +19,12 @@ Diversity of the allocation APIs combined with the numerous GFP flags
 makes the question "How should I allocate memory?" not that easy to
 answer, although very likely you should use
 
+::
+
+  kzalloc_obj(<VAR_OR_TYPE>);
+
+or
+
 ::
 
   kzalloc(<size>, GFP_KERNEL);
@@ -139,10 +145,13 @@ allocate memory for an array, there are kmalloc_array() and kcalloc()
 helpers. The helpers struct_size(), array_size() and array3_size() can
 be used to safely calculate object sizes without overflowing.
 
-The maximal size of a chunk that can be allocated with `kmalloc` is
-limited. The actual limit depends on the hardware and the kernel
-configuration, but it is a good practice to use `kmalloc` for objects
-smaller than page size.
+Since 7.0 there are type aware kmalloc-family helpers that let you safely and
+conveniently allocate a single object or arrays of objects with kzalloc_obj()
+and kmalloc_obj() and their array versions kzalloc_objs() and
+kmalloc_objs(). These helpers only need the type of the object that should be
+allocated and the count of elements in the array for the array versions.
+
+As of v7.2, vast majority of the memory allocations use kzalloc_obj().
 
 The address of a chunk allocated with `kmalloc` is aligned to at least
 ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the
@@ -154,9 +163,16 @@ Chunks allocated with kmalloc() can be resized with krealloc(). Similarly
 to kmalloc_array(): a helper for resizing arrays is provided in the form of
 krealloc_array().
 
-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.
+
+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

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/2] MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section
  2026-08-31 15:13 [PATCH 0/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc Mike Rapoport (Microsoft)
  2026-08-31 15:13 ` [PATCH 1/2] " Mike Rapoport (Microsoft)
@ 2026-08-31 15:13 ` Mike Rapoport (Microsoft)
  2026-08-31 15:17   ` Lorenzo Stoakes (ARM)
                     ` (2 more replies)
  1 sibling, 3 replies; 12+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-31 15:13 UTC (permalink / raw)
  To: Jonathan Corbet, Andrew Morton, David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
	Randy Dunlap, Shuah Khan, Suren Baghdasaryan, Vlastimil Babka,
	linux-doc, linux-kernel, linux-mm

Previous efforts to make sure that mm files are properly listed in
MAINTAINERS missed

Documentation/admin-guide/mm/
Documentation/core-api/memory-allocation.rst

Add them to "MEMORY MANAGEMENT - MISC"

Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 3a19da74d00c9..707f93320ad72 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17275,6 +17275,8 @@ F:	Documentation/ABI/testing/sysfs-kernel-mm-cma
 F:	Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers
 F:	Documentation/ABI/testing/sysfs-kernel-mm-numa
 F:	Documentation/admin-guide/mm/
+F:	Documentation/core-api/memory-allocation.rst
+F:	Documentation/core-api/mm-api.rst
 F:	Documentation/mm/
 F:	drivers/char/mem.c
 F:	include/linux/cma.h

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section
  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)
  2 siblings, 0 replies; 12+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-08-31 15:17 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Jonathan Corbet, Andrew Morton, David Hildenbrand,
	Liam R. Howlett, Michal Hocko, Randy Dunlap, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, linux-doc, linux-kernel,
	linux-mm

On Mon, Aug 31, 2026 at 06:13:02PM +0300, Mike Rapoport (Microsoft) wrote:
> Previous efforts to make sure that mm files are properly listed in
> MAINTAINERS missed
>
> Documentation/admin-guide/mm/
> Documentation/core-api/memory-allocation.rst
>
> Add them to "MEMORY MANAGEMENT - MISC"
>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>

> ---
>  MAINTAINERS | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 3a19da74d00c9..707f93320ad72 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -17275,6 +17275,8 @@ F:	Documentation/ABI/testing/sysfs-kernel-mm-cma
>  F:	Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers
>  F:	Documentation/ABI/testing/sysfs-kernel-mm-numa
>  F:	Documentation/admin-guide/mm/
> +F:	Documentation/core-api/memory-allocation.rst
> +F:	Documentation/core-api/mm-api.rst
>  F:	Documentation/mm/
>  F:	drivers/char/mem.c
>  F:	include/linux/cma.h
>
> --
> 2.53.0
>

--
Cheers, Lorenzo


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
  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
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Suren Baghdasaryan @ 2026-08-31 15:26 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Jonathan Corbet, Andrew Morton, David Hildenbrand,
	Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Randy Dunlap,
	Shuah Khan, Vlastimil Babka, linux-doc, linux-kernel, linux-mm

On Mon, Aug 31, 2026 at 8:13 AM Mike Rapoport (Microsoft)
<rppt@kernel.org> 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

s/hte/the

> 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>

Reviewed-by: Suren Baghdasaryan <surenb@google.com>

> ---
>  Documentation/core-api/memory-allocation.rst | 30 +++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> index 0f19dd5243239..8ecfa4d35f4f5 100644
> --- a/Documentation/core-api/memory-allocation.rst
> +++ b/Documentation/core-api/memory-allocation.rst
> @@ -19,6 +19,12 @@ Diversity of the allocation APIs combined with the numerous GFP flags
>  makes the question "How should I allocate memory?" not that easy to
>  answer, although very likely you should use
>
> +::
> +
> +  kzalloc_obj(<VAR_OR_TYPE>);
> +
> +or
> +
>  ::
>
>    kzalloc(<size>, GFP_KERNEL);
> @@ -139,10 +145,13 @@ allocate memory for an array, there are kmalloc_array() and kcalloc()
>  helpers. The helpers struct_size(), array_size() and array3_size() can
>  be used to safely calculate object sizes without overflowing.
>
> -The maximal size of a chunk that can be allocated with `kmalloc` is
> -limited. The actual limit depends on the hardware and the kernel
> -configuration, but it is a good practice to use `kmalloc` for objects
> -smaller than page size.
> +Since 7.0 there are type aware kmalloc-family helpers that let you safely and
> +conveniently allocate a single object or arrays of objects with kzalloc_obj()
> +and kmalloc_obj() and their array versions kzalloc_objs() and
> +kmalloc_objs(). These helpers only need the type of the object that should be
> +allocated and the count of elements in the array for the array versions.
> +
> +As of v7.2, vast majority of the memory allocations use kzalloc_obj().
>
>  The address of a chunk allocated with `kmalloc` is aligned to at least
>  ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the
> @@ -154,9 +163,16 @@ Chunks allocated with kmalloc() can be resized with krealloc(). Similarly
>  to kmalloc_array(): a helper for resizing arrays is provided in the form of
>  krealloc_array().
>
> -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.
> +
> +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
>
> --
> 2.53.0
>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
  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)
  3 siblings, 0 replies; 12+ messages in thread
From: Randy Dunlap @ 2026-08-31 17:20 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Jonathan Corbet, Andrew Morton,
	David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, linux-doc, linux-kernel,
	linux-mm



On 8/31/26 8:13 AM, 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>
> ---
>  Documentation/core-api/memory-allocation.rst | 30 +++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> index 0f19dd5243239..8ecfa4d35f4f5 100644
> --- a/Documentation/core-api/memory-allocation.rst
> +++ b/Documentation/core-api/memory-allocation.rst
> @@ -19,6 +19,12 @@ Diversity of the allocation APIs combined with the numerous GFP flags
>  makes the question "How should I allocate memory?" not that easy to
>  answer, although very likely you should use
>  
> +::
> +
> +  kzalloc_obj(<VAR_OR_TYPE>);
> +
> +or
> +
>  ::
>  
>    kzalloc(<size>, GFP_KERNEL);
> @@ -139,10 +145,13 @@ allocate memory for an array, there are kmalloc_array() and kcalloc()
>  helpers. The helpers struct_size(), array_size() and array3_size() can
>  be used to safely calculate object sizes without overflowing.
>  
> -The maximal size of a chunk that can be allocated with `kmalloc` is
> -limited. The actual limit depends on the hardware and the kernel
> -configuration, but it is a good practice to use `kmalloc` for objects
> -smaller than page size.
> +Since 7.0 there are type aware kmalloc-family helpers that let you safely and
> +conveniently allocate a single object or arrays of objects with kzalloc_obj()
> +and kmalloc_obj() and their array versions kzalloc_objs() and
> +kmalloc_objs(). These helpers only need the type of the object that should be
> +allocated and the count of elements in the array for the array versions.
> +
> +As of v7.2, vast majority of the memory allocations use kzalloc_obj().
>  
>  The address of a chunk allocated with `kmalloc` is aligned to at least
>  ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the
> @@ -154,9 +163,16 @@ Chunks allocated with kmalloc() can be resized with krealloc(). Similarly
>  to kmalloc_array(): a helper for resizing arrays is provided in the form of
>  krealloc_array().
>  
> -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

                                                              `MAX_ORDER`; the

> +same limit also applies to the page allocator.
> +
> +Internally, slab allocator differentiates allocations of different orders and

               the slab allocator
?

> +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
> 

-- 
~Randy



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
  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)
  3 siblings, 0 replies; 12+ messages in thread
From: SJ Park @ 2026-09-01  3:39 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: SJ Park, Jonathan Corbet, Andrew Morton, David Hildenbrand,
	Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Randy Dunlap,
	Shuah Khan, Suren Baghdasaryan, Vlastimil Babka, linux-doc,
	linux-kernel, linux-mm

On Mon, 31 Aug 2026 18:13:01 +0300 "Mike Rapoport (Microsoft)" <rppt@kernel.org> 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

s/hte/the/

> and make kzalloc_obj() the first answer to "How should I allocate
> memory?" question.
> 
> While on it, clarify description of kmalloc() size limitations.

Looks good improvements to me.

> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Acked-by: SJ Park <sj@kernel.org>

> ---
>  Documentation/core-api/memory-allocation.rst | 30 +++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> index 0f19dd5243239..8ecfa4d35f4f5 100644
> --- a/Documentation/core-api/memory-allocation.rst
> +++ b/Documentation/core-api/memory-allocation.rst
> @@ -19,6 +19,12 @@ Diversity of the allocation APIs combined with the numerous GFP flags
>  makes the question "How should I allocate memory?" not that easy to
>  answer, although very likely you should use
>  
> +::
> +
> +  kzalloc_obj(<VAR_OR_TYPE>);
> +
> +or
> +
>  ::
>  
>    kzalloc(<size>, GFP_KERNEL);
> @@ -139,10 +145,13 @@ allocate memory for an array, there are kmalloc_array() and kcalloc()
>  helpers. The helpers struct_size(), array_size() and array3_size() can
>  be used to safely calculate object sizes without overflowing.
>  
> -The maximal size of a chunk that can be allocated with `kmalloc` is
> -limited. The actual limit depends on the hardware and the kernel
> -configuration, but it is a good practice to use `kmalloc` for objects
> -smaller than page size.
> +Since 7.0 there are type aware kmalloc-family helpers that let you safely and
> +conveniently allocate a single object or arrays of objects with kzalloc_obj()
> +and kmalloc_obj() and their array versions kzalloc_objs() and
> +kmalloc_objs(). These helpers only need the type of the object that should be
> +allocated and the count of elements in the array for the array versions.
> +
> +As of v7.2, vast majority of the memory allocations use kzalloc_obj().

As the commit message says "Since v7.0 the most used memory allocation function
is kzalloc_obj()", should we s/7.2/7.0/ ?

I also feel like the above sentence might not really needed, or can be
version-neutral, e.g., Since its introduction, vast majoritiy of ... switched
to use ... ?  No strong opinion.

>  
>  The address of a chunk allocated with `kmalloc` is aligned to at least
>  ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the
> @@ -154,9 +163,16 @@ Chunks allocated with kmalloc() can be resized with krealloc(). Similarly
>  to kmalloc_array(): a helper for resizing arrays is provided in the form of
>  krealloc_array().
>  
> -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.

I initially thought if it makes look more consistent by using kmalloc() instead
of `kmalloc`.  But seems anyway we are mixing those here and there.  So I have
no opinion.

> +
> +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
> 
> -- 
> 2.53.0


Thanks,
SJ


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section
  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)
  2 siblings, 0 replies; 12+ messages in thread
From: SJ Park @ 2026-09-01  3:42 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: SJ Park, Jonathan Corbet, Andrew Morton, David Hildenbrand,
	Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Randy Dunlap,
	Shuah Khan, Suren Baghdasaryan, Vlastimil Babka, linux-doc,
	linux-kernel, linux-mm

On Mon, 31 Aug 2026 18:13:02 +0300 "Mike Rapoport (Microsoft)" <rppt@kernel.org> wrote:

> Previous efforts to make sure that mm files are properly listed in
> MAINTAINERS missed
> 
> Documentation/admin-guide/mm/
> Documentation/core-api/memory-allocation.rst
> 
> Add them to "MEMORY MANAGEMENT - MISC"

Makes sense to me.

> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Reviewed-by: SJ Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
  2026-08-31 15:13 ` [PATCH 1/2] " Mike Rapoport (Microsoft)
                     ` (2 preceding siblings ...)
  2026-09-01  3:39   ` SJ Park
@ 2026-09-01 10:17   ` Vlastimil Babka (SUSE)
  2026-09-01 16:10     ` Mike Rapoport
  3 siblings, 1 reply; 12+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-09-01 10:17 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Jonathan Corbet, Andrew Morton,
	David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Randy Dunlap,
	Shuah Khan, Suren Baghdasaryan, linux-doc, linux-kernel, linux-mm

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>

Suggestion below:

> ---
>  Documentation/core-api/memory-allocation.rst | 30 +++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> index 0f19dd5243239..8ecfa4d35f4f5 100644
> --- a/Documentation/core-api/memory-allocation.rst
> +++ b/Documentation/core-api/memory-allocation.rst
> @@ -19,6 +19,12 @@ Diversity of the allocation APIs combined with the numerous GFP flags
>  makes the question "How should I allocate memory?" not that easy to
>  answer, although very likely you should use
>  
> +::
> +
> +  kzalloc_obj(<VAR_OR_TYPE>);
> +
> +or
> +
>  ::
>  
>    kzalloc(<size>, GFP_KERNEL);
> @@ -139,10 +145,13 @@ allocate memory for an array, there are kmalloc_array() and kcalloc()
>  helpers. The helpers struct_size(), array_size() and array3_size() can
>  be used to safely calculate object sizes without overflowing.
>  
> -The maximal size of a chunk that can be allocated with `kmalloc` is
> -limited. The actual limit depends on the hardware and the kernel
> -configuration, but it is a good practice to use `kmalloc` for objects
> -smaller than page size.
> +Since 7.0 there are type aware kmalloc-family helpers that let you safely and
> +conveniently allocate a single object or arrays of objects with kzalloc_obj()
> +and kmalloc_obj() and their array versions kzalloc_objs() and
> +kmalloc_objs(). These helpers only need the type of the object that should be
> +allocated and the count of elements in the array for the array versions.
> +
> +As of v7.2, vast majority of the memory allocations use kzalloc_obj().
>  
>  The address of a chunk allocated with `kmalloc` is aligned to at least
>  ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the
> @@ -154,9 +163,16 @@ Chunks allocated with kmalloc() can be resized with krealloc(). Similarly
>  to kmalloc_array(): a helper for resizing arrays is provided in the form of
>  krealloc_array().
>  
> -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? (Also `MAX_ORDER` doesn't
exist anymore)

> +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
> 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] MAINTAINERS: add memory related docs in core-mm/ to MM - MISC section
  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)
  2 siblings, 0 replies; 12+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-09-01 10:18 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Jonathan Corbet, Andrew Morton,
	David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Randy Dunlap,
	Shuah Khan, Suren Baghdasaryan, linux-doc, linux-kernel, linux-mm

On 8/31/26 17:13, Mike Rapoport (Microsoft) wrote:
> Previous efforts to make sure that mm files are properly listed in
> MAINTAINERS missed
> 
> Documentation/admin-guide/mm/
> Documentation/core-api/memory-allocation.rst

These partially don't match the actually added lines :)

> 
> Add them to "MEMORY MANAGEMENT - MISC"
> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

> ---
>  MAINTAINERS | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 3a19da74d00c9..707f93320ad72 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -17275,6 +17275,8 @@ F:	Documentation/ABI/testing/sysfs-kernel-mm-cma
>  F:	Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers
>  F:	Documentation/ABI/testing/sysfs-kernel-mm-numa
>  F:	Documentation/admin-guide/mm/
> +F:	Documentation/core-api/memory-allocation.rst
> +F:	Documentation/core-api/mm-api.rst
>  F:	Documentation/mm/
>  F:	drivers/char/mem.c
>  F:	include/linux/cma.h
> 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
  2026-09-01 10:17   ` Vlastimil Babka (SUSE)
@ 2026-09-01 16:10     ` Mike Rapoport
  2026-09-02  7:50       ` Vlastimil Babka (SUSE)
  0 siblings, 1 reply; 12+ messages in thread
From: Mike Rapoport @ 2026-09-01 16:10 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE)
  Cc: Jonathan Corbet, Andrew Morton, David Hildenbrand,
	Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Randy Dunlap,
	Shuah Khan, Suren Baghdasaryan, linux-doc, linux-kernel, linux-mm

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.

> (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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc
  2026-09-01 16:10     ` Mike Rapoport
@ 2026-09-02  7:50       ` Vlastimil Babka (SUSE)
  0 siblings, 0 replies; 12+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-09-02  7:50 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Jonathan Corbet, Andrew Morton, David Hildenbrand,
	Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Randy Dunlap,
	Shuah Khan, Suren Baghdasaryan, linux-doc, linux-kernel, linux-mm

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
>> > 
>> 
> 



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-09-02  7:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 15:13 [PATCH 0/2] docs/core-api: memory-allocation: add k[mz]alloc_obj() and clarify kmalloc 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)
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)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox