From patchwork Thu Dec 7 16:12:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13483622 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 B6EFBC10F05 for ; Thu, 7 Dec 2023 16:12:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E3B46B00A3; Thu, 7 Dec 2023 11:12:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 493F16B00A4; Thu, 7 Dec 2023 11:12:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30C6D6B00A5; Thu, 7 Dec 2023 11:12:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0E0BA6B00A3 for ; Thu, 7 Dec 2023 11:12:52 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DA7F31C039F for ; Thu, 7 Dec 2023 16:12:51 +0000 (UTC) X-FDA: 81540515742.01.34D1DF6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id 2DEE412002A for ; Thu, 7 Dec 2023 16:12:49 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.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=1701965570; 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=RRRF6G+IFJ61/s33iAZuKqfxwg9QiXK8TCKtFeUPons=; b=egFZ3UX95g/fK3eRnMm7Ylv25tSbJyC8mndDS19LsRKt8cIFPdCXObNk2FtSZ5LJXErBZG 5tphVqq/pSSX9LCY6KnPdT3AnOo2Smk0YlGCjCsTtjGqbObY2KGGoCjAHdiT7tSpCe9ACA GGTgumaYX1VgGAqn27UEihWd/3yajcs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701965570; a=rsa-sha256; cv=none; b=amExxhPhk7PuihrqQP5qkv8lp3fmy6j0/pYMYQ+ilts5Ah0uFIr8yrpIQb4b2sDtxH2YfU 2YE84ZXEU2IQopYGV8LsIaCGd1d51GKzceFO4QUsmqUD2mljRKyxgf/eePMd7j8YkdUVaD Jynu820Ff6yrZf/v7KHHZVZPw3Xh7NA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.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 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 6ABB31576; Thu, 7 Dec 2023 08:13:35 -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 A33BE3F762; Thu, 7 Dec 2023 08:12:46 -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 , Barry Song <21cnbao@gmail.com>, Alistair Popple Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 07/10] selftests/mm: Support multi-size THP interface in thp_settings Date: Thu, 7 Dec 2023 16:12:08 +0000 Message-Id: <20231207161211.2374093-8-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231207161211.2374093-1-ryan.roberts@arm.com> References: <20231207161211.2374093-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2DEE412002A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: cdgqgzz7ygkhpufrkp3mohhfo1z9wyna X-HE-Tag: 1701965569-822793 X-HE-Meta: U2FsdGVkX1+AwyYV4ICAC66C0WAaLfpKrwXX5386s1Pwx42GdohoqUz1yBWZTG/968HQ3jQh0dSLhtB07cYJ0tW7sDrGpS4oZn+FX800fNisEW4NhzRxnjBDv0Rs8mmYKWtB3drHckJwoth9QQ7ygKfAZXz6c7AOX4xnzq9uWKkjvZw8jRkWYMepK/icIHBffGoQt3OgWmaIJGYTj6xh2MEV7C1sysjMgVgvC7uTYWWpWGyvg+JUoxnpvfzXheaVqnJzAZnzVu6oijoyQPHkS7Zd60i2UBfNxx45vuhJHXehS/H7Ybw6n+Sb+nHIQeVG0n399miH1oYTllX8VSzruuVX8kQBZBgX2/020CwVS1duohxO1y99jBOC2iKCLik4IMGhh9lJ1UnSfEwlZj2mJZ8GlWnkPJN76JKzwiGF1bD6jLEGag04LcwG0CMpEUWQ2iyK4Z00oQMhWvfhDR4bfijzA4bttWjKjvrXyIsADOuZFnL9BWvoYz+U0GYTQhCV4QW/cPpFKyzRcODxpaC8CefsHWwl+2/x6mOH94HmBMajolwmZKgLvPNCH1EupTMFJs/tJpF2n7wDp0HwzTO7z5cKD9ZvHTrCD/1unFiGeItRi6NLzuCPpgIT5sDRnQu9Xl2Q7YGf+7xSDV6JCqDjpCnpmodAHIPKwbX09jHmsSFKSKPVkdEBDEY4wtNXlGhT5SElFuiCwQL+Dg/J3Sq7b7WGTkvmznl4Sp8a+jRoc8RTYXZd71r7auUeZl6NUrwNYlSPMUrGaSqSP2yVClAS26MI9ZgjEaNCkHK48cNJuMzR0MJx1+0yXKpAbtK5KUsY15tWjBJmlJBAsW/NiSazQQ1TDGBcEDiekJsoFewobiIrF/IRBDLfW1mP/r88uF4JcSA3NDhDXl8EGhEbE0d9zmp3O5UKvtuI7V07puryfzj11seD4fe+OFrfyaI9tbokX91FTDkgsbT63OYOOo6 VlHptVcQ +Q/o38i78YsY6TCwYKs9kJON2gIancb3VXKtXRKgGEj6IJ4xMmr3jzfM7TN6QmQshYXWjUK127xbh3SETNvpvMbWrAhLocjPx928EbxD3KObYloR8K8Biw0Ulo4pEVZZHuYthggBL/cO5J3j6CM0J80avuOQfq43uqHKoXqD7hwNcdwKQK0qxn8POoKXWbuk8rtDutZQGr+cHCZTS1ripTp4TLZCYeBYBn7WbnsUbvic2MTefXY7oe6Z327USw7XgBC8/AyMLcVW/t95MuTdoYaCiUdeAETeOi7NBHGm2Mm1JGlwo02I6fz5FuX5A0w9FDWGM 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: Save and restore the new per-size hugepage enabled setting, if available on the running kernel. Since the number of per-size directories is not fixed, solve this as simply as possible by catering for a maximum number in the thp_settings struct (20). Each array index is the order. The value of THP_NEVER is changed to 0 so that all of these new settings default to THP_NEVER and the user only needs to fill in the ones they want to enable. Tested-by: Kefeng Wang Tested-by: John Hubbard Signed-off-by: Ryan Roberts --- tools/testing/selftests/mm/khugepaged.c | 3 ++ tools/testing/selftests/mm/thp_settings.c | 55 ++++++++++++++++++++++- tools/testing/selftests/mm/thp_settings.h | 11 ++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index b15e7fd70176..7bd3baa9d34b 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -1141,6 +1141,7 @@ static void parse_test_type(int argc, const char **argv) int main(int argc, const char **argv) { + int hpage_pmd_order; struct thp_settings default_settings = { .thp_enabled = THP_MADVISE, .thp_defrag = THP_DEFRAG_ALWAYS, @@ -1175,11 +1176,13 @@ int main(int argc, const char **argv) exit(EXIT_FAILURE); } hpage_pmd_nr = hpage_pmd_size / page_size; + hpage_pmd_order = __builtin_ctz(hpage_pmd_nr); default_settings.khugepaged.max_ptes_none = hpage_pmd_nr - 1; default_settings.khugepaged.max_ptes_swap = hpage_pmd_nr / 8; default_settings.khugepaged.max_ptes_shared = hpage_pmd_nr / 2; default_settings.khugepaged.pages_to_scan = hpage_pmd_nr * 8; + default_settings.hugepages[hpage_pmd_order].enabled = THP_INHERIT; save_settings(); thp_push_settings(&default_settings); diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/selftests/mm/thp_settings.c index 5e8ec792cac7..a4163438108e 100644 --- a/tools/testing/selftests/mm/thp_settings.c +++ b/tools/testing/selftests/mm/thp_settings.c @@ -16,9 +16,10 @@ static struct thp_settings saved_settings; static char dev_queue_read_ahead_path[PATH_MAX]; static const char * const thp_enabled_strings[] = { + "never", "always", + "inherit", "madvise", - "never", NULL }; @@ -198,6 +199,10 @@ void thp_write_num(const char *name, unsigned long num) void thp_read_settings(struct thp_settings *settings) { + unsigned long orders = thp_supported_orders(); + char path[PATH_MAX]; + int i; + *settings = (struct thp_settings) { .thp_enabled = thp_read_string("enabled", thp_enabled_strings), .thp_defrag = thp_read_string("defrag", thp_defrag_strings), @@ -218,11 +223,26 @@ void thp_read_settings(struct thp_settings *settings) }; if (dev_queue_read_ahead_path[0]) settings->read_ahead_kb = read_num(dev_queue_read_ahead_path); + + for (i = 0; i < NR_ORDERS; i++) { + if (!((1 << i) & orders)) { + settings->hugepages[i].enabled = THP_NEVER; + continue; + } + snprintf(path, PATH_MAX, "hugepages-%ukB/enabled", + (getpagesize() >> 10) << i); + settings->hugepages[i].enabled = + thp_read_string(path, thp_enabled_strings); + } } void thp_write_settings(struct thp_settings *settings) { struct khugepaged_settings *khugepaged = &settings->khugepaged; + unsigned long orders = thp_supported_orders(); + char path[PATH_MAX]; + int enabled; + int i; thp_write_string("enabled", thp_enabled_strings[settings->thp_enabled]); thp_write_string("defrag", thp_defrag_strings[settings->thp_defrag]); @@ -242,6 +262,15 @@ void thp_write_settings(struct thp_settings *settings) if (dev_queue_read_ahead_path[0]) write_num(dev_queue_read_ahead_path, settings->read_ahead_kb); + + for (i = 0; i < NR_ORDERS; i++) { + if (!((1 << i) & orders)) + continue; + snprintf(path, PATH_MAX, "hugepages-%ukB/enabled", + (getpagesize() >> 10) << i); + enabled = settings->hugepages[i].enabled; + thp_write_string(path, thp_enabled_strings[enabled]); + } } struct thp_settings *thp_current_settings(void) @@ -294,3 +323,27 @@ void thp_set_read_ahead_path(char *path) sizeof(dev_queue_read_ahead_path)); dev_queue_read_ahead_path[sizeof(dev_queue_read_ahead_path) - 1] = '\0'; } + +unsigned long thp_supported_orders(void) +{ + unsigned long orders = 0; + char path[PATH_MAX]; + char buf[256]; + int ret; + int i; + + for (i = 0; i < NR_ORDERS; i++) { + ret = snprintf(path, PATH_MAX, THP_SYSFS "hugepages-%ukB/enabled", + (getpagesize() >> 10) << i); + if (ret >= PATH_MAX) { + printf("%s: Pathname is too long\n", __func__); + exit(EXIT_FAILURE); + } + + ret = read_file(path, buf, sizeof(buf)); + if (ret) + orders |= 1UL << i; + } + + return orders; +} diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/thp_settings.h index ff3d98c30617..71cbff05f4c7 100644 --- a/tools/testing/selftests/mm/thp_settings.h +++ b/tools/testing/selftests/mm/thp_settings.h @@ -7,9 +7,10 @@ #include enum thp_enabled { + THP_NEVER, THP_ALWAYS, + THP_INHERIT, THP_MADVISE, - THP_NEVER, }; enum thp_defrag { @@ -29,6 +30,12 @@ enum shmem_enabled { SHMEM_FORCE, }; +#define NR_ORDERS 20 + +struct hugepages_settings { + enum thp_enabled enabled; +}; + struct khugepaged_settings { bool defrag; unsigned int alloc_sleep_millisecs; @@ -46,6 +53,7 @@ struct thp_settings { bool use_zero_page; struct khugepaged_settings khugepaged; unsigned long read_ahead_kb; + struct hugepages_settings hugepages[NR_ORDERS]; }; int read_file(const char *path, char *buf, size_t buflen); @@ -67,5 +75,6 @@ void thp_restore_settings(void); void thp_save_settings(void); void thp_set_read_ahead_path(char *path); +unsigned long thp_supported_orders(void); #endif /* __THP_SETTINGS_H__ */