All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: use kvmalloc for target regions array
@ 2026-06-03 11:23 Akinobu Mita
  2026-06-03 13:49 ` SeongJae Park
  0 siblings, 1 reply; 2+ messages in thread
From: Akinobu Mita @ 2026-06-03 11:23 UTC (permalink / raw)
  To: damon; +Cc: akinobu.mita

damon_commit_target_regions() temporarily allocates a single contiguous
memory region using kmalloc to store copies of all damon_regions of the
damon_target.
However, if the damon_target has a large number of damon_regions, the
total size may exceed KMALLOC_MAX_SIZE.

This problem can be avoided by using kvmalloc instead of kmalloc.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 mm/damon/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 265d51ade25b..08e5ce53a7b8 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1358,14 +1358,14 @@ static int damon_commit_target_regions(struct damon_target *dst,
 	if (!i)
 		return 0;
 
-	ranges = kmalloc_objs(*ranges, i, GFP_KERNEL | __GFP_NOWARN);
+	ranges = kvmalloc_objs(*ranges, i, GFP_KERNEL | __GFP_NOWARN);
 	if (!ranges)
 		return -ENOMEM;
 	i = 0;
 	damon_for_each_region(src_region, src)
 		ranges[i++] = src_region->ar;
 	err = damon_set_regions(dst, ranges, i, src_min_region_sz);
-	kfree(ranges);
+	kvfree(ranges);
 	return err;
 }
 
-- 
2.43.0


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

* Re: [PATCH] mm/damon/core: use kvmalloc for target regions array
  2026-06-03 11:23 [PATCH] mm/damon/core: use kvmalloc for target regions array Akinobu Mita
@ 2026-06-03 13:49 ` SeongJae Park
  0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2026-06-03 13:49 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: SeongJae Park, damon

On Wed,  3 Jun 2026 20:23:06 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:

> damon_commit_target_regions() temporarily allocates a single contiguous
> memory region using kmalloc to store copies of all damon_regions of the
> damon_target.
> However, if the damon_target has a large number of damon_regions, the
> total size may exceed KMALLOC_MAX_SIZE.
> 
> This problem can be avoided by using kvmalloc instead of kmalloc.

Nice catch, thank you!

> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

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

I applied  this patch to damon/next [1] tree.  We are now quite close to next
merge window.  We (mm community) want to focus on making mm.git more stabilized
and therefore ready for the next merge window, rather than adding more changes
that are not really urgent.  I understand this series is not really urgent.
Hence, Andrew might not add this patch until next -rc1 release.  In the case, I
will request Andrew adding this to mm.git after next -rc1 release.  Let me know
if you think this is really urgent.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees


Thanks,
SJ

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

end of thread, other threads:[~2026-06-03 13:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 11:23 [PATCH] mm/damon/core: use kvmalloc for target regions array Akinobu Mita
2026-06-03 13:49 ` SeongJae Park

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.