Skip to contentSkip to conversation

mm/damon/core: use kvmalloc for target regions array

PATCH In review Akinobu Mita 2 participants 2 messages Jun 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/damon/core: use kvmalloc for target regions array

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.

---
 mm/damon/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/damon/core.c +2 -2
index 265d51ade25b..08e5ce53a7b8 100644
@@ -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;
 }
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Wed, 3 Jun 2026 20:23:06 +0900 Akinobu Mita <[email protected]> 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!

Quoted 2 lines

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