Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3080528rdh; Mon, 27 Nov 2023 06:12:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHnBltqSVx0HkXcxySuhCU3rKU7hdNP+jWGIh+jRamTxpCkTNqyUUDfIbQ3wX3nkl9GJMF X-Received: by 2002:a05:6a21:9181:b0:187:f343:ab3d with SMTP id tp1-20020a056a21918100b00187f343ab3dmr11765494pzb.55.1701094365307; Mon, 27 Nov 2023 06:12:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701094365; cv=none; d=google.com; s=arc-20160816; b=uQMj+nLgzyhRKGpC70iJaDMgBLoWXYc5pKs+7k+56jLKuPERYiEklOUnC81Zl4oy8j SAzP+2ENUPO8Qu0sOJhwcYt0zRDG7BWjQ0NbVjqhSigWowhfP2GRrGV72zTt9ohbsPbu iCTo+idrO0/3uN2/wtTAJJ/jfIT1ElGSXbvfAN2bm1KNZgSpgiY+re0aICZeqGGFkmdK rxVAG6KPT7uXeeOSFCANjCmD3ldv/TtHn7LEt/hE0oHMIGzZQYVssacaJ21AziE4IghX KSq9a+rhFYpzdOasZKZSxUiOJ+KEQcV5+abh8NJLH1apye20QvvW8lXehRCv5iHfbgpb ATqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=G9wP5kL5K/X3kMTbr4sHrA2WTRmCS3JZrnmiMvzqDpg=; fh=FqonUikKAjIwNRZ1ApB5NfFNuD9zWnbgUpco8Kwc9o4=; b=TTB3xyf3i2yvrnSO2wk4PQ0CEiH/tna6X211tEKjyQjPrzqO/+gTCWo67zlOOblZig +rAxMy6UqBb757b8hGVg1h3XHkyRy6GMLoPPMjLCAJxQCAL/z4YyVKSQ1D5jDQCN3rw1 PJwKICEPgNH416UXtntDhI4fzrrdXwIH23pLs4XEEmYZdHjrA72LcXCQEyXLiczfFE1y AthALX2WiEyGavIBd/yuyY3Adf1C6/g35M/KXWJMIBrwq8Gn2Q44gPQHkB6UwI2C84jk Z2Mu/AhiP/ZXfVXl3UZ6qPsB5GmfHq3nH+ivkKh6e6B4XnEQ32sptdmKBh0Kw4A66xSu dNhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id l13-20020a63f30d000000b005c21fcf96a2si9955812pgh.825.2023.11.27.06.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:12:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 6B86C80220A2; Mon, 27 Nov 2023 06:12:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233526AbjK0OMG (ORCPT + 99 others); Mon, 27 Nov 2023 09:12:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233582AbjK0OLW (ORCPT ); Mon, 27 Nov 2023 09:11:22 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6812526B3 for ; Mon, 27 Nov 2023 06:02:08 -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 B0D572F4; Mon, 27 Nov 2023 06:02:55 -0800 (PST) Received: from [10.57.73.191] (unknown [10.57.73.191]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 626723F6C4; Mon, 27 Nov 2023 06:02:05 -0800 (PST) Message-ID: <8dd0f52c-d261-4541-930f-bd4e5921be5b@arm.com> Date: Mon, 27 Nov 2023 14:02:04 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RESEND PATCH v7 10/10] selftests/mm/cow: Add tests for anonymous small-sized THP Content-Language: en-GB 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: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231122162950.3854897-1-ryan.roberts@arm.com> <20231122162950.3854897-11-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: <20231122162950.3854897-11-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 27 Nov 2023 06:12:22 -0800 (PST) On 22/11/2023 16:29, Ryan Roberts wrote: > 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]; Off the back of some comments David made againt the previous patch [1], I'm proposing to rework this a bit so that ALL thp sizes are stored in this array, not just the non-PMD-sized sizes. This makes the changes overall a bit smaller and easier to understand, I think... > 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) This changes to detect_thp_sizes() and deposits all sizes in sizes[] > +{ > + 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); This just prints "[INFO] detected THP size: %zu KiB" > + } > + > + 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(); > + } This same loop covers the pmdsize tests too, and I've just added a conditional that runs the 2 extra tests that are pmdsize only. > 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", > -- > 2.25.1 >