From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11F8243E074 for ; Fri, 18 Sep 2026 03:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703948; cv=none; b=uybeMfTEYWsGqGV3BCCtO46PR4MTu1sz9ddLF5W8PnLoBz4DJ3hW41Sq9k0GAQdFTYd+wj8DZ1r6VzEwLiLLALCesDj1W+BYYcm/gamOQ4DxZZJi9UtsGRQHI/Je/Gr1F3mt2+Dccp0LjMLBmoS8rKMb7tGzf+bPTHPbfaI/S20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703948; c=relaxed/simple; bh=oTY7ToQKQxWUPqnpGGIaIJGoOnKFr/LL/Ic95Ezpc4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eCukV70tJBC0mtdzqslY48SzzoBdN64kT8bLnauI5Gh042owxPn9KvtFYQdWGBNIwqI7MG+mQdtfdkQBW++C3rth2XZdiwHiaSSr6zD8hUBW20NgoiTP+weeZZlIsRHKgLSj3NiXivnXutJrE9OFlxo+BcfiX0n2dHAUEh32CDA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=KFcmzR5k; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="KFcmzR5k" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703937; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=0x3dSjlUiTkXS7vb5onP0ckg+vTzpvO3+8JjOPhJO8M=; b=KFcmzR5kQpdstBc3Dq1M/4Qqp0umEOoxwgYuFSUbIQXQkbopP6NeCpzU8qCo8Jk4X1oUgastqj7onW0eTxkDjSgGehvB8pL5wG+dDMyUDr5Sp7I+I7QN/lW7EUOAKdpzLI2JiNwaNdTQ2PfTg4GKoOON4Kiz7umYRDTy5SF3XPQ= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R901e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9o3cX_1789703935; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9o3cX_1789703935 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:55 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/12] mm: shmem: run khugepaged for all shmem mTHP orders Date: Fri, 18 Sep 2026 11:58:41 +0800 Message-ID: <3dee70b589a0190e5e7b5c8b085a7e9da4b27f4a.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When only non-PMD-sized mTHP is enabled (such as only 64K mTHP enabled), we should also allow kicking khugepaged to attempt scanning and collapsing 64K shmem mTHP. Modify shmem_hpage_pmd_enabled() to support shmem mTHP collapse, and while we are at it, rename it to make the function name more clear. Signed-off-by: Baolin Wang --- include/linux/shmem_fs.h | 4 ++-- mm/khugepaged.c | 2 +- mm/shmem.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index a7c7a96a7cbf..9f2036f58bb8 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -135,7 +135,7 @@ int shmem_unuse(unsigned int type); unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, loff_t write_end, bool shmem_huge_force); -bool shmem_hpage_pmd_enabled(void); +bool shmem_hpage_enabled(void); #else static inline unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, @@ -144,7 +144,7 @@ static inline unsigned long shmem_allowable_huge_orders(struct inode *inode, return 0; } -static inline bool shmem_hpage_pmd_enabled(void) +static inline bool shmem_hpage_enabled(void) { return false; } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index dba747442461..5c477ea16c6f 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -447,7 +447,7 @@ static bool hugepage_enabled(void) return true; if (anon_hpage_enabled()) return true; - if (shmem_hpage_pmd_enabled()) + if (shmem_hpage_enabled()) return true; return false; } diff --git a/mm/shmem.c b/mm/shmem.c index 951e922091fe..6567bd4cdc07 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2018,17 +2018,17 @@ static struct folio *shmem_swapin_cluster(swp_entry_t swap, gfp_t gfp, } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -bool shmem_hpage_pmd_enabled(void) +bool shmem_hpage_enabled(void) { if (shmem_huge == SHMEM_HUGE_DENY) return false; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_always)) + if (READ_ONCE(huge_shmem_orders_always)) return true; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_madvise)) + if (READ_ONCE(huge_shmem_orders_madvise)) return true; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_within_size)) + if (READ_ONCE(huge_shmem_orders_within_size)) return true; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_inherit) && + if (READ_ONCE(huge_shmem_orders_inherit) && shmem_huge != SHMEM_HUGE_NEVER) return true; -- 2.47.3