Skip to content

Commit

Permalink
mm/damon/vaddr: add 'nr_piece == 1' check in damon_va_evenly_split_re…
Browse files Browse the repository at this point in the history
…gion()

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>
  • Loading branch information
Zheng Yejian authored and Andrew Morton committed Nov 7, 2024
1 parent f3c7a1e commit 477327e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions mm/damon/tests/vaddr-kunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions mm/damon/vaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 477327e

Please sign in to comment.