From patchwork Wed Nov 15 13:27:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13456681 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 8D596C531AC for ; Wed, 15 Nov 2023 13:28:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DD4C6B0347; Wed, 15 Nov 2023 08:28:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 266C56B0348; Wed, 15 Nov 2023 08:28:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12F716B0349; Wed, 15 Nov 2023 08:28:22 -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 0337E6B0347 for ; Wed, 15 Nov 2023 08:28:22 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C3D4814086F for ; Wed, 15 Nov 2023 13:28:21 +0000 (UTC) X-FDA: 81460267602.03.4E31E88 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf04.hostedemail.com (Postfix) with ESMTP id 1E33340017 for ; Wed, 15 Nov 2023 13:28:19 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.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=1700054900; 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=gx5ezs6T34kipBJF59rbGWkxAd4YqsYNUswT1SDntEEb2mGfG2amZPauLjnBrgPABkOtRA 0jtEtZCp101jjlBXJaxAUmJ5S6GmJs1BmocJYu3b2LyFKp+dOwzqEw0eLQ1AVJBCMwJPDp 7BNbAy5BTmKw1xcsTrJg1MWXrB33Cig= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700054900; a=rsa-sha256; cv=none; b=YELt+LhrXKuunfyTynj5Ht3FHN0qqMpBv5sRwFptte8HrZ09QzCj/hPlrfy8R/ngAJ2CRL aS22XZGu/wuk9hsWDBzCSxQG/ZJfBlKWmo6RZrhCfoEJ5j2MUBMwvmlCZfLKaznhP/Rtiw vDy5VnmtcTysROY8oZqSc7x8g19kdkk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.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 D1B8315DB; Wed, 15 Nov 2023 05:29:04 -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 676053F7B4; Wed, 15 Nov 2023 05:28:16 -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: [PATCH v7 07/10] selftests/mm: Support small-sized THP interface in thp_settings Date: Wed, 15 Nov 2023 13:27:31 +0000 Message-Id: <20231115132734.931023-8-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231115132734.931023-1-ryan.roberts@arm.com> References: <20231115132734.931023-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1E33340017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 1detgw9zo68zda31nu7e4w74banow97d X-HE-Tag: 1700054899-967988 X-HE-Meta: U2FsdGVkX18b0HEG4Ljd67iRXzEYQVu32v9qHFNmpsKjAeLM8xy0q+zfN6tp8j45sFJYJPCqclzXL+EvFhimpdc5Vb2O1RohGG1+mPtKv8pLUbFZ2QUnSER9rRVbT9nXCVtOqWNUfGo6WbyZ1D5Y8ZQSNAQa3bOkMgFo1Kzl2C9z4fHU63iUY4QzYn4+JM4yyUBvhZxQ0XJrQNLP3PI1eFPj+AChuz12SSUIy6E+zBzOs5LO6WwbyeXllfLewk3BFX27S2gFOAUdwjmWsN1eYwHCnxqdTIhcRel4+F3GJTSTuhCUq9xFmX4YSdhT7225ra1PdgTTOR0qGWJZb/aqjjl+MNEzx3zIqbHz5P+Kp8vKCQpLMpQ6nJ7mcNajo0ivH/xyDTdksKtqquJLrG+l/eWoyp2eDb/1c64gHh9ryHzjCF38WGWVAG2dSCglK5ba5RZ+YMBAaDa3deIWU+Q4p8YmvixxrOVoaPKgLD6+JU1ouniQE6bDxQ/yNQz/GLpwu4lol715ZXsydvEPCSCNGwWH9bsbGrm4GyC+0+eov/BAW22PKMu9vl29J49yC/CPkZfFdijhu5EIJRHEgamEb0K/RmR2h3dz4gc+2LlNREEjXlcd0VovlMPMjyDDfCG+K5OImAAYy0dbenLZRcVmEGkLt5YAzU3jS5pLlu5tJhNOJDqpJkMWItycrC9FXTk7qMZNx8kNNFmpHGIkK3ITN9is8rH2Yq+hEbzQnfwrQRMwkofgyFSOgbs2sIPgrQnzyIZ2/xKjum0hZdhhskdmwhQAIzbBkqQxjamLHw4mI0+i/kTeANiZpqZXddxNnk2peigQYnlS132cZ4jr1oYQpjSkDLT+F66WyssiaWZyNIyEZotLq5CgSAcvWE3zmhDg32jcbKQUp7P7/CIyEknwv9AVo1CRrnKjoVc6GTzohZf0Azd4jKY5mT7dMLjeOrkw7CzXxFn5gJlRCExgrrc WlLUpNkR ETODtbnqnFh7nGniWyGMLBurNsOrOpYnB2mqGfGgquj0Qt1K7UT+oso0S3XI3bLcxjqjDlly4HDwiuyFX8ZQM+BdMG1oPU32uy9Z3Df4ufNKaMkTE1j7hay/oRfhKkKs3WG8cGkPpUzZgi6HTC7BzEUldMv/uSAU+sIJyOMMwzPeqW2wYaKGi4vMb8vcljfBewMpTRlsZW6JYgL/D6M3nZo+lkawFqdVWa9uajq6qyOuvjTjnaHVfjAu1WDidHf18iHARncyKmRo4zzw0fgi0rg5QRQ== 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..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__ */