From nobody Mon Nov 25 11:28:22 2024 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 751ED1DA63F; Mon, 28 Oct 2024 12:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730117131; cv=none; b=uGt1uogW/9vFjr3YHiPzxktiD4XUGh16RoAXdrXOcwHIwczBmQjKB6p/tGn+zORioY3PsW233+gF82W8w8eovVmloicABpWsOyg80eoiK42qGk5u+ID8urQujDteJtCupA6T2AHydVVUdwWwtGfl2V9YfcaWXMJKEZaRzk3JyqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730117131; c=relaxed/simple; bh=OAAn6AtZPCe522akGFfkCKvJoBBc3aTAMgK76mCoTZM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uKcSuokt/r+xqRgWmlaN8MNsCz6ZznOef6KLez9lGZeRJu3aaUa4pKPcn+qyMZOJQeJo7cq+bpC4X/3jGYkWsTBNsfP4dh6j8gNDNHv2WfaQivolugjr/YOxdsYaau9KSL+JtYA/hFKllijhoMXkyRT2KZQFjQUpvXEc1Pu8L/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4XcXCH3dm4z1ynhW; Mon, 28 Oct 2024 20:05:31 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 396571A0188; Mon, 28 Oct 2024 20:05:23 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 28 Oct 2024 20:05:22 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Linux-MM , Shuah Khan , Subject: [PATCH RFC 08/10] mm: page_frag: add testing for the newly added API Date: Mon, 28 Oct 2024 19:58:48 +0800 Message-ID: <20241028115850.3409893-9-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241028115850.3409893-1-linyunsheng@huawei.com> References: <20241028115850.3409893-1-linyunsheng@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemf200006.china.huawei.com (7.185.36.61) Content-Type: text/plain; charset="utf-8" Add testing for the newly added prepare API, for both aligned and non-aligned API, also probe API is also tested along with prepare API. CC: Alexander Duyck CC: Andrew Morton CC: Linux-MM Signed-off-by: Yunsheng Lin --- .../selftests/mm/page_frag/page_frag_test.c | 76 +++++++++++++++++-- tools/testing/selftests/mm/run_vmtests.sh | 4 + tools/testing/selftests/mm/test_page_frag.sh | 27 +++++++ 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/page_frag/page_frag_test.c b/tools/= testing/selftests/mm/page_frag/page_frag_test.c index e806c1866e36..3b3c32389def 100644 --- a/tools/testing/selftests/mm/page_frag/page_frag_test.c +++ b/tools/testing/selftests/mm/page_frag/page_frag_test.c @@ -32,6 +32,10 @@ static bool test_align; module_param(test_align, bool, 0); MODULE_PARM_DESC(test_align, "use align API for testing"); =20 +static bool test_prepare; +module_param(test_prepare, bool, 0); +MODULE_PARM_DESC(test_prepare, "use prepare API for testing"); + static int test_alloc_len =3D 2048; module_param(test_alloc_len, int, 0); MODULE_PARM_DESC(test_alloc_len, "alloc len for testing"); @@ -74,6 +78,21 @@ static int page_frag_pop_thread(void *arg) return 0; } =20 +static void frag_frag_test_commit(struct page_frag_cache *nc, + struct page_frag *prepare_pfrag, + struct page_frag *probe_pfrag, + unsigned int used_sz) +{ + if (prepare_pfrag->page !=3D probe_pfrag->page || + prepare_pfrag->offset !=3D probe_pfrag->offset || + prepare_pfrag->size !=3D probe_pfrag->size) { + force_exit =3D true; + WARN_ONCE(true, TEST_FAILED_PREFIX "wrong probed info\n"); + } + + page_frag_refill_commit(nc, prepare_pfrag, used_sz); +} + static int page_frag_push_thread(void *arg) { struct ptr_ring *ring =3D arg; @@ -86,15 +105,61 @@ static int page_frag_push_thread(void *arg) int ret; =20 if (test_align) { - va =3D page_frag_alloc_align(&test_nc, test_alloc_len, - GFP_KERNEL, SMP_CACHE_BYTES); + if (test_prepare) { + struct page_frag prepare_frag, probe_frag; + void *probe_va; + + va =3D page_frag_alloc_refill_prepare_align(&test_nc, + test_alloc_len, + &prepare_frag, + GFP_KERNEL, + SMP_CACHE_BYTES); + + probe_va =3D __page_frag_alloc_refill_probe_align(&test_nc, + test_alloc_len, + &probe_frag, + -SMP_CACHE_BYTES); + if (va !=3D probe_va) { + force_exit =3D true; + WARN_ONCE(true, TEST_FAILED_PREFIX "wrong va\n"); + } + + if (likely(va)) + frag_frag_test_commit(&test_nc, &prepare_frag, + &probe_frag, test_alloc_len); + } else { + va =3D page_frag_alloc_align(&test_nc, + test_alloc_len, + GFP_KERNEL, + SMP_CACHE_BYTES); + } =20 if ((unsigned long)va & (SMP_CACHE_BYTES - 1)) { force_exit =3D true; WARN_ONCE(true, TEST_FAILED_PREFIX "unaligned va returned\n"); } } else { - va =3D page_frag_alloc(&test_nc, test_alloc_len, GFP_KERNEL); + if (test_prepare) { + struct page_frag prepare_frag, probe_frag; + void *probe_va; + + va =3D page_frag_alloc_refill_prepare(&test_nc, test_alloc_len, + &prepare_frag, GFP_KERNEL); + + probe_va =3D page_frag_alloc_refill_probe(&test_nc, test_alloc_len, + &probe_frag); + + if (va !=3D probe_va) { + force_exit =3D true; + WARN_ONCE(true, TEST_FAILED_PREFIX "wrong va\n"); + } + + if (likely(va)) + frag_frag_test_commit(&test_nc, &prepare_frag, + &probe_frag, test_alloc_len); + } else { + va =3D page_frag_alloc(&test_nc, test_alloc_len, GFP_KERNEL); + } } =20 if (!va) @@ -176,8 +241,9 @@ static int __init page_frag_test_init(void) } =20 duration =3D (u64)ktime_us_delta(ktime_get(), start); - pr_info("%d of iterations for %s testing took: %lluus\n", nr_test, - test_align ? "aligned" : "non-aligned", duration); + pr_info("%d of iterations for %s %s API testing took: %lluus\n", nr_test, + test_align ? "aligned" : "non-aligned", + test_prepare ? "prepare" : "alloc", duration); =20 out: ptr_ring_cleanup(&ptr_ring, NULL); diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/self= tests/mm/run_vmtests.sh index 2c5394584af4..f6ff9080a6f2 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -464,6 +464,10 @@ CATEGORY=3D"page_frag" run_test ./test_page_frag.sh al= igned =20 CATEGORY=3D"page_frag" run_test ./test_page_frag.sh nonaligned =20 +CATEGORY=3D"page_frag" run_test ./test_page_frag.sh aligned_prepare + +CATEGORY=3D"page_frag" run_test ./test_page_frag.sh nonaligned_prepare + echo "SUMMARY: PASS=3D${count_pass} SKIP=3D${count_skip} FAIL=3D${count_fa= il}" | tap_prefix echo "1..${count_total}" | tap_output =20 diff --git a/tools/testing/selftests/mm/test_page_frag.sh b/tools/testing/s= elftests/mm/test_page_frag.sh index f55b105084cf..1c757fd11844 100755 --- a/tools/testing/selftests/mm/test_page_frag.sh +++ b/tools/testing/selftests/mm/test_page_frag.sh @@ -43,6 +43,8 @@ check_test_failed_prefix() { SMOKE_PARAM=3D"test_push_cpu=3D$TEST_CPU_0 test_pop_cpu=3D$TEST_CPU_1" NONALIGNED_PARAM=3D"$SMOKE_PARAM test_alloc_len=3D75 nr_test=3D$NR_TEST" ALIGNED_PARAM=3D"$NONALIGNED_PARAM test_align=3D1" +NONALIGNED_PREPARE_PARAM=3D"$NONALIGNED_PARAM test_prepare=3D1" +ALIGNED_PREPARE_PARAM=3D"$ALIGNED_PARAM test_prepare=3D1" =20 check_test_requirements() { @@ -77,6 +79,20 @@ run_aligned_check() insmod $DRIVER $ALIGNED_PARAM > /dev/null 2>&1 } =20 +run_nonaligned_prepare_check() +{ + echo "Run performance tests to evaluate how fast nonaligned prepare API i= s." + + insmod $DRIVER $NONALIGNED_PREPARE_PARAM > /dev/null 2>&1 +} + +run_aligned_prepare_check() +{ + echo "Run performance tests to evaluate how fast aligned prepare API is." + + insmod $DRIVER $ALIGNED_PREPARE_PARAM > /dev/null 2>&1 +} + run_smoke_check() { echo "Run smoke test." @@ -87,6 +103,7 @@ run_smoke_check() usage() { echo -n "Usage: $0 [ aligned ] | [ nonaligned ] | | [ smoke ] | " + echo "[ aligned_prepare ] | [ nonaligned_prepare ] | " echo "manual parameters" echo echo "Valid tests and parameters:" @@ -107,6 +124,12 @@ usage() echo "# Performance testing for aligned alloc API" echo "$0 aligned" echo + echo "# Performance testing for nonaligned prepare API" + echo "$0 nonaligned_prepare" + echo + echo "# Performance testing for aligned prepare API" + echo "$0 aligned_prepare" + echo exit 0 } =20 @@ -158,6 +181,10 @@ function run_test() run_nonaligned_check elif [[ "$1" =3D "aligned" ]]; then run_aligned_check + elif [[ "$1" =3D "nonaligned_prepare" ]]; then + run_nonaligned_prepare_check + elif [[ "$1" =3D "aligned_prepare" ]]; then + run_aligned_prepare_check else run_manual_check $@ fi --=20 2.33.0