From patchwork Tue Aug 20 09:49:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13769796 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 95474C3DA4A for ; Tue, 20 Aug 2024 09:50:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 114B66B009D; Tue, 20 Aug 2024 05:50:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C4626B009E; Tue, 20 Aug 2024 05:50:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECD886B009F; Tue, 20 Aug 2024 05:50:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CB7AD6B009D for ; Tue, 20 Aug 2024 05:50:02 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 530AFC1903 for ; Tue, 20 Aug 2024 09:50:02 +0000 (UTC) X-FDA: 82472152644.01.BB8A2B1 Received: from out199-4.us.a.mail.aliyun.com (out199-4.us.a.mail.aliyun.com [47.90.199.4]) by imf11.hostedemail.com (Postfix) with ESMTP id 0C63B40014 for ; Tue, 20 Aug 2024 09:49:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=kbGM7uKb; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 47.90.199.4 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724147361; 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:dkim-signature; bh=NETcifOYIb+Yf9TxOqDeY39PaKApxrCiukqpjtRmh74=; b=a6tZyhNIy/K8diAP2GeSAoegpxVJYPNNK53NdHmp/Ux1F4R79Qgda1x2BWdRggLGGwf8EO Rc9g9jhG/dXPF+xJbtCEbR8UBDbrMzfOqjbwsWRXklXBgwAsFIdyEYj2ac5U1QxyigdID+ WU7IN5KG2kzVymV2JORIUsMMqnKHGS0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=kbGM7uKb; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 47.90.199.4 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724147361; a=rsa-sha256; cv=none; b=sFBUBQc2A2wlT9rIsg7Ikiy3C49SJP/aynpg1RToK+nKGAZjn9EKvw0ACfuEsCarLLmF4g yehKoYZaXeFRXtQP8Ar/oXlKZlpZaavQlJFzZ8oEpaUwgNBqpuj0Pe23BINy6bsgEfhIIc tR0+kcd2nJ1DM8LZ8lJTCu9BG7lmzPQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724147386; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=NETcifOYIb+Yf9TxOqDeY39PaKApxrCiukqpjtRmh74=; b=kbGM7uKbxeQJwLDFnmM7YJxxLdAEaMfd4WAuliMyaYQcTe81bEVZJxQUKgAl0LcAX7On5qhUuqMDcQ1T/eRcxkbxJY5AgOF4QLqOBoeYI5l5AyiFCO+nbwUAcwTPfxyFpMfs/fJ5XDyU7FaTssjFE6txPv4FSB7aFTIWMsB+hl8= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WDIEwkS_1724147384) by smtp.aliyun-inc.com; Tue, 20 Aug 2024 17:49:45 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: hughd@google.com, willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] selftests: mm: support shmem mTHP collapse testing Date: Tue, 20 Aug 2024 17:49:17 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 0C63B40014 X-Stat-Signature: ohb9qfe67q4j1tc9hu93nc1r7set1j4w X-HE-Tag: 1724147399-164004 X-HE-Meta: U2FsdGVkX1+K9C+G+03KZqG3A1xDABloUHMyosg3XPNBemepHZBqeljq05i/AQDqdBtQjsp6envBnAqKkLSoOXsHAUxsnItqts8hmB7QpPSpdRD5ui1Uus/Gl+Butcc9sf7tfvGUtZddFncbZFlHp76+1UEoioj+8oIFrQ6kALhzv4uFAOVyJeROPAi+uVd+4MOUvtMk01vKvIZ7gd+5C3IlNJPaib/8iSGPS7VwuXFiCqrUhdm5DwKAsZEpJbFFb7Xe0lA6mKSy7VtMA0wfeZlei8eRgtZCTbJ3CfZuQp55QSNtu9m5R6Vp1+sVimXp2wfA1ilHbP1MrY2YXk2GYyj+flYGeIMCPkrDlMcYwsm/S4NfkRDHCPqSqNmwvSsUUGgdyB75HwCPSZQYU93jHXshAWVMRKVDldAWkEqoHOToP7kA+jnGZGmw6PA54Syua2//KkN/7nNlu2FVjV4CLl6Y2JcEpBJWLFs7bwIjz7fsxj/Nz9ErlWmzB+DeoscQ+9wyFGlv0qaALP846I4OnbYvbAOACpptC/sChz9afl5hHUDgdIYI1H4sZH8/AVVe/SGXXb90fwpaAW/WAkWwL8uTnCsaYNvhooTqg21F+ei524pdxyACOyHSCJRKdj9rPL0xdLJdJmNih0JpkC5ge/UqGuITbKo2FU5RzZDilfLSl7dIEEz87CFGKIzpfYJL0k8H/NkLDizd7EcPfqebAC9pSJi6bwzGeJetyAg36zoLGHuUTQKWKWw84C+641RRtPKDDMyf0WyulABF7upP4ZMWljBbKgKzcAWD4MviHXSYWbd3LydGzJ69xFkhNjvUmLCHWw9HuyIsHnrqFHd5WRxfZlkolozUfgWJ5KgPsjQWI2IlZBzw1ynukmKYmjt1xTvKoyYRKijQAQwCI9Edj5odzzTc1Rc3BetGdZk/VG0ctajdjG8TgWGvawJf/968e97X5zaHDBXm2R4kdCb sqp8pbSQ 71uREJRsL8/tD1imbxWwVYhTld67TE8zokZOB1zxU1iKajlJtAt1alVJBNfwAPMF8lJV8hxRJK+q3WgwnvFE1pT6eQ4Lrn1g0VhCs1Jxa8dFi6f8BBOVadPeB+3Li4/OiDWiHekAsJgJpyVaAowFwqcJIdv8Oj7JXAfsHBj8HWfsaQKAGvY7e2zMrNOE8GCa3OwvE7+28V8brsUJIArKL8D6RXBT5QhSqlalWxvY3GgdBAo2sPu0fs8Nm51YElkRyDIFAT2n0qPcnYcQVA1wKL85Ivw== 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 shmem mTHP collpase testing. Similar to the anonymous page, users can use the '-s' parameter to specify the shmem mTHP size for testing. Signed-off-by: Baolin Wang --- tools/testing/selftests/mm/khugepaged.c | 4 +- tools/testing/selftests/mm/thp_settings.c | 46 ++++++++++++++++++++--- tools/testing/selftests/mm/thp_settings.h | 9 ++++- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index 829320a519e7..56d4480e8d3c 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -1095,7 +1095,7 @@ static void usage(void) fprintf(stderr, "\n\tSupported Options:\n"); fprintf(stderr, "\t\t-h: This help message.\n"); fprintf(stderr, "\t\t-s: mTHP size, expressed as page order.\n"); - fprintf(stderr, "\t\t Defaults to 0. Use this size for anon allocations.\n"); + fprintf(stderr, "\t\t Defaults to 0. Use this size for anon or shmem allocations.\n"); exit(1); } @@ -1209,6 +1209,8 @@ int main(int argc, char **argv) default_settings.khugepaged.pages_to_scan = hpage_pmd_nr * 8; default_settings.hugepages[hpage_pmd_order].enabled = THP_INHERIT; default_settings.hugepages[anon_order].enabled = THP_ALWAYS; + default_settings.shmem_hugepages[hpage_pmd_order].enabled = SHMEM_INHERIT; + default_settings.shmem_hugepages[anon_order].enabled = SHMEM_ALWAYS; 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 a4163438108e..577eaab6266f 100644 --- a/tools/testing/selftests/mm/thp_settings.c +++ b/tools/testing/selftests/mm/thp_settings.c @@ -33,10 +33,11 @@ static const char * const thp_defrag_strings[] = { }; static const char * const shmem_enabled_strings[] = { + "never", "always", "within_size", "advise", - "never", + "inherit", "deny", "force", NULL @@ -200,6 +201,7 @@ void thp_write_num(const char *name, unsigned long num) void thp_read_settings(struct thp_settings *settings) { unsigned long orders = thp_supported_orders(); + unsigned long shmem_orders = thp_shmem_supported_orders(); char path[PATH_MAX]; int i; @@ -234,12 +236,24 @@ void thp_read_settings(struct thp_settings *settings) settings->hugepages[i].enabled = thp_read_string(path, thp_enabled_strings); } + + for (i = 0; i < NR_ORDERS; i++) { + if (!((1 << i) & shmem_orders)) { + settings->shmem_hugepages[i].enabled = SHMEM_NEVER; + continue; + } + snprintf(path, PATH_MAX, "hugepages-%ukB/shmem_enabled", + (getpagesize() >> 10) << i); + settings->shmem_hugepages[i].enabled = + thp_read_string(path, shmem_enabled_strings); + } } void thp_write_settings(struct thp_settings *settings) { struct khugepaged_settings *khugepaged = &settings->khugepaged; unsigned long orders = thp_supported_orders(); + unsigned long shmem_orders = thp_shmem_supported_orders(); char path[PATH_MAX]; int enabled; int i; @@ -271,6 +285,15 @@ void thp_write_settings(struct thp_settings *settings) enabled = settings->hugepages[i].enabled; thp_write_string(path, thp_enabled_strings[enabled]); } + + for (i = 0; i < NR_ORDERS; i++) { + if (!((1 << i) & shmem_orders)) + continue; + snprintf(path, PATH_MAX, "hugepages-%ukB/shmem_enabled", + (getpagesize() >> 10) << i); + enabled = settings->shmem_hugepages[i].enabled; + thp_write_string(path, shmem_enabled_strings[enabled]); + } } struct thp_settings *thp_current_settings(void) @@ -324,17 +347,18 @@ void thp_set_read_ahead_path(char *path) dev_queue_read_ahead_path[sizeof(dev_queue_read_ahead_path) - 1] = '\0'; } -unsigned long thp_supported_orders(void) +static unsigned long __thp_supported_orders(bool is_shmem) { unsigned long orders = 0; char path[PATH_MAX]; char buf[256]; - int ret; - int i; + int ret, i; + char anon_dir[] = "enabled"; + char shmem_dir[] = "shmem_enabled"; for (i = 0; i < NR_ORDERS; i++) { - ret = snprintf(path, PATH_MAX, THP_SYSFS "hugepages-%ukB/enabled", - (getpagesize() >> 10) << i); + ret = snprintf(path, PATH_MAX, THP_SYSFS "hugepages-%ukB/%s", + (getpagesize() >> 10) << i, is_shmem ? shmem_dir : anon_dir); if (ret >= PATH_MAX) { printf("%s: Pathname is too long\n", __func__); exit(EXIT_FAILURE); @@ -347,3 +371,13 @@ unsigned long thp_supported_orders(void) return orders; } + +unsigned long thp_supported_orders(void) +{ + return __thp_supported_orders(false); +} + +unsigned long thp_shmem_supported_orders(void) +{ + return __thp_supported_orders(true); +} diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/thp_settings.h index 71cbff05f4c7..876235a23460 100644 --- a/tools/testing/selftests/mm/thp_settings.h +++ b/tools/testing/selftests/mm/thp_settings.h @@ -22,10 +22,11 @@ enum thp_defrag { }; enum shmem_enabled { + SHMEM_NEVER, SHMEM_ALWAYS, SHMEM_WITHIN_SIZE, SHMEM_ADVISE, - SHMEM_NEVER, + SHMEM_INHERIT, SHMEM_DENY, SHMEM_FORCE, }; @@ -46,6 +47,10 @@ struct khugepaged_settings { unsigned long pages_to_scan; }; +struct shmem_hugepages_settings { + enum shmem_enabled enabled; +}; + struct thp_settings { enum thp_enabled thp_enabled; enum thp_defrag thp_defrag; @@ -54,6 +59,7 @@ struct thp_settings { struct khugepaged_settings khugepaged; unsigned long read_ahead_kb; struct hugepages_settings hugepages[NR_ORDERS]; + struct shmem_hugepages_settings shmem_hugepages[NR_ORDERS]; }; int read_file(const char *path, char *buf, size_t buflen); @@ -76,5 +82,6 @@ void thp_save_settings(void); void thp_set_read_ahead_path(char *path); unsigned long thp_supported_orders(void); +unsigned long thp_shmem_supported_orders(void); #endif /* __THP_SETTINGS_H__ */