From patchwork Tue Oct 22 08:39:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yejian X-Patchwork-Id: 13845298 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2734CD1CDBC for ; Tue, 22 Oct 2024 08:39:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8583B6B0082; Tue, 22 Oct 2024 04:39:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 808336B0083; Tue, 22 Oct 2024 04:39:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A8266B0088; Tue, 22 Oct 2024 04:39:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4C8DF6B0083 for ; Tue, 22 Oct 2024 04:39:36 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E4A06140D3A for ; Tue, 22 Oct 2024 08:39:18 +0000 (UTC) X-FDA: 82700589048.10.2B289F5 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf25.hostedemail.com (Postfix) with ESMTP id CE3DBA000F for ; Tue, 22 Oct 2024 08:39:19 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of zhengyejian@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=zhengyejian@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729586223; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B/qXp7gPtVXF5LR3orr+9syIVKp5AXTKT7cNoSMNNPM=; b=AUO2BZBf6SeaZip2krWm0LYvweNfcPNbnZMSqZ32DwX+nUpLELy+QuZOZsUZrFg9sPkWdX ovMU52swgeaW+hrvMbd7e0qRD+XsGmFQ3rkYGqq7TaAmkXJG3WikP88xGg7WlYspeA8FhW Y3YMZaUj+LAneY53QtEF01ZX+nyopc4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729586223; a=rsa-sha256; cv=none; b=ECGrau0WJ1aASlkwYAIUxbxkhvodsdtZtHAwhEiwprCaeybnWCaajNE/HxBsq4EIWsF03P XW+wDhMNlc083JQkXKLkaDU0g3+urQJPGw33YLtVM5z7UXmZPh+fw4g2ooecSBE6r09vad ZtUobS6K7ZjTYO7prIHiLWv02RVlx6I= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of zhengyejian@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=zhengyejian@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4XXlw22T3tz4f3jty for ; Tue, 22 Oct 2024 16:39:14 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 9DD501A018D for ; Tue, 22 Oct 2024 16:39:26 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP3 (Coremail) with SMTP id _Ch0CgCnRoO3ZBdndQiQEg--.6910S3; Tue, 22 Oct 2024 16:39:25 +0800 (CST) From: Zheng Yejian 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 1/2] mm/damon/vaddr: Fix issue in damon_va_evenly_split_region() Date: Tue, 22 Oct 2024 16:39:26 +0800 Message-Id: <20241022083927.3592237-2-zhengyejian@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241022083927.3592237-1-zhengyejian@huaweicloud.com> References: <20241021163316.12443-1-sj@kernel.org> <20241022083927.3592237-1-zhengyejian@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgCnRoO3ZBdndQiQEg--.6910S3 X-Coremail-Antispam: 1UD129KBjvJXoWxXw4UZrWDCr45Xw13uFW8Xrb_yoW5urWrp3 93WrWfKFWDtFy2vw15Z3Z5ZrnFyrW8tF1UGryfJF1vyF1vg34UtFW3J345tryrCFWxZw1f Zw4xtrWfGF9rCa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm014x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67 kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY 6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVj vjDU0xZFpf9x0JUqkskUUUUU= X-CM-SenderInfo: x2kh0w51hmxt3q6k3tpzhluzxrxghudrp/ X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CE3DBA000F X-Stat-Signature: pxkq95sgb8ntca9uxsc4mk7rm1qaccu7 X-HE-Tag: 1729586359-492688 X-HE-Meta: U2FsdGVkX1+atDiAe2JagO3QB7lTf/Gp408xMvQ1M9YSkNr6D6+M8YwCZwaU+8WZGTTd8vgP+MWhCjBGXxMr88Ocziz1dkFEoxY4Y5d9hh9uAdUwiilfoTTMvTnV6s4tZSMF6jV8CEiB85Iptc3gd+RWcYLaEkyXHtzNzPqcSHiIKkNBhjYeP0yDa5L5/qku/1ue6gtLCZFTaQCh8CmNISXLDIYa65uoMJesTzxD/m+Koj108YJhK+RGgaL07vjA9AooQ0vL9NGcx/WbYPY5+ZlQJZlDX+xqn35FJUbr0Fwj2pLcZzd/ZXTDoQhmivZvX62Efscb5TUMa5S1zSe0tk7WP/KAUo4+/KRvC6w/y5aYeti3XsRoDwXEJIJVwBm+ljX78cVbqpYVEL61O8Ypy1NwBWelBzjyg257fr2oo3HMUWh6wAup/2+qtHO3ON0Og2d75+MMdp0jBy4NnfB6RAaEpRKI7QNC6cBLEUCShNZhMmZpdAsOWViOxczjZPeek0jszzFnEqlMSPMqEyz0aCa5tciY2YdnwE1nIlGfATMagLauNKVLoXKKr0g7CR/5a0D6S9jDkj2RHPW1xDLLTHvY2Mat1ezKXK1W6jXExXqbtuSxSMOs1myylQn5BBMuDNegSRGILHd0S9x0GkZnPGDQ8b8cAr+UWU7BBvJZSjRrYjw1O59pfYaxaIZUrxsyYEhLA8jMrxznN7Tnx2Ocn7n/TpLb9NdxvKTCQqrMrP0XdqSJCue+epQ0I0CL39HHtuaQs1Pk08mlMFJK8flLT6RWn9kj5/6uilDCs+8lOCHcgURsOGmeUG1MdrIzuyH+YAESd641bFuAKgjjYIvBlNvVNjAXWIEoZ0KVo94Onm/lF2/aluyLC+hN+10JYU+rAO5pf64KFm9iKQETwEG2+JMbWh03lDcHqscgTFSqjDygcscisiXpz9ul5dsiG5tjkgDqx7qTWFDNe60sKHH 4Mj/MbtW mMf9BONuZWbGer4rb+8AJjhCjKd3+782WUVnvNufthwkr+w9919M+g+4Mi4Iqs9oy8WpH4tymfUHZGlJUoGs6R8UvSIdHveFV55DEmj8KqwQ0oCOcVGFsvwLCqpp1td9nf9EYk4BmTaHKNt9vwCvQZC5v9OMCgiyGKtz16457S9HkuVZk7zrMYmIGPwnyd5Ixou0RcNfiL6p2ilo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: According to the logic of damon_va_evenly_split_region(), currently following split case would not meet the expectation: Suppose DAMON_MIN_REGION=0x1000, Case: Split [0x0, 0x3000) into 2 pieces, then the result would be acutually 3 regions: [0x0, 0x1000), [0x1000, 0x2000), [0x2000, 0x3000) but NOT the expected 2 regions: [0x0, 0x1000), [0x1000, 0x3000) !!! The root cause is that when calculating size of each split piece in damon_va_evenly_split_region(): `sz_piece = ALIGN_DOWN(sz_orig / nr_pieces, DAMON_MIN_REGION);` both the dividing and the ALIGN_DOWN may cause loss of precision, then each time split one piece of size 'sz_piece' from origin 'start' to 'end' would cause more pieces are split out than expected!!! To fix it, count for each piece split and make sure no more than 'nr_pieces'. In addition, add above case into damon_test_split_evenly(). After this patch, damon-operations test passed: # ./tools/testing/kunit/kunit.py run damon-operations [...] ============== damon-operations (6 subtests) =============== [PASSED] damon_test_three_regions_in_vmas [PASSED] damon_test_apply_three_regions1 [PASSED] damon_test_apply_three_regions2 [PASSED] damon_test_apply_three_regions3 [PASSED] damon_test_apply_three_regions4 [PASSED] damon_test_split_evenly ================ [PASSED] damon-operations ================= Fixes: 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces") Signed-off-by: Zheng Yejian Reviewed-by: SeongJae Park --- v1 -> v2: - Move 'nr_pieces == 1' check into separate patch and update commit messages; - Change type of variable 'i' to be 'unsigned int'; - Remove a puzzling comment; v1: https://lore.kernel.org/all/20241018035304.1050135-1-zhengyejian@huaweicloud.com/ mm/damon/tests/vaddr-kunit.h | 1 + mm/damon/vaddr.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h index a339d117150f..a149e354bb26 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, 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 08cfd22b5249..dba3b2f4d758 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -67,6 +67,7 @@ static int damon_va_evenly_split_region(struct damon_target *t, unsigned long sz_orig, sz_piece, orig_end; struct damon_region *n = NULL, *next; unsigned long start; + unsigned int i; if (!r || !nr_pieces) return -EINVAL; @@ -80,8 +81,7 @@ static int damon_va_evenly_split_region(struct damon_target *t, r->ar.end = r->ar.start + sz_piece; next = damon_next_region(r); - for (start = r->ar.end; start + sz_piece <= orig_end; - start += sz_piece) { + for (start = r->ar.end, i = 1; i < nr_pieces; start += sz_piece, i++) { n = damon_new_region(start, start + sz_piece); if (!n) return -ENOMEM;