diff options
author | Zheng Yejian <zhengyejian@huaweicloud.com> | 2024-10-22 10:39:27 +0200 |
---|---|---|
committer | Andrew Morton <akpm@linux-foundation.org> | 2024-11-07 05:11:18 +0100 |
commit | 477327e10639a1ec5698847030b494dc75de33e4 (patch) | |
tree | 4c29aecabb746429412e447b634654c78c955603 /mm/damon | |
parent | mm/damon/vaddr: fix issue in damon_va_evenly_split_region() (diff) | |
download | linux-477327e10639a1ec5698847030b494dc75de33e4.tar.xz linux-477327e10639a1ec5698847030b494dc75de33e4.zip |
mm/damon/vaddr: add 'nr_piece == 1' check in damon_va_evenly_split_region()
As discussed in [1], damon_va_evenly_split_region() is called to
size-evenly split a region into 'nr_pieces' small regions,
when nr_pieces == 1, no actual split is required. Check that case
for better code readability and add a simple kunit testcase.
[1] https://lore.kernel.org/all/20241021163316.12443-1-sj@kernel.org/
Link: https://lkml.kernel.org/r/20241022083927.3592237-3-zhengyejian@huaweicloud.com
Signed-off-by: Zheng Yejian <zhengyejian@huaweicloud.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Cc: Fernand Sieber <sieberf@amazon.com>
Cc: Leonard Foerster <foersleo@amazon.de>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Ye Weihua <yeweihua4@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/damon')
-rw-r--r-- | mm/damon/tests/vaddr-kunit.h | 1 | ||||
-rw-r--r-- | mm/damon/vaddr.c | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h index fcdccb614fd8..b9fe3bc8472b 100644 --- a/mm/damon/tests/vaddr-kunit.h +++ b/mm/damon/tests/vaddr-kunit.h @@ -300,6 +300,7 @@ static void damon_test_split_evenly(struct kunit *test) damon_test_split_evenly_fail(test, 0, 100, 0); damon_test_split_evenly_succ(test, 0, 100, 10); damon_test_split_evenly_succ(test, 5, 59, 5); + damon_test_split_evenly_succ(test, 4, 6, 1); damon_test_split_evenly_succ(test, 0, 3, 2); damon_test_split_evenly_fail(test, 5, 6, 2); } diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 86f612fbf886..b9eaa20b73b9 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -72,6 +72,9 @@ static int damon_va_evenly_split_region(struct damon_target *t, if (!r || !nr_pieces) return -EINVAL; + if (nr_pieces == 1) + return 0; + orig_end = r->ar.end; sz_orig = damon_sz_region(r); sz_piece = ALIGN_DOWN(sz_orig / nr_pieces, DAMON_MIN_REGION); |