From patchwork Mon Dec 4 10:20:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13478091 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 A6FB5C4167B for ; Mon, 4 Dec 2023 10:21:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40AB46B028C; Mon, 4 Dec 2023 05:21:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 393966B028D; Mon, 4 Dec 2023 05:21:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BE576B028E; Mon, 4 Dec 2023 05:21:16 -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 06C116B028C for ; Mon, 4 Dec 2023 05:21:16 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D6BED160184 for ; Mon, 4 Dec 2023 10:21:15 +0000 (UTC) X-FDA: 81528743310.04.2B3E20E Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf07.hostedemail.com (Postfix) with ESMTP id 0AFEC40004 for ; Mon, 4 Dec 2023 10:21:13 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf07.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=1701685274; 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=ybKh59PJSd5wY1GZp+ExRS4oOOHVXopESADjUovlYns=; b=C639K889MJPGhwMUVQHh6augSVY/dsNdnCI6NvnK6PJwxsMg5rdJ67037RWqF7JedRuReM kTRJaltabTo1/wnVw3TH2U6ApW4r/JfU52wMarmHR3OysxTzPNRskA37dGck1gdBjBwBBQ c9FTBvEqp40uz2gBGJXk/zwIMPshXqs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf07.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=1701685274; a=rsa-sha256; cv=none; b=zXHgjtzFwPVisqm+W2En+v6+YEhQqgvsKjsd0ObeY4qQxyOFToMjO+KdL+w5QhpAB6wvYH FR4noPAoSeJJxzpPcy3VHKpT0kX1uyywQ5xg+qWH/3vdbLlq5ABnP1gv53HAxN1PoFjszn VB27WgRn54uYNsHbnVi05/M5N/7eeP4= 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 7525D1684; Mon, 4 Dec 2023 02:22:00 -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 5E3633F6C4; Mon, 4 Dec 2023 02:21:10 -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 v8 07/10] selftests/mm: Support multi-size THP interface in thp_settings Date: Mon, 4 Dec 2023 10:20:24 +0000 Message-Id: <20231204102027.57185-8-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231204102027.57185-1-ryan.roberts@arm.com> References: <20231204102027.57185-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0AFEC40004 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: jhqqroirypiocwt1b5cmmj9n7t917zgo X-HE-Tag: 1701685273-583472 X-HE-Meta: U2FsdGVkX1+80uQJMk6MparcRXb/xk8SD2UZZr+M+aone+zxa2WO9ZVZ1yidKtapMzWrhuUhbZrjXh87yigiXUgJJYzbXF5fjI32CMUzqQiiTVF3l3bMsMHV58mhArTKhlrZQcBxyOj4AClbe0Gipug1HrykHL2XSlFVdFygnv2Hc+9cgWV2IHTURtLwQWBvczEPk/RuGCRoNzdjR6CvywVqV85pXRA72JAa1iVUIif10SfndIshx6OGlat3bwYx0lA5XuY0YSTkuqklSCpKhUJVOc7rM7hJFMYfZoQPoyiGKfHdTM5DMakbnSFhh/XEkSFZQHismD31tZdM5EhVLVpEwZpbc4VV0exiaDAONjoGlko7kgHGDDRQTAsrMomcn9LKA8aP5yo2skDVRo/fJ/hVcE1N0LZf2hR3U1rYMBucd/j/GQkjUUsJFhsPRF00jNoPyehz6qLRc/onuSYqFdV8MStUMg1HhlFIlndHt6zRdztqZYCV/9c9wnsDRtJNW0Yh3MWOXGAlVuLy1B2t2gibOrzcQwvg7hS7s89i3WEdZE5z+iVIBXOxpSoogmSH710rrIMHsSxiC9H3zn0e3WN3g80PO2WXwXt7vGQI/WzOXa5rs+xphbnP6inApO0V1sodggzSXQbnnPsQzBwj8lNsJmlQKEvpDSpTxbacizaFmEcs57uPC/5Cj/QBHPwyjZKGkVJ3eTMIVVIG7jW/klhf6TpmaNuCBTMviiZ2GwYEQ5V8aZ2cpId+h9Os+/hQXnRdQucTZ2ogOBpOQtuhKRurJC7Wf8uqtGUArCuQbE+y/otzVSmhfP6lAzRPFJZhuyONoYoLa87NCN6uyl0nmEmyH0gtwbRnu3f0gH19SxtsMr7UCENHLhs6xhGQg6eSalYlf78lz+oL7yrWm0FJn2ibHOWWOg4yQ717XozWpOI9xypAuyBI8frsRO3PplgMJK5qKsUBlX0zG+6LE1V 5XwCtFoI WtZuZgH96f8vUso2wZITd0lm0GT+BRwHBTnSpVZAz8+wWgZzsd4oyIwLj1RTI+TkNFFE4cL0Jq450w2u5Tcj13fBEw/FpZ8Tqr1sS/SP5EZDeuI0tTmZFBcrM9gwEa0M+4xNvSxQGTA65xYkJoZcAbfN+XQPH0Y/a76hREAaOR62S61WuOQ+gkxhigeJF1Gkz53YSPhGDxlvL5Tcf3ip9hoMDVdbV+10UEVy81zbOZsmE/qP5LWzef0xIZMtmbaNn+upB3egGW1w0Pnvvn3nraJRO4g== 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(-) 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__ */