From patchwork Mon Dec 4 10:20:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13478094 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 81CA2C4167B for ; Mon, 4 Dec 2023 10:21:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E69C6B0292; Mon, 4 Dec 2023 05:21:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 171496B0293; Mon, 4 Dec 2023 05:21:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDE216B0294; Mon, 4 Dec 2023 05:21:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D81C16B0292 for ; Mon, 4 Dec 2023 05:21:24 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A904B8018D for ; Mon, 4 Dec 2023 10:21:24 +0000 (UTC) X-FDA: 81528743688.26.DE7F8CE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf16.hostedemail.com (Postfix) with ESMTP id F2D6A180014 for ; Mon, 4 Dec 2023 10:21:22 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701685283; 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=MkYhSjq1gmn+NvQIs839Rv9wLvHAy0pkB1przhhCExU=; b=LKPMVfqHZJm+fuISXGQlGqu1SXb4cLnjF0QPev7zMYN4LuXlFXI0tIA1+9XRodLADqXGM/ 0SxBgShcGdxMEAOHxoJb0TIfsl2X2eMHem7mBaeJmIwRyxh4FP4szj1AC3acZN+3hD8HcG 0D0iFfldr8wRtfB3IhMfTBoL5H5gz5I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701685283; a=rsa-sha256; cv=none; b=YCTZIoxcXQ5D9KsToB6GeHqF983JRceBxRF7pzi1GEv1ikoM04Uybls6etUlWyMh0W9AD9 xsiWyA/1UwL5/oDfpcEF5kxxEMNPIvQtN4Nwk/hMGYzJETML7RUot2+zVG4osl5bg/CKAD e1HFVY8laNpTkRxwEQor6rcFk/CfU1I= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9BC2A16F3; Mon, 4 Dec 2023 02:22:09 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 845573F6C4; Mon, 4 Dec 2023 02:21:19 -0800 (PST) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Alistair Popple Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 10/10] selftests/mm/cow: Add tests for anonymous multi-size THP Date: Mon, 4 Dec 2023 10:20:27 +0000 Message-Id: <20231204102027.57185-11-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231204102027.57185-1-ryan.roberts@arm.com> References: <20231204102027.57185-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F2D6A180014 X-Rspam-User: X-Stat-Signature: n7am4tggi4gqywcu5u8eaqcktce6mm18 X-Rspamd-Server: rspam03 X-HE-Tag: 1701685282-321093 X-HE-Meta: U2FsdGVkX18owN7w3DxJEKTr79yw+x2FgDnhucwAWuO6G9GKJpr+i/RPfJb+cqHJhF56Bijk4dmdvZOJMztibmrM3t2lNEOXQ8zxQMH+w2sxvXttXiB3Isr+Sf5OL6lZ0fPojG7Blzu7qzpgi8o3PdSExnNJjUxM4MYtQBq74u4IPhE/XT1ufqiOX2qCHpQ9cA6HjFidE2yAW0R92EwowUl1byVblsKCoqstn9RC8pasAt5PlJaCQiQVX7r8FuMzekbzXdKDzah6KgfLzfSVyfaCcdBDVWhygyxlxYklgFOf3kNKhfGhrneeaHHdtpe/Kc6voOETGriZjNIUA7ElnyfZBnrQSYizG3pLNu221ti0XGDByaTjlRnaDgXZgnYzS3eFLFRpUZoPqL/qJm35nvnM99qptQoANCxtwP5Wk6rWvysuaAybhvVzHDpr40Org2VdYnR0CNDrtp5Eg240aBzhA7NwsX/AaYPvnb/Sdf7z008PLDClLqxK0zDHb7Gt5NddtcSKJGapfigAeG8T+pwZUlAoCUffCf7YDH0xCpmzfG32c2y010uysXdENImXcMW/fJwMOhkxi3Mazq+3aVOCgftxxztDvfwnEmgywnubEluFTykAhOL7qVPtF9kf7woRVr8CuLpm1b2sP+9H+o/UwRcqMV6BFbmJgSJHO5bd59EottD7Ykqf5OMh9dwCwtZn2EQhLGfgjqFQXQOGSxJLqvBJDitDiHyyB+WZKDgGnxY9xpyo32iyZ5yXXYMPIXnJn3yQ7Pb2DXupJ6yb5gstdNwyUUA7+FvWYFd3GjgH5Bwur9zzsD+d/nSeDZp2AD4W1luTaDmi3oZ/vFprCIbbSv/1GUK5J2Q4SSir1cKZNamQUMjdpDstulFfcInfNcBWR6NTD+miW3pJPQaqHJ5OtdqI0rgmCaUtv4ushZf0nlljjQVPCGZOjCndAsI+Kq+u5scA70LkaXbQQo6 XGUu0d80 Y+iswfUgou0hE3HmVZY1WMmimDi81G6HDAsOpMj1c2e0deq3+OJKrppxnThzRBqUC8KkfXieXwcpZJ7SOXhwa8GA4iXvqN5SKendT5c3LSDNdAFqFSeLgjLftmKzdvyxCpNqugzjZCbMlX9IQq7ZuXfCmcHgZA4M/xLrMtp18q2NDmyXMUjWhfUe/TFJMfKgVEk+1JDqCCGRnPpakfmnIN4yfJAmwLGWP8F/V 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: Add tests similar to the existing PMD-sized THP tests, but which operate on memory backed by (PTE-mapped) multi-size THP. This reuses all the existing infrastructure. If the test suite detects that multi-size THP is not supported by the kernel, the new tests are skipped. Signed-off-by: Ryan Roberts Reviewed-by: David Hildenbrand --- tools/testing/selftests/mm/cow.c | 84 +++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index 4d0b5a125d3c..37b4d7d28ae9 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -29,15 +29,49 @@ #include "../../../../mm/gup_test.h" #include "../kselftest.h" #include "vm_util.h" +#include "thp_settings.h" static size_t pagesize; static int pagemap_fd; static size_t pmdsize; +static int nr_thpsizes; +static size_t thpsizes[20]; static int nr_hugetlbsizes; static size_t hugetlbsizes[10]; static int gup_fd; static bool has_huge_zeropage; +static int sz2ord(size_t size) +{ + return __builtin_ctzll(size / pagesize); +} + +static int detect_thp_sizes(size_t sizes[], int max) +{ + int count = 0; + unsigned long orders; + size_t kb; + int i; + + /* thp not supported at all. */ + if (!pmdsize) + return 0; + + orders = 1UL << sz2ord(pmdsize); + orders |= thp_supported_orders(); + + for (i = 0; orders && count < max; i++) { + if (!(orders & (1UL << i))) + continue; + orders &= ~(1UL << i); + kb = (pagesize >> 10) << i; + sizes[count++] = kb * 1024; + ksft_print_msg("[INFO] detected THP size: %zu KiB\n", kb); + } + + return count; +} + static void detect_huge_zeropage(void) { int fd = open("/sys/kernel/mm/transparent_hugepage/use_zero_page", @@ -1101,15 +1135,27 @@ static void run_anon_test_case(struct test_case const *test_case) run_with_base_page(test_case->fn, test_case->desc); run_with_base_page_swap(test_case->fn, test_case->desc); - if (pmdsize) { - run_with_thp(test_case->fn, test_case->desc, pmdsize); - run_with_thp_swap(test_case->fn, test_case->desc, pmdsize); - run_with_pte_mapped_thp(test_case->fn, test_case->desc, pmdsize); - run_with_pte_mapped_thp_swap(test_case->fn, test_case->desc, pmdsize); - run_with_single_pte_of_thp(test_case->fn, test_case->desc, pmdsize); - run_with_single_pte_of_thp_swap(test_case->fn, test_case->desc, pmdsize); - run_with_partial_mremap_thp(test_case->fn, test_case->desc, pmdsize); - run_with_partial_shared_thp(test_case->fn, test_case->desc, pmdsize); + for (i = 0; i < nr_thpsizes; i++) { + size_t size = thpsizes[i]; + struct thp_settings settings = *thp_current_settings(); + + settings.hugepages[sz2ord(pmdsize)].enabled = THP_NEVER; + settings.hugepages[sz2ord(size)].enabled = THP_ALWAYS; + thp_push_settings(&settings); + + if (size == pmdsize) { + run_with_thp(test_case->fn, test_case->desc, size); + run_with_thp_swap(test_case->fn, test_case->desc, size); + } + + run_with_pte_mapped_thp(test_case->fn, test_case->desc, size); + run_with_pte_mapped_thp_swap(test_case->fn, test_case->desc, size); + run_with_single_pte_of_thp(test_case->fn, test_case->desc, size); + run_with_single_pte_of_thp_swap(test_case->fn, test_case->desc, size); + run_with_partial_mremap_thp(test_case->fn, test_case->desc, size); + run_with_partial_shared_thp(test_case->fn, test_case->desc, size); + + thp_pop_settings(); } for (i = 0; i < nr_hugetlbsizes; i++) run_with_hugetlb(test_case->fn, test_case->desc, @@ -1130,8 +1176,9 @@ static int tests_per_anon_test_case(void) { int tests = 2 + nr_hugetlbsizes; + tests += 6 * nr_thpsizes; if (pmdsize) - tests += 8; + tests += 2; return tests; } @@ -1689,15 +1736,23 @@ static int tests_per_non_anon_test_case(void) int main(int argc, char **argv) { int err; + struct thp_settings default_settings; pagesize = getpagesize(); pmdsize = read_pmd_pagesize(); if (pmdsize) { + /* Only if THP is supported. */ + thp_read_settings(&default_settings); + default_settings.hugepages[sz2ord(pmdsize)].enabled = THP_INHERIT; + thp_save_settings(); + thp_push_settings(&default_settings); + ksft_print_msg("[INFO] detected PMD size: %zu KiB\n", pmdsize / 1024); - ksft_print_msg("[INFO] detected THP size: %zu KiB\n", - pmdsize / 1024); + + nr_thpsizes = detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes)); } + nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes, ARRAY_SIZE(hugetlbsizes)); detect_huge_zeropage(); @@ -1716,6 +1771,11 @@ int main(int argc, char **argv) run_anon_thp_test_cases(); run_non_anon_test_cases(); + if (pmdsize) { + /* Only if THP is supported. */ + thp_restore_settings(); + } + err = ksft_get_fail_cnt(); if (err) ksft_exit_fail_msg("%d out of %d tests failed\n",