From patchwork Mon Aug 19 08:14:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13768059 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 9FDC8C52D7C for ; Mon, 19 Aug 2024 08:15:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D6636B0095; Mon, 19 Aug 2024 04:15:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 436E36B0096; Mon, 19 Aug 2024 04:15:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AF2B6B0098; Mon, 19 Aug 2024 04:15:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0B0346B0095 for ; Mon, 19 Aug 2024 04:15:00 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B92921C4C1A for ; Mon, 19 Aug 2024 08:14:59 +0000 (UTC) X-FDA: 82468284318.01.20E9E28 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf16.hostedemail.com (Postfix) with ESMTP id B0CA118000E for ; Mon, 19 Aug 2024 08:14:56 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pIaJgWaL; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724055241; a=rsa-sha256; cv=none; b=DpHSMUVwNs0uWqBDrByZdJwqyavRH/yuDQih9CE8eZQe5Q2mWTV4WL3PfrQb0TF+ejd6Z6 vZf+wqLajLjDHJmYj3/P742lmUgSvBJTwSC3/gyryioc9haUKJbkgHmERV2f5VFIm1WgCu em3Z9mYgQOiot+J+hwBFXuYjQIZLKow= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pIaJgWaL; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724055241; 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=gdiMhSr9CWuEkkgyNrCFPYAXca4PLn9QlPXLT+JByV/0d0QG3jOfXFYuvRQ8voIvP3gxjQ ISUoFrv5qM3erqnRLzKg3wYXrXEPflGHMU+BMg+Eg/Ycewg6T7yjTkMGT6+qZ++cqJQljl SN2NYZHgUez+J6fBSYqZC4UPgYPvJYY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724055291; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=NETcifOYIb+Yf9TxOqDeY39PaKApxrCiukqpjtRmh74=; b=pIaJgWaLYPkSjsM2fSFfdx9rwuEUuQksJTQJKmAOtW4DrFZ3yHH2Fm2VAiYFObD3N/1xw9Au/tL61a17zqxEyQ1QhA3GVXQYT1nX//vMXfywYv/SNA7FS7JItQbAVQ8ixpGFMOnL0XoSvuKFvOF1pBk+PNVZ5poJh4Dmoexd/6M= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WD9CrJE_1724055289) by smtp.aliyun-inc.com; Mon, 19 Aug 2024 16:14:50 +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 5/5] selftests: mm: support shmem mTHP collapse testing Date: Mon, 19 Aug 2024 16:14:06 +0800 Message-Id: <12ec6a8b5fe51cd17db1a82c3ffa5006d4b22de3.1724054125.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: B0CA118000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fttg6xotkrtz8dmn57d78mnbi8comrsn X-HE-Tag: 1724055296-874144 X-HE-Meta: U2FsdGVkX19kpwylxz25cQbGOUXGrHv7I/IC8SH2ueDhcxxM9qMyY1RFWUsyZFJ+nWUkoezbauIAczir9vXOCTakH7R6AkIbRlYVbWHBM3QH+6llNud5HuwL/9+WZ194uPNXamAnD4Cq67US/eOJ7TOK1IXL8FlKt7DtrLUHXEl9KUmwvSCflH7O5useWAMF1PusJ4EQ8pRStgkHWJt1lKptFhUFkGLLZD3gEwBPRjda4pMHBIUfpsmMajEolDiiX0Jz0wGtLUxHgc7IR+7PEOofcbXx/DZqc5sPhcRjg7uLo6xLXwn5hzDbsG/cPJHx4d13/1KZof/8Ur4CnSFJCahhHOeBWSxRjvfGjXSLWEc1GvHlJ1EduHH44ToxKQxnDo0accBffW0p3V97g2OgXB8LL1MeOeoHdCQ9XSqupdCr7S27KrWvZeUhVmEyIkP+B4Rj2WiWKv+FldaTjsVeAtPhUrn6q1II3tcrvCyLXYTMDgR3tD+nkrUCFmk6XP52j+wfDA12WH8JO7AKk/ea4VJWnCN2xsCWJBGH3SZqS5I4ToxBkFICHpK8UjZSf7rV7/VuMNMM+op3qBUyROB27lNvax8H1VvhiZPwCg7QFVVUG11fz1QXl4Tip1NHzSz1uGWU8ga7FzTAtFLTzBqWZYS/GG0mwLSX/YCd6B3EKPpanPjqEr9vd1Hpfxm6icLynsihqm5QRdJSgFTDFHsihdSjPewno+xqoXTdaIt9kIBGBSRsQ1UBj1BIjNngA3c5ZvTTHnG2XEfvVd3BKcoqFdp+FHAeBdL90m+6tOzSB/ibVlxxTJ9HLYBA17deImbew17bY+m7JD3yaDrD8LWFR8YJBnNzwivi20Jiekeu2Cfx2LhDVct24voZHoazhyqwXtWMgkjhadWYO2P8cXAdM0jvrmCf0FCangtk2sAVwlxGkxrMGeSQcMg5Uq9izf890OhwWITlwV6r4gUfl9p +GtejCPS ZjczOoe1My+0kH7uWMcuSkYQ/KZnYmTCYMVftCwnCkAlBc/sp6uBprDBpUoZcA6AbH+DHokHzRz8R+F8a+EuyBjon2vUEZIl0nS3Ym0U0vxvOJ7E5ZNNxeP4YYQylm99hVhkBhiPtc8Of8mPfFkzJMVnroan6/HFSKc/JjzVuNGb80x6myNTizli8n0BNw37YyFqy6GxNYh8vnEk= 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__ */