From patchwork Fri Nov 8 04:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13867520 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 67994D5E129 for ; Fri, 8 Nov 2024 04:13:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F6B06B00B1; Thu, 7 Nov 2024 23:13:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FACB6B00B4; Thu, 7 Nov 2024 23:13:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34C928D0001; Thu, 7 Nov 2024 23:13:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F3E226B00B1 for ; Thu, 7 Nov 2024 23:13:30 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B63101A01C9 for ; Fri, 8 Nov 2024 04:13:30 +0000 (UTC) X-FDA: 82761607824.18.ABA6DCC Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf06.hostedemail.com (Postfix) with ESMTP id D272D18000B for ; Fri, 8 Nov 2024 04:13:02 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="waC//g2Z"; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731039038; a=rsa-sha256; cv=none; b=pNzCjmyyzhl1JXOfDuPbt7qG1epADdFzadhSJQYqVBVVHyF0OM7skk0KbrykieRgNtjbME fuk4f/qz4FzXaXsn/bKsouPsVhJc9pFH2M9qQLIB25QeGONEyYxIzKeyaQ+jMzrkGBpnXI xb1NDumdiXdfVXxqLXSHi5O5/gNTFzA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="waC//g2Z"; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 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=1731039038; 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=OAXkgfSC/TSIsttX/eS9fvBNEIFaQACVaW/jTgI39Ao=; b=UMll/v3Ia/phGtXWjcIAVwmc3M+tQ+O0Mtx6gO85T8CeaosBkRQX8RxGnHNewMH36gf81e dwCni+qScgIX6ltg/CU30PrIjYmHaIjTEqr7vGVIjwNOCrLHlYBf1EkBPUOCP/x/Sfhj7g MK0fAjPpWApTkUWWCRvhPHyrvd0YKac= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1731039205; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=OAXkgfSC/TSIsttX/eS9fvBNEIFaQACVaW/jTgI39Ao=; b=waC//g2Z7LcVw7cSIEOwv9vL/4wGocXTrav2+04qF0sz9jy4YcTE6ww31ZSxJEheK2QsKE0r4d1jjuvI3TozIMBeiaubhOtO7585yR4gP/4fCvwSMrT/83NZB/YWWjWvGiL+Ke268xrYdcuiVrys1Gi+xH6RFoEYqzomlpRumkc= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WIxZtPU_1731039204 cluster:ay36) by smtp.aliyun-inc.com; Fri, 08 Nov 2024 12:13:24 +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 2/4] mm: shmem: change shmem_huge_global_enabled() to return huge order bitmap Date: Fri, 8 Nov 2024 12:12:56 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: mnrhfurr35tq5ejzogfpfw4cuibso4g4 X-Rspamd-Queue-Id: D272D18000B X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731039182-345316 X-HE-Meta: U2FsdGVkX1+GMVrvkoTPTMGVbPKg/ogyo+CEdi+QKSzVq2QAqNRiHwjmhkxrGxzYtuHxOCLmhMXsB6YIQmCjaUML6pIkDiPj2aMvo74K+5r+QrOimAIhf9wNjcxeqSbc5enONu9WQl7LeqHXZwqC2puUWHqjMsWro1ZPsBsa1J/c5gcUznoiweYd1zLFSJAUnFp4+TJu9ITdsS6G4/u10YhOMsL9QUrLPjyRptYsLvhGNqLWun7y1U31H/jJmYR3QT4c31hSCDoH8PDPesaxs9MRGeLuA6GOlpAj9VrplXhPXWYzQAVCCKBAIQRDxfrcUsEr+tLpM556At6DI9twcmTgc1jWgUq8rkhzyfHeSa3v/Q63jV8U7ZcfFHtahHdWtNqEOf6bdQwJeWNSflJapWQxCTR7MPZJqku3ntyu5nSkWKdy04CkuDRcOoXae0Am1scVeftsXnQkNSUTtHs9YhCXNoICf/qXyi3KLZRClhYQJFpAze9Sptu+OTduRMkWJxgahf/35khVUFkK4DXJjHuMCsJiTX2b6jLho8XLGMpwDMoepjh54PBhrDGG1sXW7v3pjBctKPrMf8/POG5CE5Fh3RrNsEl4pvWgbw462/vpx14LA5T26WajPr+99lw75fNDfWKpwHD23E2yOBIr8fP6kcjFm0CwxksSR0ijmmIfV9uU6qShuQ7HH5AnlThFIT8jD8QJ82wXbPNRYaPdd6vu12JRyrXRlVdhNxzj0KNGJiAupInWESGVF3EAW6koU++sBRqVYp3BLRfiF96tGtREIPpdQ6h8Dx6siQ0wAaPD1YWNn7zQkPViGnpFEIeGaw1+HkjwBRMFHnJaDvO+zaeIKXcXJZ2Jhs4WfG/sMGIzcY5mIzhVUKgRI5cTmGvRQA0Q5ICfXFG9nJxoQJxfG/HpRTipgr2ioPhY6jxJYN0f8pxSv6+ULTrYPWu6Ud57h96Kz9RMJBQPEiBwFZJ TxrAwPJH Z3a2xk3MKgYdfwaLmbeCo1wK1gQY82tnPEwVOQdZdjdA/P2aOKmymLtwqqCRAJJ6mtgTkBC0+DnmFLiB9ceJJljDCaJWY1duZ69zV9S23C1YCWFuR7+HML2EOE/1v28psIytAG16rGQdY4FffG+kMOTn5ad65/gPrSTv3m3Ob/xkPd5oqk9U8WNjYti5mJ+mllqd0gBX9peW5qp9OKDGW2QKZoWrViAiKNgzneaGq0Xj7gO2NohXRG4/wSHUDUorWIzNLxpUgYzJQo0Qn4KXEaJdwVA== 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: Change the shmem_huge_global_enabled() to return the suitable huge order bitmap, and return 0 if huge pages are not allowed. This is a preparation for supporting various huge orders allocation of tmpfs in the following patches. No functional changes. Signed-off-by: Baolin Wang --- mm/shmem.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 579e58cb3262..361da46c4bd5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -549,37 +549,37 @@ static bool shmem_confirm_swap(struct address_space *mapping, static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER; -static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, - loff_t write_end, bool shmem_huge_force, - unsigned long vm_flags) +static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index, + loff_t write_end, bool shmem_huge_force, + unsigned long vm_flags) { loff_t i_size; if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER) - return false; + return 0; if (!S_ISREG(inode->i_mode)) - return false; + return 0; if (shmem_huge == SHMEM_HUGE_DENY) - return false; + return 0; if (shmem_huge_force || shmem_huge == SHMEM_HUGE_FORCE) - return true; + return BIT(HPAGE_PMD_ORDER); switch (SHMEM_SB(inode->i_sb)->huge) { case SHMEM_HUGE_ALWAYS: - return true; + return BIT(HPAGE_PMD_ORDER); case SHMEM_HUGE_WITHIN_SIZE: index = round_up(index + 1, HPAGE_PMD_NR); i_size = max(write_end, i_size_read(inode)); i_size = round_up(i_size, PAGE_SIZE); if (i_size >> PAGE_SHIFT >= index) - return true; + return BIT(HPAGE_PMD_ORDER); fallthrough; case SHMEM_HUGE_ADVISE: if (vm_flags & VM_HUGEPAGE) - return true; + return BIT(HPAGE_PMD_ORDER); fallthrough; default: - return false; + return 0; } } @@ -774,11 +774,11 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo, return 0; } -static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, - loff_t write_end, bool shmem_huge_force, - unsigned long vm_flags) +static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index, + loff_t write_end, bool shmem_huge_force, + unsigned long vm_flags) { - return false; + return 0; } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -1173,8 +1173,11 @@ static int shmem_getattr(struct mnt_idmap *idmap, generic_fillattr(idmap, request_mask, inode, stat); inode_unlock_shared(inode); - if (shmem_huge_global_enabled(inode, 0, 0, false, 0)) +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (shmem_huge_global_enabled(inode, 0, 0, false, 0) == + BIT(HPAGE_PMD_ORDER)) stat->blksize = HPAGE_PMD_SIZE; +#endif if (request_mask & STATX_BTIME) { stat->result_mask |= STATX_BTIME; @@ -1682,21 +1685,21 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, unsigned long mask = READ_ONCE(huge_shmem_orders_always); unsigned long within_size_orders = READ_ONCE(huge_shmem_orders_within_size); unsigned long vm_flags = vma ? vma->vm_flags : 0; - bool global_huge; + unsigned int global_orders; loff_t i_size; int order; if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags))) return 0; - global_huge = shmem_huge_global_enabled(inode, index, write_end, - shmem_huge_force, vm_flags); + global_orders = shmem_huge_global_enabled(inode, index, write_end, + shmem_huge_force, vm_flags); if (!vma || !vma_is_anon_shmem(vma)) { /* * For tmpfs, we now only support PMD sized THP if huge page * is enabled, otherwise fallback to order 0. */ - return global_huge ? BIT(HPAGE_PMD_ORDER) : 0; + return global_orders; } /* @@ -1729,7 +1732,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, if (vm_flags & VM_HUGEPAGE) mask |= READ_ONCE(huge_shmem_orders_madvise); - if (global_huge) + if (global_orders > 0) mask |= READ_ONCE(huge_shmem_orders_inherit); return THP_ORDERS_ALL_FILE_DEFAULT & mask;