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: 165365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2536952vqg; Wed, 15 Nov 2023 05:31:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IExZJF9iL3fTcnx470qGrt2obex6CD0kWDayfr3qb+d1vEFHgxAe4qzI2ImHAjmfAG2qHc8 X-Received: by 2002:a05:6e02:1526:b0:359:3ee6:a909 with SMTP id i6-20020a056e02152600b003593ee6a909mr16200556ilu.13.1700055069686; Wed, 15 Nov 2023 05:31:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700055069; cv=none; d=google.com; s=arc-20160816; b=kzalJ2uYc/vCaTDVt3+KXGlrg+UWLbbSXwETbgGWUYz7gf9NMQ3slLHrTMP9vm31fm eXhiZB9zd5KBeZFWTnSvpxgAE2xsB1XTu/wwFBpBhPJP6lQSqkb/K5Ayl3L5Be+w1CAZ ytq6UCmkCwh7GIPdICOuRaUervpYzW1rcIAtA6aN6WZ8+Gs3g9U6Ij2jPj7CEfVhbu+C RNLDaRMThRba61ofMVcfqprzPk6aXQAs4745DPBdS8H20b5J8lO6fIeC8+/aRSGaDnGB f2eLm4KpgVurVLNnJwBwmqtWuRTNhBbQMMxTkOj57b6BI4m6JMNM8COgDkGiTEo+QklZ 79xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lVXulFLM/BbOzECqCrIvkGa5SvSb3hxRV73P3vTC2Os=; fh=7axEUdnMUApK6aLYLrmxIYzEqwt8JUQTbtI9r8kD7PQ=; b=qwsnx+DCxKlcgzv7QI+P2684b2onukuMwIv7dFQnLneyfq0H42WaGh3adkit3qKTuO 81MAF43LWP1mRQ4L0Qn05MK9d/cecmlr6RD1XMH6bIP1YRHkruWrcT2HhvGh9jBKnWGQ EAAvCy93mDUfUxYXWbbcQE9l6Ps2FbrUFsDpL+aKs3mqkDkBJLHaRbDkaH4clfaqZRjo XDoUzqo3c7hlzUT1W4TNge8TTE8H+GlbSthicNfjaSKNGNk4JH2qC2MIY9vSTO7Vi4aj vtkVkuJuiP5UYrlaYOpxgbZmkybYRcpdj1FhVD/UnerdLXGLdsq8y04HbYIO/LW+ZjUb XA2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id c1-20020a655a81000000b005c1b322b3c1si4048018pgt.681.2023.11.15.05.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:31:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E5E988075B11; Wed, 15 Nov 2023 05:30:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344085AbjKON3F (ORCPT + 28 others); Wed, 15 Nov 2023 08:29:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344030AbjKON2h (ORCPT ); Wed, 15 Nov 2023 08:28:37 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CBEE610D5 for ; Wed, 15 Nov 2023 05:28:28 -0800 (PST) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 15 Nov 2023 05:30:17 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782636944717373188 X-GMAIL-MSGID: 1782636944717373188 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",