From patchwork Mon Jul 22 05:43: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: 13738278 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 1DC53C3DA5D for ; Mon, 22 Jul 2024 05:43:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E89EB6B0082; Mon, 22 Jul 2024 01:43:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E391C6B0083; Mon, 22 Jul 2024 01:43:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD9E36B0088; Mon, 22 Jul 2024 01:43:32 -0400 (EDT) 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 AE1A66B0083 for ; Mon, 22 Jul 2024 01:43:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EAE711A1422 for ; Mon, 22 Jul 2024 05:43:31 +0000 (UTC) X-FDA: 82366296222.02.F31DD75 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf25.hostedemail.com (Postfix) with ESMTP id 6D74AA001A for ; Mon, 22 Jul 2024 05:43:29 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Dt2KRBPF; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 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=1721626975; 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=J5dcVB7jyKKfrkmzqLedgx6fPLHuGxUqgTPplR6Z9pA=; b=Hwk5rMIoQhZs6AEOjCq7uekfRBVtzyKrj5+xArhxtQBXZARfsLMs6KyF2i/vy0qQiTJ4aJ /GNm5iPfDA5lIw/NlKE0/ZZgC/WrySK/koaU/LFNs5uLEHcLv19QuWf84Ho9OIGgg9EX2K pYkqcmqyK8v8h/0TkpKWt7/A+d4aO14= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Dt2KRBPF; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 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=1721626975; a=rsa-sha256; cv=none; b=sFoKaJJ8LBMJjngaf1vPCxwYjbGRq9uXdEUmUrxAekbS/Iu89pVOtpRSpefaBbFbvcHFkr e2uks44FKV0+8KZtPe04HO5jqS99SrGeDpZfiMt64E+LyV1J9anqjuLrI32onl7izcPPN5 TaVmRyfP51NB4ll0GxaboHvj21r1X5w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1721627007; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=J5dcVB7jyKKfrkmzqLedgx6fPLHuGxUqgTPplR6Z9pA=; b=Dt2KRBPFFzjXQiniXmtD4/4SntKWSTF+Kg0sF+BfgF4WyXTmpX+vC6ujNyGIwbiC9t7q5cg2WiXEohzAujYTDwQ6wCuVSWj/unON+vUPY2E74JM6rFiux7vPxK33C6xSOnhRn9KXL2XKcZ130QjaGFrs4TFiVJRvtp5a8Lhpby0= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033068173054;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0WAyvGdp_1721627004; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WAyvGdp_1721627004) by smtp.aliyun-inc.com; Mon, 22 Jul 2024 13:43:25 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ziy@nvidia.com, ioworker0@gmail.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/3] mm: shmem: simplify the suitable huge orders validation for tmpfs Date: Mon, 22 Jul 2024 13:43:17 +0800 Message-Id: <965985dd6d322929d78a0beee0dafa1c2a1b81e2.1721626645.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 6k11hkozps3wekytfroxcgc367xr9nqr X-Rspam-User: X-Rspamd-Queue-Id: 6D74AA001A X-Rspamd-Server: rspam02 X-HE-Tag: 1721627009-812105 X-HE-Meta: U2FsdGVkX19g+lI0NO/pCfC7A+q7a3wQVezvS1dQWwdcDfWS6zrF9XPkF1RvB+SIXCoHadosJ8XeEvXEvpD/0Ebn1UiAf5FNax0PChpL3k41HjZJaBSahUEWkz1NQozfKoukBdh/X/Oj/Rr6lNH/lCJe0FKezGlUuBJctRhggeeTeozROindsll7f9puGhkR/GsnX5VhCtmXYMDAfxHzSqk9C+3yowmXnz754uKtn18GMZyW8bZqmRZcww+Rdpc6DKsOIsuXPMbH5QVWcunYkXzakxVXOgaBufLtB2JHnZ1Bh9gl8f87D77oufJJfAXicR/tn8vdRuZNWRMe9n8NcPAecmGWFNaAxw6AJqBe2i42bUXMlb2cfzt+dz0lE84xg3tLeHXa1Bq06riBQx0Qba/l8TCtjFpgiNNNHiwfzt2UcYrCiAl09ELgdHjnSJ5HAl7M0A3yRYDkHSHkbZhx0V8p3VHk5LlesyFIX5biBoOR4mSwoHbTXHMy2Pfvihf3e3cpFdknYwVVovgCfKP1n7udXBcD5EmIJUdRUFOhT5FvcWsXVaQQqP0z+JE35NsKt8CrF2SwmnAwxGkViN3PKGKA/SX319MGcyMffforndox6wDn9s/tvv9gHrRNEIQ/VErrsb06JejKF8S0j0jOIFV/BurrOJLQf29+S9wgoo7d5vUzSHv27jrntJKcl9T+PWFIEM1xQk3hF4z2werygw7jP8mabXvjVcUArHKE860hxBMG9V76eAZN2a8YPVPXjK0UUXatdppHO1RAmBE8XE7R5l7CD01joUoEAthqWtKqkSscbAdtbFuq+QSB5wYWeixmlIdGkDQ4vuZ8Cah+CUnT1YYsH9KFRBkWpkwqtVH2XTUOL43T1aJfuJTbbsmlKB7cMc43syG240cZ6zRBhtrjwzhSNWsC+PQ8oy+EjJrFDrz/lFXWize4qHwEC0OEgrQ2/GVOIAuzZle+eUb aQ8zvZ24 R8XZ1rIxdjc67jKG03RyH05ev15kR6WiHMHkrITM6Osz9mz4tckN98Q4cuAb9EEpP4ZJPyOnn2E3yKXBTrZxID7dwh8qWiHUd4cM+luf3xw1cvCZhfrqGAE+8bVhNpe35p+Gtm8Okn8v4wgQEHWh2EhrSMgx/43w+79ATKIpTD9BERNBQMz4PkKsGlZOlG9mQ92C2GNvFPuy8pQ6tTKRE7GJaO0l9AliFLdpVsG4GNLjlI1utHl46xfd1VIQwbsuITcr/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000010, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move the suitable huge orders validation into shmem_suitable_orders() for tmpfs, which can reuse some code to simplify the logic. In addition, we don't have special handling for the error code -E2BIG when checking for conflicts with PMD sized THP in the pagecache for tmpfs, instead, it will just fallback to order-0 allocations like this patch does, so this simplification will not add functional changes. Signed-off-by: Baolin Wang Reviewed-by: Ryan Roberts --- mm/shmem.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index f24dfbd387ba..db7e9808830f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1685,19 +1685,29 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault struct address_space *mapping, pgoff_t index, unsigned long orders) { - struct vm_area_struct *vma = vmf->vma; + struct vm_area_struct *vma = vmf ? vmf->vma : NULL; unsigned long pages; int order; - orders = thp_vma_suitable_orders(vma, vmf->address, orders); - if (!orders) - return 0; + if (vma) { + orders = thp_vma_suitable_orders(vma, vmf->address, orders); + if (!orders) + return 0; + } /* Find the highest order that can add into the page cache */ order = highest_order(orders); while (orders) { pages = 1UL << order; index = round_down(index, pages); + /* + * Check for conflict before waiting on a huge allocation. + * Conflict might be that a huge page has just been allocated + * and added to page cache by a racing thread, or that there + * is already at least one small page in the huge extent. + * Be careful to retry when appropriate, but not forever! + * Elsewhere -EEXIST would be the right code, but not here. + */ if (!xa_find(&mapping->i_pages, &index, index + pages - 1, XA_PRESENT)) break; @@ -1735,7 +1745,6 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, { struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); - struct vm_area_struct *vma = vmf ? vmf->vma : NULL; unsigned long suitable_orders = 0; struct folio *folio = NULL; long pages; @@ -1745,26 +1754,8 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, orders = 0; if (orders > 0) { - if (vma && vma_is_anon_shmem(vma)) { - suitable_orders = shmem_suitable_orders(inode, vmf, + suitable_orders = shmem_suitable_orders(inode, vmf, mapping, index, orders); - } else if (orders & BIT(HPAGE_PMD_ORDER)) { - pages = HPAGE_PMD_NR; - suitable_orders = BIT(HPAGE_PMD_ORDER); - index = round_down(index, HPAGE_PMD_NR); - - /* - * Check for conflict before waiting on a huge allocation. - * Conflict might be that a huge page has just been allocated - * and added to page cache by a racing thread, or that there - * is already at least one small page in the huge extent. - * Be careful to retry when appropriate, but not forever! - * Elsewhere -EEXIST would be the right code, but not here. - */ - if (xa_find(&mapping->i_pages, &index, - index + HPAGE_PMD_NR - 1, XA_PRESENT)) - return ERR_PTR(-E2BIG); - } order = highest_order(suitable_orders); while (suitable_orders) { From patchwork Mon Jul 22 05:43:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13738280 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 01D3CC3DA59 for ; Mon, 22 Jul 2024 05:43:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E0076B0083; Mon, 22 Jul 2024 01:43:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D92A6B0089; Mon, 22 Jul 2024 01:43:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 148B26B008C; Mon, 22 Jul 2024 01:43:33 -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 EA2C06B0088 for ; Mon, 22 Jul 2024 01:43:32 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8F23681541 for ; Mon, 22 Jul 2024 05:43:32 +0000 (UTC) X-FDA: 82366296264.17.579C1FA Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf01.hostedemail.com (Postfix) with ESMTP id 66FA540009 for ; Mon, 22 Jul 2024 05:43:30 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=VX3tETft; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 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=1721626988; 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=0R5gZULxFaFfXiCneasc1B0qQrqeZpO2sMKXtBQXAHQ=; b=5OC0X9wZ576ftkrmdZSVLX4gLO4i/1Zq+TjL7A/16cK4mBCPQQ01tGQTx49ZjkOL/M3BBo uoQMGHZdcG8uvq1eIrJGk2I8I7GLew6cYz1NoD4+4QdtQMDFgez9zmifj33xw/BEUn5WNx fU2eFuhPR/ijHZO36gmsCIX66OF1Ckc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=VX3tETft; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 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=1721626988; a=rsa-sha256; cv=none; b=AEtJ4OePacs2+nLatlHWAqR6Etgb7tvN8pfaTS4abDt52hUXZ0mZ8XfBr73bAWM05LGHDS 3Fo3tMV/MDYT/4Bf7K9ZeAivF/GGbWqx3KR05J797+mX5qzPDW7ZGEk9hw5zfDpl1DJPgP bqJuD7XR2a64sKQlnM5WZ93xITJ94pc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1721627007; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=0R5gZULxFaFfXiCneasc1B0qQrqeZpO2sMKXtBQXAHQ=; b=VX3tETft68JnLqMQ90bz9ii8s7dfzAo5Y1VfYBz/123/BBGQ4atByOXu8x6w3VeuctvidddSuMm7smVZSHayxsMO34HQSru6dTRTjL76EFCevjGV6XsSoCBMHbkyZhql82gDyECDCFil2YYpxIo4eBNRu8rhiY4KTgTxWO8cWYY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032014031;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0WAyvGdz_1721627005; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WAyvGdz_1721627005) by smtp.aliyun-inc.com; Mon, 22 Jul 2024 13:43:26 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ziy@nvidia.com, ioworker0@gmail.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] mm: shmem: rename shmem_is_huge() to shmem_huge_global_enabled() Date: Mon, 22 Jul 2024 13:43:18 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 66FA540009 X-Stat-Signature: pqmzgpadsney7bhxbc63xg7eszekza96 X-Rspam-User: X-HE-Tag: 1721627010-884932 X-HE-Meta: U2FsdGVkX1+5+3I3a944/tx/904lRXZDjFbJ55xKQXfSjgaBqlCRLqalEHNyUBgsHwUk5P/P6AxsTlVlB3qjB2N/b5vY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JdIRJ6sGuMDDRuls4TmN2/tAgfTsSveemLpV9ik39T8NNFDYR+qq8JTAsWzWVsRAQSjUkvolqLYNqF1f61YyOqKyMLLReVMOIWnBv70LAsmi89iiHMYEH1zbwoG4IBLiK+80Q1yNzI147VnQ== 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: The shmem_is_huge() is now used to check if the top-level huge page is enabled, thus rename it to reflect its usage. Signed-off-by: Baolin Wang Reviewed-by: Ryan Roberts --- include/linux/shmem_fs.h | 9 +++++---- mm/huge_memory.c | 5 +++-- mm/shmem.c | 15 ++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 1d06b1e5408a..405ee8d3589a 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -111,14 +111,15 @@ extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); int shmem_unuse(unsigned int type); #ifdef CONFIG_TRANSPARENT_HUGEPAGE -extern bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force, - struct mm_struct *mm, unsigned long vm_flags); +extern bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, bool shmem_huge_force, + struct mm_struct *mm, unsigned long vm_flags); unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, bool global_huge); #else -static __always_inline bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force, - struct mm_struct *mm, unsigned long vm_flags) +static __always_inline bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, + bool shmem_huge_force, struct mm_struct *mm, + unsigned long vm_flags) { return false; } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f4be468e06a4..e8388ea33f50 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -160,8 +160,9 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, * own flags. */ if (!in_pf && shmem_file(vma->vm_file)) { - bool global_huge = shmem_is_huge(file_inode(vma->vm_file), vma->vm_pgoff, - !enforce_sysfs, vma->vm_mm, vm_flags); + bool global_huge = shmem_huge_global_enabled(file_inode(vma->vm_file), + vma->vm_pgoff, !enforce_sysfs, + vma->vm_mm, vm_flags); if (!vma_is_anon_shmem(vma)) return global_huge ? orders : 0; diff --git a/mm/shmem.c b/mm/shmem.c index db7e9808830f..1445dcd39b6f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -548,9 +548,9 @@ static bool shmem_confirm_swap(struct address_space *mapping, static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER; -static bool __shmem_is_huge(struct inode *inode, pgoff_t index, - bool shmem_huge_force, struct mm_struct *mm, - unsigned long vm_flags) +static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t index, + bool shmem_huge_force, struct mm_struct *mm, + unsigned long vm_flags) { loff_t i_size; @@ -581,14 +581,15 @@ static bool __shmem_is_huge(struct inode *inode, pgoff_t index, } } -bool shmem_is_huge(struct inode *inode, pgoff_t index, +bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, bool shmem_huge_force, struct mm_struct *mm, unsigned long vm_flags) { if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER) return false; - return __shmem_is_huge(inode, index, shmem_huge_force, mm, vm_flags); + return __shmem_huge_global_enabled(inode, index, shmem_huge_force, + mm, vm_flags); } #if defined(CONFIG_SYSFS) @@ -1156,7 +1157,7 @@ static int shmem_getattr(struct mnt_idmap *idmap, STATX_ATTR_NODUMP); generic_fillattr(idmap, request_mask, inode, stat); - if (shmem_is_huge(inode, 0, false, NULL, 0)) + if (shmem_huge_global_enabled(inode, 0, false, NULL, 0)) stat->blksize = HPAGE_PMD_SIZE; if (request_mask & STATX_BTIME) { @@ -2153,7 +2154,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, return 0; } - huge = shmem_is_huge(inode, index, false, fault_mm, + huge = shmem_huge_global_enabled(inode, index, false, fault_mm, vma ? vma->vm_flags : 0); /* Find hugepage orders that are allowed for anonymous shmem. */ if (vma && vma_is_anon_shmem(vma)) From patchwork Mon Jul 22 05:43:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13738281 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 B35E4C3DA5D for ; Mon, 22 Jul 2024 05:43:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87D7D6B0088; Mon, 22 Jul 2024 01:43:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81EB96B0089; Mon, 22 Jul 2024 01:43:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C02D6B008A; Mon, 22 Jul 2024 01:43:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 463D86B0088 for ; Mon, 22 Jul 2024 01:43:34 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CD8BEA1408 for ; Mon, 22 Jul 2024 05:43:33 +0000 (UTC) X-FDA: 82366296306.02.BDF4C9B Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by imf19.hostedemail.com (Postfix) with ESMTP id D57D71A0009 for ; Mon, 22 Jul 2024 05:43:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="d/l2iALs"; spf=pass (imf19.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 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=1721626990; 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=Vs/dizXu3sRF7w2mzo6J6uL+Sv07j1HZRmB25ivkki0=; b=rVpsqP0bQJ9lgsaQms/C8HshBwtDV8tMHU6rsjdr1UeYd3wLNQDzmgCtTn2jTdtI+7TUO0 Q7pTWUBMuzu6VF1l7Cv8oCFvSD9TtKeJfQcGhnctEX3XJT6yn+ggJBTPQuHrdWrcLEQYB/ vrV8vWjhuIt8UJb7gVlztSSRMVRBvGk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="d/l2iALs"; spf=pass (imf19.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 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=1721626990; a=rsa-sha256; cv=none; b=wzgPK7QhFFt6nc3Fb81znPJ5zrzBtbs0U3AtVgLl9PvbXI+Xw0Rs5pue7uWFFaRK1+iAW+ maljNOG8nqiVOpBYgllpFRP+rcdLPKEPlzwUY2rLOplbY6zZz7KzyvBKXl4iGU4FjtvOPd GyErM9CRXTjtMY47tmSCSrLZjryidsY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1721627008; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Vs/dizXu3sRF7w2mzo6J6uL+Sv07j1HZRmB25ivkki0=; b=d/l2iALsrZiVWSqoKxN5ZXfyp+OwgSPKP/+7JFGoB1FwHbTbaOb0jbOP5rRAxIuBis4i7dQ4tVA3D5da0b5vlrn2EB9I/gpY26sJP9rFSxtDWVMBtDYYLB37ev39sGVc7dLeqyQn6lAtjP4EVQ1Wh/MkstDW/1rsifbOjceSCBc= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R861e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032019045;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0WAzW.hk_1721627006; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WAzW.hk_1721627006) by smtp.aliyun-inc.com; Mon, 22 Jul 2024 13:43:27 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ziy@nvidia.com, ioworker0@gmail.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] mm: shmem: move shmem_huge_global_enabled() into shmem_allowable_huge_orders() Date: Mon, 22 Jul 2024 13:43:19 +0800 Message-Id: <8e825146bb29ee1a1c7bd64d2968ff3e19be7815.1721626645.git.baolin.wang@linux.alibaba.com> 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: D57D71A0009 X-Stat-Signature: bmr897zgcupe6jyuj4pqtp6yhaupozgs X-HE-Tag: 1721627011-346996 X-HE-Meta: U2FsdGVkX19S2NfP0dmYhwAsXLXeE6JBXGuCR0G/uUXlZvwvkITMBWoXa0baKWJ1HgSkqrtBfdp7k3nbFIzq1jSxuVnCBAW4qMWMYXTOxpN23iixgaXxDiarLjf1B+tc8Jda786QWDmu2tvV1RH9XzQYhyelZai6bpuCYD2hyaGe4ApIg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f21YpDiiExihg+vd1g7MC/t1isnYGSw8KLJbtZbQ== 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: Move shmem_huge_global_enabled() into the shmem_allowable_huge_orders() function, so that shmem_allowable_huge_orders() can also help to find the allowable huge orders for tmpfs. Moreover the shmem_huge_global_enabled() can become static. While we are at it, passing the vma instead of mm for shmem_huge_global_enabled() makes code cleaner. No functional changes. Signed-off-by: Baolin Wang Reviewed-by: Ryan Roberts --- include/linux/shmem_fs.h | 12 ++-------- mm/huge_memory.c | 12 +++------- mm/shmem.c | 47 +++++++++++++++++++++++++--------------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 405ee8d3589a..1564d7d3ca61 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -111,21 +111,13 @@ extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); int shmem_unuse(unsigned int type); #ifdef CONFIG_TRANSPARENT_HUGEPAGE -extern bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, bool shmem_huge_force, - struct mm_struct *mm, unsigned long vm_flags); unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, - bool global_huge); + bool shmem_huge_force); #else -static __always_inline bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, - bool shmem_huge_force, struct mm_struct *mm, - unsigned long vm_flags) -{ - return false; -} static inline unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, - bool global_huge) + bool shmem_huge_force) { return 0; } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e8388ea33f50..e555fcdd19d4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -159,16 +159,10 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, * Must be done before hugepage flags check since shmem has its * own flags. */ - if (!in_pf && shmem_file(vma->vm_file)) { - bool global_huge = shmem_huge_global_enabled(file_inode(vma->vm_file), - vma->vm_pgoff, !enforce_sysfs, - vma->vm_mm, vm_flags); - - if (!vma_is_anon_shmem(vma)) - return global_huge ? orders : 0; + if (!in_pf && shmem_file(vma->vm_file)) return shmem_allowable_huge_orders(file_inode(vma->vm_file), - vma, vma->vm_pgoff, global_huge); - } + vma, vma->vm_pgoff, + !enforce_sysfs); if (!vma_is_anonymous(vma)) { /* diff --git a/mm/shmem.c b/mm/shmem.c index 1445dcd39b6f..db8f74cac1a2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -549,9 +549,10 @@ 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, - bool shmem_huge_force, struct mm_struct *mm, + bool shmem_huge_force, struct vm_area_struct *vma, unsigned long vm_flags) { + struct mm_struct *mm = vma ? vma->vm_mm : NULL; loff_t i_size; if (!S_ISREG(inode->i_mode)) @@ -581,15 +582,15 @@ static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t index, } } -bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, - bool shmem_huge_force, struct mm_struct *mm, +static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index, + bool shmem_huge_force, struct vm_area_struct *vma, unsigned long vm_flags) { if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER) return false; return __shmem_huge_global_enabled(inode, index, shmem_huge_force, - mm, vm_flags); + vma, vm_flags); } #if defined(CONFIG_SYSFS) @@ -772,6 +773,13 @@ 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, + bool shmem_huge_force, struct vm_area_struct *vma, + unsigned long vm_flags) +{ + return false; +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ /* @@ -1625,27 +1633,38 @@ static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp) #ifdef CONFIG_TRANSPARENT_HUGEPAGE unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, - bool global_huge) + bool shmem_huge_force) { 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->vm_flags; + unsigned long vm_flags = vma ? vma->vm_flags : 0; /* * Check all the (large) orders below HPAGE_PMD_ORDER + 1 that * are enabled for this vma. */ unsigned long orders = BIT(PMD_ORDER + 1) - 1; + bool global_huge; loff_t i_size; int order; - if ((vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) + if (vma && ((vm_flags & VM_NOHUGEPAGE) || + test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) return 0; /* If the hardware/firmware marked hugepage support disabled. */ if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) return 0; + global_huge = shmem_huge_global_enabled(inode, index, shmem_huge_force, + vma, 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; + } + /* * Following the 'deny' semantics of the top level, force the huge * option off from all mounts. @@ -2081,7 +2100,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, struct mm_struct *fault_mm; struct folio *folio; int error; - bool alloced, huge; + bool alloced; unsigned long orders = 0; if (WARN_ON_ONCE(!shmem_mapping(inode->i_mapping))) @@ -2154,14 +2173,8 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, return 0; } - huge = shmem_huge_global_enabled(inode, index, false, fault_mm, - vma ? vma->vm_flags : 0); - /* Find hugepage orders that are allowed for anonymous shmem. */ - if (vma && vma_is_anon_shmem(vma)) - orders = shmem_allowable_huge_orders(inode, vma, index, huge); - else if (huge) - orders = BIT(HPAGE_PMD_ORDER); - + /* Find hugepage orders that are allowed for anonymous shmem and tmpfs. */ + orders = shmem_allowable_huge_orders(inode, vma, index, false); if (orders > 0) { gfp_t huge_gfp;