From patchwork Thu Nov 28 07:40:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13887736 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 35954D690E3 for ; Thu, 28 Nov 2024 07:41:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 516D56B0085; Thu, 28 Nov 2024 02:41:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 267B56B0093; Thu, 28 Nov 2024 02:41:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F14396B0098; Thu, 28 Nov 2024 02:41:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AD1876B0085 for ; Thu, 28 Nov 2024 02:41:04 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 61D2E1A15AF for ; Thu, 28 Nov 2024 07:41:04 +0000 (UTC) X-FDA: 82834707564.02.3655D4F Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by imf04.hostedemail.com (Postfix) with ESMTP id 784DA40004 for ; Thu, 28 Nov 2024 07:40:54 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=VZi5KW16; spf=pass (imf04.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 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=1732779659; 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=UjYAYqlkSGfPZJ/FlT3GkxA+JCX542ZQmJh945HHSHc=; b=s/8e5wftI7Q28jvGqtpB/DSUJ47pcSemdXapqPxIz+qWHNBjfk7M6dc/zbn9CydOrkyRDE 9kDLzytuQ/gHakoZeD+FSob2YuwRFX32Tb1DXhb8GWVEdyhY1Q/4RVsqpofcaovyeFWsCg 3ovOs00VstvnolZBiPhIL7n1C6mt8TA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=VZi5KW16; spf=pass (imf04.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 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=1732779659; a=rsa-sha256; cv=none; b=CpQA1naO1RkEjJfRahEYozh1hJJ5cAkvGLdhrFSmHZTq1yTfDM4fHPEA1TUpxdmq/cexqq Wvot+L0LmCv22krKK4v2Lu8lrJEsfU7FQHM9nUfwLhiU3hvGYxvFNdyBilwS2pv+1Yu4tG OAuLmfaw4cphhmxfa3zrj7yPAb/JDA0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1732779659; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=UjYAYqlkSGfPZJ/FlT3GkxA+JCX542ZQmJh945HHSHc=; b=VZi5KW16nfnP/meeoupv4HZEf3oQKHma8eZykUmqdysyawBens3s5v63TdskS+LhxBPGFtcxTvGTby5ix/BifNVEqqJ9QgG+48xNbLwzIIX2aPCCV5vW14evxv8PF1qUo+e3Q5vAuJDfe6hUecH0mbu+thPiLO+HKDqVHuw39R8= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WKP.Wl-_1732779657 cluster:ay36) by smtp.aliyun-inc.com; Thu, 28 Nov 2024 15:40:58 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ioworker0@gmail.com, da.gomez@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/6] mm: shmem: add a kernel command line to change the default huge policy for tmpfs Date: Thu, 28 Nov 2024 15:40:42 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 784DA40004 X-Stat-Signature: boqfpf75z5cfkrstyfcmnkshbss3gayk X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1732779654-170581 X-HE-Meta: U2FsdGVkX18KTB/X8wrrmzaDNE847AHiuxo8JRi48MS/5kbrHfXLEpYNfvd02FNpzocEPVwEC0IhXYNot6BZkr56E+FNo8ImJF9XE1L59Wk4YXvTbEFoXf4ZwzDEF9b/wyevnBDU4yZkIfDV2D0WD0lahFRfU8oMnUnFCQ2JXa3MSu5wX5jJmQfOvnY2JLmv+OYlZpUexOBLHK+KI633tCBwhbmzGI96cVI3Q++fpuLMUDvFkL/aO/7Ixq+5IXL6s4LjOSBGCfj2fDJ24Ro8l7hl4v4pejoXdN2CIoa/j9e10d/2FsHmqcUhVh0I5tzvV+j/lTuUz/8eh+XhlswZGGPa+7TiwQUKdmHQeX+9j8iJ7Gl1SuJtbMbT8hzQJr+2hjJ36xZh+gTZ0PV+SY+72c8Bru+5w87wASCdfr/OcKtoFvDWtJ7rRSQTvbA4rImSqUKD1totIYHieaNPlY4I+pQAE4SnyiOTwn8V8EWBD1nhhgzI1j9UZOEaX7haGb9BKdkcnP6PrvHcTkwpmDj//75ir0i9W8L2d/f58N1j6HTW/04fbG7iUiaiQZorhtROIZBWCKOX08Q2Y2uQJkZ1RELqTYpkTp8Q1JD2dCzS9Cpav2i6nRsBHtfEaf6jfp8kXsqrHW45J1bsO9aFW0pokKJfv/dSZ+nRQ047Omx1aC7roe9ZFcNTyHQYOxHLquKz9rRYB2J8Dt/hQYaz+e+pAXClIp91d7Gm7LAEIKHwyvtBH+yLorjfuOmLmrJGK3zKHwBaG4FOTbDhKf9mqQ1HS3Ac6SkbFQYalC7vomeaR0nE88P6P4Rra3BLZHVOxV13+pb+WQD9By7Pp2VpF+KQeAx02qX3/ql/vw6h2FHYv7kSyFbWNKCRg05Vs4d8Q9kQaRmJghOGdogGmot9XRA0irszXcRL/6LJUFMpT75XCfi4VYhjzXqRVg0kz0B+OG5tvDIs53/K3ZYT/mshxQP kO5j0o1a O24OS158mEZ89ecq8bEJIA2f1ii2ol/o/HseLfIbEkfyVkYusctSH6jIxvo8z+cyUIAP29WpbwCo2bIdRLZY3QMpjyf9QolNgFNd3HvixQgv6xTLj//Ghrj6z9L0zgn0YL33/6wf4DX3V3KMNQDC4aD2DTltqji4xOJNXxjeggtrRdouuBOqpnBPnzzHICNqLSxndM+rTA0Ikz+cFaeLtbOGWqFWF0RAw3RBHz3UT6z+fVoN4Y44QW9RO7TObsw8BtiZrjll4Uusxqwx7g9Hzd29m3EPdN37172r18IT4nqKx/GrrPLNGKfoLNw== 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: Now the tmpfs can allow to allocate any sized large folios, and the default huge policy is still preferred to be 'never'. Due to tmpfs not behaving like other file systems in some cases as previously explained by David[1]: " I think I raised this in the past, but tmpfs/shmem is just like any other file system .. except it sometimes really isn't and behaves much more like (swappable) anonymous memory. (or mlocked files) There are many systems out there that run without swap enabled, or with extremely minimal swap (IIRC until recently kubernetes was completely incompatible with swapping). Swap can even be disabled today for shmem using a mount option. That's a big difference to all other file systems where you are guaranteed to have backend storage where you can simply evict under memory pressure (might temporarily fail, of course). I *think* that's the reason why we have the "huge=" parameter that also controls the THP allocations during page faults (IOW possible memory over-allocation). Maybe also because it was a new feature, and we only had a single THP size. " Thus adding a new command line to change the default huge policy will be helpful to use the large folios for tmpfs, which is similar to the 'transparent_hugepage_shmem' cmdline for shmem. [1] https://lore.kernel.org/all/cbadd5fe-69d5-4c21-8eb8-3344ed36c721@redhat.com/ Signed-off-by: Baolin Wang --- .../admin-guide/kernel-parameters.txt | 7 ++++++ Documentation/admin-guide/mm/transhuge.rst | 6 +++++ mm/shmem.c | 23 ++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index dc663c0ca670..e73383450240 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6987,6 +6987,13 @@ See Documentation/admin-guide/mm/transhuge.rst for more details. + transparent_hugepage_tmpfs= [KNL] + Format: [always|within_size|advise|never] + Can be used to control the default hugepage allocation policy + for the tmpfs mount. + See Documentation/admin-guide/mm/transhuge.rst + for more details. + trusted.source= [KEYS] Format: This parameter identifies the trust source as a backend diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 5034915f4e8e..9ae775eaacbe 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -332,6 +332,12 @@ allocation policy for the internal shmem mount by using the kernel parameter seven valid policies for shmem (``always``, ``within_size``, ``advise``, ``never``, ``deny``, and ``force``). +Similarly to ``transparent_hugepage_shmem``, you can control the default +hugepage allocation policy for the tmpfs mount by using the kernel parameter +``transparent_hugepage_tmpfs=``, where ```` is one of the +four valid policies for tmpfs (``always``, ``within_size``, ``advise``, +``never``). The tmpfs mount default policy is ``never``. + In the same manner as ``thp_anon`` controls each supported anonymous THP size, ``thp_shmem`` controls each supported shmem THP size. ``thp_shmem`` has the same format as ``thp_anon``, but also supports the policy diff --git a/mm/shmem.c b/mm/shmem.c index 54eaa724c153..8a602fc61edb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -553,6 +553,7 @@ static bool shmem_confirm_swap(struct address_space *mapping, /* ifdef here to avoid bloating shmem.o when not necessary */ static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER; +static int tmpfs_huge __read_mostly = SHMEM_HUGE_NEVER; /** * shmem_mapping_size_orders - Get allowable folio orders for the given file size. @@ -4951,7 +4952,12 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) sbinfo->gid = ctx->gid; sbinfo->full_inums = ctx->full_inums; sbinfo->mode = ctx->mode; - sbinfo->huge = ctx->huge; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (ctx->seen & SHMEM_SEEN_HUGE) + sbinfo->huge = ctx->huge; + else + sbinfo->huge = tmpfs_huge; +#endif sbinfo->mpol = ctx->mpol; ctx->mpol = NULL; @@ -5502,6 +5508,21 @@ static int __init setup_transparent_hugepage_shmem(char *str) } __setup("transparent_hugepage_shmem=", setup_transparent_hugepage_shmem); +static int __init setup_transparent_hugepage_tmpfs(char *str) +{ + int huge; + + huge = shmem_parse_huge(str); + if (huge < 0) { + pr_warn("transparent_hugepage_tmpfs= cannot parse, ignored\n"); + return huge; + } + + tmpfs_huge = huge; + return 1; +} +__setup("transparent_hugepage_tmpfs=", setup_transparent_hugepage_tmpfs); + static char str_dup[PAGE_SIZE] __initdata; static int __init setup_thp_shmem(char *str) {