From patchwork Wed Nov 15 13:27:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13456684 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 59D59C48BF9 for ; Wed, 15 Nov 2023 13:28:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9D246B034D; Wed, 15 Nov 2023 08:28:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4D346B034E; Wed, 15 Nov 2023 08:28:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D15946B034F; Wed, 15 Nov 2023 08:28:31 -0500 (EST) 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 C29CA6B034D for ; Wed, 15 Nov 2023 08:28:31 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 99BCA80A89 for ; Wed, 15 Nov 2023 13:28:31 +0000 (UTC) X-FDA: 81460268022.04.A48619A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 9471940010 for ; Wed, 15 Nov 2023 13:28:29 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.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=1700054909; 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=lVXulFLM/BbOzECqCrIvkGa5SvSb3hxRV73P3vTC2Os=; b=CaNLym3hpsSTS3xjzvLs9JPJOKj3IG/jCfxdfrBnLtlNGrCJ0PMn+yLgqAvaJBgJIgzpNH rPvGUf0znWOi1Y16+QM5NNVLobYrLBhPySoZVYwr8kNmEB+LmX05jCG6Ob6RjFqBcIshtz gbokTXlp6h3UmjbxrHqjp/knxRrBSRA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.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=1700054909; a=rsa-sha256; cv=none; b=Fj4p7/x1Mlb959xYZ/JRV50Yt5X6TiXoNKPim722EZu8vtqda1hyP5vJBAKWObuaJf2t9Z wi1eIl79eKysZe52PyH65Hn839AUfX1T99wBPCXErPZO3aai0NF80713chv/YhsjY372JO 1Ou8qw2H6vSYcLecgMO77EPTe+4D+dg= 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 20C55DA7; Wed, 15 Nov 2023 05:29:14 -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 A56AB3F7B4; Wed, 15 Nov 2023 05:28:25 -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 Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 10/10] selftests/mm/cow: Add tests for anonymous small-sized THP Date: Wed, 15 Nov 2023 13:27:34 +0000 Message-Id: <20231115132734.931023-11-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231115132734.931023-1-ryan.roberts@arm.com> References: <20231115132734.931023-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9471940010 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: fo88mnkuegarce9eoumgfgxo47b655zf X-HE-Tag: 1700054909-575265 X-HE-Meta: U2FsdGVkX1+xz71aOMmfx1yfwvXJkb4np7my0RBs0j9vmBWrhCKe7y3CNYK8ml1YypGFRMVVUoLGHfdcawrWTiWOEuoL5FUB81ZIv7JjDcBmUMS57bD2K+jhzBMyxR1Rmk9Z70Aju0oAyNH0yOUeeeJXiuGgL6LSY4TlO2S+P9uRPZJs7CjjtN4cxup0GIyhEg9Qo+B+tBk0Yyb2vLyqwy1TCwVKI0A/2Ow/Y33phKGUoCPKh8ZbCT6YJ3NFvx58affpKPshGJ/MEg0zzDZfnQe7gpxNzLRHAj+bcBkGkD2d/FVZTC9WWMchKYMCEQpaH5O8F5wkQ6MG9ussDNehHq4Dkc/jCGTn1zAuo2csqtJOtCkino5xIjme4xCB4ZhDespFUcmBj9W7sGpD2u+jYOkbjJLZc6jQrLn9B6ZHynhykDWqmutohl81QW3JN4V4V/bisSgRqktJynLNyUcl9Fi3wj69yWB/4j/p6yMaqkJkh6sxeIITxXOxjLfh52ML5KovgOIRUyC5bsEvkcR/zgBzFg22zo+noyovfKIcZyg9H3dJR9HpvyIKdaM+TTbshh6UD7L7Q+kxKrMR/SeEck/ZZh0X6TFY8XO0oH+5jLM+CVCmpZWZ9+PQckxJQbUw3fpBCzam8ddGN4PTZZQebwoKtyHU+mXXQu6lhpF1XjEsz+T1it6A/6L58u8mCRIAuiqAg6vfNoWmL1nWVTl30TjTvgsrCJnqZ2Cm7qoDKDWI8sIa9808daS1G2fz5o/0ZpbicVy2qvZCdZKlYCkfVkKabHuWq914aE73g4H3YfYFGR+oHt7dBRazNDpzjHURx+wjaQD1wYTo/FJPTIX9cWfNNfaq3UFxb7xpOruA/2UKH9vif2WX+Kv5CqSRkU4jaWbQsetSZj2QBGgAESa26i4RcJVg4ftELqDpP23+YMG6AuB4aSUbnmoKZA6IQxXVevT74NJEldBer/Nm7ki lUhUTwV7 sbkSjif1EPH0+Io+3clJWm9FgZH8eKGXG7D5n7sCUwslKq/Wk3lOc5KfxN9H6zwelpsYn43+Ki+pikuHV1icLMkdIdq/ZTqUa2Y6SDVBKgmHoR4gJjNRDkdodR3NdNe1ppOp2kVIZCx76np0BtcwXkW2rkHkdSiBlM70PZXsWYUu/F2Oh+Tufrz0RLqCv2OnRIN88xbL2P9vZleP/JG0XZ16TaeE/ZjAdn0l9 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) small-sized THP. This reuses all the existing infrastructure. If the test suite detects that small-sized THP is not supported by the kernel, the new tests are skipped. Signed-off-by: Ryan Roberts --- tools/testing/selftests/mm/cow.c | 71 +++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index d03c453cfd5c..3efc395c7077 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_thpsmallsizes; +static size_t thpsmallsizes[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_smallthp_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 = thp_supported_orders(); + + /* Only interested in small-sized THP (less than PMD-size). */ + for (i = 0; i < sz2ord(pmdsize); i++) { + if (!(orders & (1UL << i))) + continue; + kb = (pagesize >> 10) << i; + sizes[count++] = kb * 1024; + ksft_print_msg("[INFO] detected small-sized 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", @@ -1113,6 +1147,23 @@ static void run_anon_test_case(struct test_case const *test_case) 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_thpsmallsizes; i++) { + size_t size = thpsmallsizes[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); + + 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, hugetlbsizes[i]); @@ -1134,6 +1185,7 @@ static int tests_per_anon_test_case(void) if (pmdsize) tests += 8; + tests += 6 * nr_thpsmallsizes; return tests; } @@ -1691,12 +1743,24 @@ 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) + if (pmdsize) { + /* Only if THP is supported. */ + thp_read_settings(&default_settings); + default_settings.hugepages[sz2ord(pmdsize)].enabled = THP_GLOBAL; + thp_save_settings(); + thp_push_settings(&default_settings); + ksft_print_msg("[INFO] detected PMD-mapped THP size: %zu KiB\n", pmdsize / 1024); + + nr_thpsmallsizes = detect_smallthp_sizes(thpsmallsizes, + ARRAY_SIZE(thpsmallsizes)); + } + nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes, ARRAY_SIZE(hugetlbsizes)); detect_huge_zeropage(); @@ -1715,6 +1779,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",