mm/damon/core: use kvmalloc for target regions array
Subsystems (2)
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
@@ -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
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 alldamon_regionsof thedamon_target.
However, if thedamon_targethas a large number ofdamon_regions, the total size may exceedKMALLOC_MAX_SIZE.This problem can be avoided by using kvmalloc instead of kmalloc.
Nice catch, thank you!
Quoted 2 lines
Signed-off-by Akinobu Mita <[email protected]>
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