[PATCH 1/5] mm/damon/core: use kvmalloc for target regions array
From: SJ Park
Date: Mon Jun 29 2026 - 11:16:57 EST
From: Akinobu Mita <akinobu.mita@xxxxxxxxx>
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@xxxxxxxxx>
Reviewed-by: SJ Park <sj@xxxxxxxxxxx>
Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
Changes from v1
- v1: https://lore.kernel.org/20260603112306.58490-1-akinobu.mita@xxxxxxxxx
- Collect R-b: from SJ.
- Rebase to latest mm-new.
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 3dd2750c2ef20..ded76719e8a14 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1362,14 +1362,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.47.3