From patchwork Wed Nov 22 16:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13465129 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 0DDEFC61D97 for ; Wed, 22 Nov 2023 16:30:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF1C58D004B; Wed, 22 Nov 2023 11:30:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA1A58D0008; Wed, 22 Nov 2023 11:30:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D42A98D004B; Wed, 22 Nov 2023 11:30:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C476B8D0008 for ; Wed, 22 Nov 2023 11:30:36 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 943C881056 for ; Wed, 22 Nov 2023 16:30:36 +0000 (UTC) X-FDA: 81486128472.23.F8C9F2F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf21.hostedemail.com (Postfix) with ESMTP id DA4741C001A for ; Wed, 22 Nov 2023 16:30:34 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700670635; a=rsa-sha256; cv=none; b=PXzQBawuCLP1hitYHqUv7b6LV8zayCyXFL91KT5A+TVQqybq9X74zL87ngE3FDwEogBocq nVEvXgCntB1DCVCrt5kfhfyTXbitTIH2vFuCg93ytIKm7y+C1PC3OaWy3DSvhxIpx9S34+ 2xpP142jO6yN/9xnvglnGQJQPUSdQAY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700670635; 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=ZniqqemjxFxJsmh9ZkolQS/48QSAu/omKPvrAd2nTg44QHMDBEmROwEzvJegoGkofzF2xv U/GSCmWGLN2WLExBGlqSX52+oYfHttElUGdtDuhifIadEttcUsb7vya1DBOXMQwkDp8v9N O8AYxHzMtnxjkS6m6Yuri7z21z4Qht4= 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 036CA1650; Wed, 22 Nov 2023 08:31:21 -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 8A75A3F73F; Wed, 22 Nov 2023 08:30:31 -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: [RESEND PATCH v7 10/10] selftests/mm/cow: Add tests for anonymous small-sized THP Date: Wed, 22 Nov 2023 16:29:50 +0000 Message-Id: <20231122162950.3854897-11-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231122162950.3854897-1-ryan.roberts@arm.com> References: <20231122162950.3854897-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DA4741C001A X-Stat-Signature: 98k1ueeqts5suyn5tqdmqy3iyaa9ajgj X-HE-Tag: 1700670634-876889 X-HE-Meta: U2FsdGVkX19TYCllEfD1wCFUOXOo2lk8xSajsxqghRx5v2W+cFltIBNCTr8UL5+gruLGDzRnQ6iJdUq7Hodwy5/dW3y2xq98BST1Gdr4S7AXaFJTX+Z8vs3laHKKklhVuxjXK1x7EwH++2ERM89OMGaj7+1a/PEVj3pfOtI5X6c1/Bd+c4nSNKk0UpLnn1E/88RDXSKLYlZysYP9HxsQUz3/dQnbJjSm9KGIHs6CyA7NcmW7pE1fh730Bgq10/ku/Xe6ENdA3kA2YOAd6KbLFOwwO7V9c93HHcl8YBTLRXUYv4Nhw8MzObBhxmZaqty5qoRKr83X6mkntLkE8Pjon3KY7AamsmtvK7k1QmL5pgZqzcJ//AskIrRGoTRVq8BBw3TNoPUiBm2YfkqVYAQXPPqCpQsQ0yVv3NsSvfluynStMqI+UmkN2lPyh6aTIEZGru0v/c1CaTP1+bcws8kAdDty0g6gr0mNilZlEfBWegW8fm+WEgOyHjjg9SFYkWpnQc9j705IS8OMAUXhqrIR6y3T26QZr32PyFg6FT7VXgZCn9rpJXcAA2khqCla/7DAgCV9usScoSvnsb96v1Rdux00sh57149zEu9LXoS8hJf0xm4LJWH7HglkdDdGoPTQxf9PaY3FvpXZ8NNgEDLh2q7y4JdSUcDUUSYqCduGyunNbSRXHPmnudB2mdWW5E9x+jBMVXKM9tI/GI5QR/4Yr3rPRo5ZGTYLGzA6Cjfa9SiYQQmJ5guP2K0Ts1Mp0CR/pcqBegi4DeIovhxp2M8E6Ff8SfFff2vpTkf1cmEqv12t41AoRi35W2Bp8YDQcQx63W1ZJsWk9+VNrYMQD5KkcFWFUi5KFbVyhKA+/BCYt88txhYaylH3G4zZJU5yla8N+SCZMfYv/LNNrWQY8jho8x3JXEzLtCKWQhS/XiAFHdBDpjmH3te9c/8HBsqfHDGScfe+3LkFR5JBgJwRgx7 ziWtN6mW nA5SxPaL27gKneW/jrj8EDmdAobcu2YyjurGmjyHMl/MQOC8W//pnflB0zy8RQ2JlinekIdCkpr5zl3wVxO1dUJP+dkyJORbZwBHinb3qUuMyNEiXW/kBmt8SD6qdCBFgyAL1wJT22/RdQoj2sbLUnfD6GhSZEi6lHFhLMxE+tvaFt5gfHdcSSOMu/IsZkCBBIKZLsvzluYQKfD0O5ww1JDVs68v2aQczhstB 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(-) -- 2.25.1 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",