linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zheng Yejian <zhengyejian@huaweicloud.com>
To: sj@kernel.org
Cc: akpm@linux-foundation.org, damon@lists.linux.dev,
	foersleo@amazon.de, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, shakeel.butt@linux.dev, sieberf@amazon.com,
	yeweihua4@huawei.com, zhengyejian@huaweicloud.com
Subject: [PATCH v2 2/2] mm/damon/vaddr: Add 'nr_piece == 1' check in damon_va_evenly_split_region()
Date: Tue, 22 Oct 2024 16:39:27 +0800	[thread overview]
Message-ID: <20241022083927.3592237-3-zhengyejian@huaweicloud.com> (raw)
In-Reply-To: <20241022083927.3592237-1-zhengyejian@huaweicloud.com>

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/

Signed-off-by: Zheng Yejian <zhengyejian@huaweicloud.com>
---
 mm/damon/tests/vaddr-kunit.h | 1 +
 mm/damon/vaddr.c             | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
index a149e354bb26..b9a03e4e29e5 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 dba3b2f4d758..25db0a582c27 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);
-- 
2.25.1



  parent reply	other threads:[~2024-10-22  8:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-18  3:53 [PATCH] mm/damon/vaddr: Fix issue " Zheng Yejian
2024-10-18 18:33 ` SeongJae Park
2024-10-21  3:56   ` Zheng Yejian
2024-10-21 16:33     ` SeongJae Park
2024-10-22  8:39       ` [PATCH v2 0/2] " Zheng Yejian
2024-10-22  8:39         ` [PATCH v2 1/2] " Zheng Yejian
2024-10-22 17:54           ` SeongJae Park
2024-10-22 18:00           ` SeongJae Park
2024-10-22  8:39         ` Zheng Yejian [this message]
2024-10-22 17:57           ` [PATCH v2 2/2] mm/damon/vaddr: Add 'nr_piece == 1' check " SeongJae Park
2024-10-22 18:05         ` [PATCH v2 0/2] mm/damon/vaddr: Fix issue " SeongJae Park
2024-10-23  1:27           ` Zheng Yejian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241022083927.3592237-3-zhengyejian@huaweicloud.com \
    --to=zhengyejian@huaweicloud.com \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=foersleo@amazon.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shakeel.butt@linux.dev \
    --cc=sieberf@amazon.com \
    --cc=sj@kernel.org \
    --cc=yeweihua4@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox