From patchwork Thu Dec 7 16:12:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13483625 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 C4744C4167B for ; Thu, 7 Dec 2023 16:13:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFBE46B00A5; Thu, 7 Dec 2023 11:13:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C33F46B00A6; Thu, 7 Dec 2023 11:13:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A87056B00A7; Thu, 7 Dec 2023 11:13:01 -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 8F8CA6B00A5 for ; Thu, 7 Dec 2023 11:13:01 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 607851C0434 for ; Thu, 7 Dec 2023 16:13:01 +0000 (UTC) X-FDA: 81540516162.01.1BA23D3 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf25.hostedemail.com (Postfix) with ESMTP id 46B07A002B for ; Thu, 7 Dec 2023 16:12:59 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf25.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701965579; 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=LD85FP3STUXbijC3O1hkm3ScDaZ5uXar2npdZOjBaag=; b=HhLWnavEMbp3G+YgOHMGKhCwTZVbFLcCmpqAuQv7HaX32rl87TcrzwwfUrEZL5dvr3+4qE dsG4h2+IsZgW4FZlkwrwF+4IAm4QY7N9WsICx7j7qQlAWBibjpHQr8YniG2+XBDS5cq0DI 9iGGwBgjU0VNzFw3AQ4K1xs0/2AHCMI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf25.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701965579; a=rsa-sha256; cv=none; b=6FKu1lIlP97TDzJ/XkyOmCRN3e8nVKorcvSDbLxT5K7hu3LV3QzK1pptkwPXb5rdNwn92y nQshLrRJXPcNtmWQt5EGG5MLmZY3zs5Yf2YB4Sd7K2eUTuCu45ZnH04ov4ps5qiCTekIlg OkOxscgC2INkoNkqY2tfly8Va4CRHII= 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 92E8A15BF; Thu, 7 Dec 2023 08:13:44 -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 CC2203F762; Thu, 7 Dec 2023 08:12:55 -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 v9 10/10] selftests/mm/cow: Add tests for anonymous multi-size THP Date: Thu, 7 Dec 2023 16:12:11 +0000 Message-Id: <20231207161211.2374093-11-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231207161211.2374093-1-ryan.roberts@arm.com> References: <20231207161211.2374093-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 46B07A002B X-Stat-Signature: scfo1gcrog1f73p6c5cs73uinxrrub98 X-HE-Tag: 1701965579-481697 X-HE-Meta: U2FsdGVkX19neTyEgJi+ZFjA8SdmO7jFAyfAHPM2uI48dLKHYHyYuYl0dMdy3lAqjFXsmqmsxu9j2lyga9Ma++StGmantOe1NfP8LvQ4R1yKG9zLm+nx2HVpEggU0qv7gA5L+tTz+F+fFsUePt1e+LfEpaG4V6BZ29vBNQ9YIp2wQTwLxYFDr8w1N+9+yaPBFvP4npMw1hoDH9lN/DNu9rgF+8qM7wOQnfZaJho9crCAL/OYoBcIh+bLqAEQKh12CC63eRqWUj/uWiZ8JW5OQctGQDBVEsai7aZtuquGlMOLCnDUzsoXgaTLeqHevWXUHyBZEDHLX596JEiOZ64gRhBsgPR0/T9ACZZx6ibnO8YmE4FB0QvZvHkI04o/23dOgwAcRcwm7qeoV3ISF6Ulb3w/EgmWBgPlaZxteIAqL6FeGDioij27bBnz2p0JWnjZ3HVQeQinPTt4Stln9zal+4BENg3An+RQRm8F2c61GX20LAl8HjOBoDJL/B/NRK06VNgUUp5SXZEvl1M/NPa5pDiQXXEMHL81NMHX7MqAe0q3yd3JKMeFL05MT8XTBExT7Bfo1LdnFzSVGqsxXPHNaJNsOPSxbt4i9xnugao6w+EmK3cPAO2N2dxTMdrz32YsenAA3s3vCJroYNibgVvbI/5/MR0OLsgZ4gmAr5RLCNdp47YhvBtOjhs+hyw/WrDCRnJ/tJL7OfOcnoLgwievbBj/kV0ruJNyMGmQ7y5OHpBtkUIb6LxiFxlCU90sI/lbdy6MXiLBNEVtF4dQQjBpiK9Pv/fpr7pOIxng0JXt7Qud4FCMJfrTrbCGNPj9+rcw668Ml4a7XKnN3+SPwf77t2RQFGrXNgCMHGxJ2+UlMwK7pJGwSNlGZhT+8IzC38H5vDN2em4wRuPsh778GgOUtGYKRTtyYVNiT+o2TiqhxZIxAblkVTexKa6ewbRa0QC5Q9b2zpuIKWS6TpiYnic kpU8wdF3 Dl80pi6U088GFbhAAubLtUxbdyyb41Fo02h+kVeTzM1Hv53ntZbvs3+iGK8cE5iN/uHliESjdOxdcJdhF6l1HaUEEYsCT9YD2pgOdsQx/N68H3r41Mk5hq+MZ3pizp59vTc4xyp/tgRw8HB+iRFrYx9q8PME1FOxJRNqOZbuT0J8rnfTORX2QJmSt2Gb76H8JKT6AjflgjispBv+GXnowMg7yZbRvVd1eLTZyy25wZu4xyducl5IdGZ/jCSItjPC9cwyALf5aQbYwJ+ZBw0dDUnlp71ifwXmvNIm0sCsOoQJdu/M= 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. Reviewed-by: David Hildenbrand Tested-by: Kefeng Wang Tested-by: John Hubbard Signed-off-by: Ryan Roberts --- 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",