From patchwork Tue Nov 12 07:45:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13871829 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 BC7D0D41D65 for ; Tue, 12 Nov 2024 07:46:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C26D6B00E7; Tue, 12 Nov 2024 02:46:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 871E96B00E8; Tue, 12 Nov 2024 02:46:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 712836B00EE; Tue, 12 Nov 2024 02:46:05 -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 456C96B00E7 for ; Tue, 12 Nov 2024 02:46:05 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E3F8EC049A for ; Tue, 12 Nov 2024 07:46:04 +0000 (UTC) X-FDA: 82776656592.20.0DBD1BC Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf28.hostedemail.com (Postfix) with ESMTP id A2C09C0011 for ; Tue, 12 Nov 2024 07:45:20 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RijQOClj; spf=pass (imf28.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 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=1731397421; 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=mOCJluRojGIhiFhKxbeJdF6tM55rkRyZI48QBIuEF6A=; b=vCj77djPxo2A5sXamYEpoJon69nBiFCWP9RnX+RYl0wAz9LZsNCAPEaZDJa8Wy7W/iUmYI NgUyvzU354s1Zx7ccrplyHk5RNwZnLzFS03+D8r0K6vl4izncnZ8h3xhTJrAwVoGAHA5aV bZnrnKlYx0+gpiPEXk/MDSPiHC2uoMU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731397421; a=rsa-sha256; cv=none; b=IKxLAKb255wIP6hTE1FHPnQZOaQ0CGJBheBFHO0NGZp4t0SDjo/mszO8tDFOxoNvb9sbCi VOM5acHSlAtLJ1u1F/5MI9LpjZeHC1V7zIVenX0wqJfSHVz397KpRBYfWktTpY70H/idUE uLIrUrkwvSfmE/Yl6bDbvSMlTI6bZEM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RijQOClj; spf=pass (imf28.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1731397560; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=mOCJluRojGIhiFhKxbeJdF6tM55rkRyZI48QBIuEF6A=; b=RijQOClj4iHpEULXd41QvhBbOxNvwNxshECWy3k7mFeJJNypwLek3QpQxu3YaEbKNrl2mSnz2K9+qtZebhihidTeHx80o3DBka3B11Xl2k1fXSTUIxXqVIWVdVeBen56HkLntucPpsdHcZmvlYAdBiF4tHVuIRRLx6fUpB+zSnQ= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WJGC0DF_1731397558 cluster:ay36) by smtp.aliyun-inc.com; Tue, 12 Nov 2024 15:45:59 +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 v2 4/5] mm: shmem: add a kernel command line to change the default huge policy for tmpfs Date: Tue, 12 Nov 2024 15:45:51 +0800 Message-Id: <64091a3d5a8c5edb0461fae203cfcf6f302a19ce.1731397290.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A2C09C0011 X-Stat-Signature: ctdutxmmgtpwenmif4jg9wpor4bzaj99 X-HE-Tag: 1731397520-706037 X-HE-Meta: U2FsdGVkX18SIk86YfcVSyp9QLRYkJPbGI8R5QUnnVTLz4XjCNlfg51R4aAxV9Miv3IkUy7JUew2onE3XwWzdZb1PwhGxN+TVkattqzqxrzgVQZYtKebs0zRzaF5o4rSS52EBEN60lWsU0uzqjC/pmUK8o0k52NP4OnxxPaQehMvj/tiJbi7O2VejmrPVhOdn0gH4tpj5R+kP2OMVOwdfeXdLeStvizEQjnNcQmsDY4oKU3hxtcNwLdcnDgi2YKGXCbyJISjYmQhduA5cREuxhc6VoZEwzXur6aQKeQxr3FIeWG5oT8sKSnjjdWnOnJKv/WoWAfX3FvH1MG1be3CsT8OxPOyvWlKT+IIaibSpJQnoRzqXJJ9gMxCdK5xro3KZTbGGd4gkmu4TZNJIbsNWeZ1nubXZbrfd43uoaw3MCR2/pEaHp2hiyKmLlpXkE2Vut5RCGBOKNweJLn/0CLoOzNkyfjMlF7ntTIz9uJIxElcWugsKL43Jnx54UO00QNZDxNmI8E77yDt1jDnjwUykjRKWnTJL3KlSkfQJArnYzcbyKlKdlNCqpmWO1vU3MixiJhoYq6ipdcaf7SdEEAyobwEDRUdDRqEwwQYJvCyn6jwydjZm19Bk84BVJuLIZ4xJkotg8KJ0NNdaQRnrNsTMdYb4mGIiXDNaWyrdRKdgtmBW1vq/y+JbYZr9A6OtKxY/C3HatZvB6l3/ZdfQRbZXHowXZh8GfKBzRMgwzX300ao76abnuB1li5cPilG/jeAYaa3IV79cdk41QpMTo/I3zIHOcRSPE/wbOVKB9sUryXa8IgueHvCzRu2O5P/y9H04Qt/5yinRhipy3pXZnp9wk6NdXuFiRSP2icv3aN4SJnxa4O0sl1O8TkM68lVltVrA4BZGuZdiIRXP/87TBeVqgseoT874qeTrOmlvJuJpdhHXhszsKCpNDTq2Xsfp+vTHFQWFAAPd5vxo5Nn0RR iUF6meHd 5lO1DRQjUBLkrMmd7Ke1o0OtUM28SPPIPgF2rPknPka1hI+orGaLX7JEFkj4rpa/rnbFSSRjLZzFYYl8+slefECoF1e11g3eDiwcln/rL2DdeuyvvDIBBkreKZYGI3AT+Fag7nZSn+zDqakmS5sJatMMnbH9GTAVTjMOgeXlSTQlyHJ0vPRrblK2dnSNYuI7OfSB7s5iZDSs/1N/Dr+KJ3d5BCUxBKpOlQ8QppsyuMZgQqWOVoutxrvGDndiq9xu3SEW6 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 'never'. 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. 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 b48d744d99b0..007e6cfada3e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6943,6 +6943,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 a3203cf8860f..021760e91cea 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -548,6 +548,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. @@ -4780,7 +4781,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; @@ -5259,6 +5265,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) {