From mboxrd@z Thu Jan 1 00:00:00 1970 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 A3D59C46CA3 for ; Mon, 27 Nov 2023 14:03:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24BD06B0250; Mon, 27 Nov 2023 09:03:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FBF16B0256; Mon, 27 Nov 2023 09:03:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09CCB6B025F; Mon, 27 Nov 2023 09:03:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EA4576B0250 for ; Mon, 27 Nov 2023 09:03:23 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7D9861A0288 for ; Mon, 27 Nov 2023 14:03:23 +0000 (UTC) X-FDA: 81503901486.10.F45E834 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 93569C0039 for ; Mon, 27 Nov 2023 14:02:16 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.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=1701093739; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G9wP5kL5K/X3kMTbr4sHrA2WTRmCS3JZrnmiMvzqDpg=; b=3Im8JFOjK8Hsdl0viZXLsk5Rm+kUxmZNkojy4ly7so1oIqdFlDrhbuyAc+HdydB14R46Y9 sqAYSyyMwnF/zvAcO87X90Po64mhSZYkkWqhMM8UMurCQOxvdhRE2yxsrAgmWwVnGmaeH7 jgZ7nRG8Amts49x/UvuVv4oLcAuJW9w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf22.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=1701093739; a=rsa-sha256; cv=none; b=opVNowI4iLO43ogbN52t5sxR3I/jyVbd60bP3jFLRrHhymrmu2EdYfDJkBLwcLaLutSutI Kz6vYax2lRdwBzfHCbP1fp5AmxmBRXC618UcT61mrTu2KksRxYFW4yk243FA9EGsMtBTeO MYLmDnZP1uA1VSbAt/AsagT25fWyhsk= 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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 93569C0039 X-Stat-Signature: iy8czoktxz5tuh5arrcw1ajweqkhqaxq X-Rspam-User: X-HE-Tag: 1701093736-578839 X-HE-Meta: U2FsdGVkX18AB96i7fDm0MvnbgJdzdkM9qMd9ShlKyuhri6C4zSXy13tiQyJs3X4rYHGCTq2z4seEWmpvmqIT63v13PIFWJSXOyVm80Wdc6EmwtwCp8IhoWEKwtN+IxZ9JuvKx7MF9ExJPYTby241Hh1h/Q4H9ti7KXJo7vdg4ceiv7y5bFh6qu88tbedkhzGiJLCUDqEpFrGyLah8cXQvjIg2WOfSFj56Zz+B1kBxlHzGoRvNkEo4Ie6DnZ2xHJFOd93vpTH5s34Z4CycUu0dJ5LN2RYtAGS8s7l83rw2T+ueICP7++C3zhV+xExuckgU4AmIU06q1eAErSpjVm/HyVXy2RVDh0VyOtHefctnr9qFC4ogOulQq0Njthrx7XClyk3lv448z3Ou5mZ/C+IlpzDXACM27e5jJMJ1ingicw3YwZmwcpnzs4+fn4LV2orssnAqCE+FBcPWMnN5tDRSFD+W98xV6H8FYsZ6Ku3iKA13Mr1BT/XBsFqCWfYnT9b+m1etSFv/ichmt6ZAHfVmZnHIFNfWay5cVowVbcHThdLmqDqVFxrP9X134CpTQgm0wJXlFSgeu5zJDLYcFHqruM9Mj28Nu+kQ0aOQjEYQO38/JDZtPJDiVwnLrwNWTJMAg+x15uZROx0JRdoY6crJcmLFrIAg7LsUczR/nsLVGSKkqoRMdpmricLPfL7ZqX/z3Fy/2RWnkOMoyRbNdYTTpvdBge70ExCNwxo97YBhbp6l1+hmooA2dL5//fJvpOgqkKHyVIPh63FGRVcGlL2lwUA3ZRhqcIrqFAJfV00B1kg3etXfUDVX6s044zfLkwmMxxzMIcUBnVczKOgFN4DDKmQo2msUK4z2Etn+NVw2Y0gSphko3/ap+XRqzoYaIrvwebtvWS0hkl3dnmo3Ddd8jgl+nSo1QkI5aInla7T6mbVqIPe4gV1ZYLxmbjuwpmG5fLc5dGRm7Wt6iL82x S2Oumc9e SriWq3jjsrwYUteW5tELKoI6ZqUifbMLxCvorGuoIYgIdDc8Gb8MKQuX5VwNyEuIqeeXsUz/q8joG71Jll1iwhH1kUX/sBy5kkxQuwtZ/fkBEdeANBm1NhB4HfbU/p9dPO2mqvIcggey/inbybzboquGpjBthBGdJOgi2/PtW9nC5LdcuwfQ2oVMJsjPNQ8o3r4KG3X9lJ3Rdk+FAJ8x9NUsrGSu/G1hxggfxAuYhRAhpXS5tIsTdKRwmoljC2xMVGPRvlcbCYEk8GMhedj1UlcRxYw== 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: 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 >