From patchwork Wed Nov 22 16:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13465126 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 3836AC61D9B for ; Wed, 22 Nov 2023 16:30:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE50F8D0048; Wed, 22 Nov 2023 11:30:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B95838D0008; Wed, 22 Nov 2023 11:30:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A35C28D0048; Wed, 22 Nov 2023 11:30:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8C7A68D0008 for ; Wed, 22 Nov 2023 11:30:28 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5AAFA810BA for ; Wed, 22 Nov 2023 16:30:28 +0000 (UTC) X-FDA: 81486128136.15.1F708A6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 586ED1A000C for ; Wed, 22 Nov 2023 16:30:26 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.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=1700670626; 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=c00HuZh8f7EUjjIu9Dd6BGADK5NutdsxCPhz2j3JNic=; b=OlP8VpIaHmM29jNtKXKoyB9nZTI+Wp48frL7OOQ60NBlfeJIhFkIiwikZZKJHoIA2LymC5 8BM/RWqdIR6byzsTpZ85i8u/NYuLceosYEon2MMWTvnp/J86EtZVUdiCWs6Cj2Y60dVLpu 0PS/PdWamff2SsbOEAbG8AKxEdD7Rio= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700670626; a=rsa-sha256; cv=none; b=NJKBY6By9vse4+Rf5u3oLaArB1UlzWFjxMegTjZow1cSrfa9jG397CddUc3K+pKVm6hO4n Erlwe4RpJ8RbdV67lEOLf9MwDtuMdca3bpKHLDmrcsVxZFrluAhK9vbauv8YHXu+CNHtWK tBgBDiwUMcucT0CC8orG1yilWP4Vmhw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.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 8D2FA1595; Wed, 22 Nov 2023 08:31:12 -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 20A5B3F73F; Wed, 22 Nov 2023 08:30:23 -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 07/10] selftests/mm: Support small-sized THP interface in thp_settings Date: Wed, 22 Nov 2023 16:29:47 +0000 Message-Id: <20231122162950.3854897-8-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-Stat-Signature: 4o1oxcmqmj5pafuanmtgs4t6xhtsdebq X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 586ED1A000C X-Rspam-User: X-HE-Tag: 1700670626-760610 X-HE-Meta: U2FsdGVkX19518gA23Bb2nUtwSGE53hyj2caZuOd6iQBLIHco5O454zC1lWiZYRLhmyATFvLe0ss6IjFtuLrb1hGAX/VP619ou6mP8mGl/qLi4Bpe8VnZ25cY/q6BKLEq83gUiuDItQT5F/o/lRP6S08fovfSbe0aPtCKazcBbdAGoUokHCtU+iRZShUx8ufWKcXcaOWHIGtzQ4OgkwWiVP/tDyrgo93krbDMLhOu6xmSl3/FPDMEWAyBbf2mVBrXuEZjG79JPe/yFJz9WC9Bz56m6FrMJAVXmYuAifSEeVlHCj+Vf/6RFaqddNFhiStqMfpHHIai0xv4Qf4Z/qgN1TIqlP5Kq764yHRY4UOSHl8Zp2p+AlAQdvqc8FknxmKSsE4b57sTjWVQr/2C5qj/B0Z03yzyMRGwr8+Fx1ShLDU02ehiuRB7ezMAW8A8XwMFoKOPFlM1jSSPdODvDlQbXwyzmSeF7gstpzz1OUPGiPV0k0CNTZDdfXBCpW1ht1PIx7EZxx1TY7kJweXJUBNKPxPqGY5WKLiG9x0lwBTNq6bfIxBY7g/6Zl0JkIYqQfnsK/fo73Ys4Sz1I9iK6QBgHWqcxqgC/7IHHn5CS4m2st4YHfQULfrOWZLxA/DIc0nqiIPDL7GHr49WxuLQlHcY2f3vKgm8Y4aTCHk0AxiG8uw6lcSRU8tbZT87MDhp1q2mZUWTpiDc8sBjzt3nLUB7Sa1Skgh5cdfE6iAlvJ9pz5GHW6VExoiIcKOw7gGeD6PVwZDSfPePRzyw+t2gs4QQ2EY/Y4xEY50xXNT3rKw5KL14MmpkfacXf0BeR8JlyI1lx/puHkUAI3+4ptUHnNN5UPu0zbt+Aq66+HgIQLY0VxESgZuxKzgJg6Wf9xV1YPplQGolJtLfF0q0+NlTNIUSk31w5flBjw+o3mG90flDiStfDD4+H/6TxwTZVewoXBoQcvQW8ziedeaL4DDvuZ nDXQseLj gaatO1emGNnkyoQ9+Q2LCRHa8pI7E4+lzRqiB5DsKrN6Gl5x3lZRNOUMEpaTqJLEm4aflWemhrHhc/XUu8NsMAxwVVMYqKfU6Zt/6EXz6N+UNOUd7k8TDRbT3MAqLg9MSqy/0ZEd9m17ejaiRighB+Y+UI3gsHtoVhbZzEumN0SBAI03myHqRpeoyDj77QqH7nE/iwu6whROBrLd+mtiasOrOgdONd3SYWYNyxZ5zdZxRrjGuDN/l18Jv8Zve6+oRQ9+29oaEdJ6CvhgIn6/0QLVzZA== 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. 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(-) -- 2.25.1 diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index b15e7fd70176..473ba095cffd 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_GLOBAL; 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..3296995c8e4b 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", + "global", "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..8e71e323546c 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_GLOBAL, 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__ */