From nobody Sun Nov 24 04:34:19 2024 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 B5BE31CF5F4 for ; Fri, 8 Nov 2024 04:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731039215; cv=none; b=QiYv+grVog7CRW3decDh2aZtfDZ++1dJU9U3qsmwVDb5T0cXgDOclzqzqXicsRCn/Hrj3mGHYnI8/8KYTI73xLaeZ1lWA0VggQrSmJRNWdZrnkAbhEgYUwdWYvnRrpTN0AyEYhFUUqH7GehNIHvTx+eD94s+LvrQOPnCmoHV/eA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731039215; c=relaxed/simple; bh=pIINmnRuMhBwhKo7Aoq6MuHbbIlkpLT5NNRZGvEsE3I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pSzWrROXRTGBqJolJqeQm0JtwXoiO4qkE8p4UehJv/6kRNtYr94E5FPRXxGt5PoWhOXne4VHvAjlOzwDfwk3pFlLrrDKf1hmGIFqNYhKfcaDNBRf5WHCfo/dWG7wzRdxnmRp9qawmuEoStYzr1JdIRAl01vlSaBNeMho50jjBck= 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=Rwm+hqD7; arc=none smtp.client-ip=115.124.30.132 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="Rwm+hqD7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1731039206; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=OAXkgfSC/TSIsttX/eS9fvBNEIFaQACVaW/jTgI39Ao=; b=Rwm+hqD79ng0V3+gkZY7ifxG0EexZrRinnxWZM74LSYPR7l/LN4/38agX9VUIPHFeE792YQkYAKjzo3umiexnvFk2f7VLj1JPh9Gvyey+oe5C31JAvTsCwPY8PKfXo23/0DkpXqfzM13nBgESoPmas7FQsKgPv+Ba6a+stDplug= 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, =20 static int shmem_huge __read_mostly =3D SHMEM_HUGE_NEVER; =20 -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; =20 if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER) - return false; + return 0; if (!S_ISREG(inode->i_mode)) - return false; + return 0; if (shmem_huge =3D=3D SHMEM_HUGE_DENY) - return false; + return 0; if (shmem_huge_force || shmem_huge =3D=3D SHMEM_HUGE_FORCE) - return true; + return BIT(HPAGE_PMD_ORDER); =20 switch (SHMEM_SB(inode->i_sb)->huge) { case SHMEM_HUGE_ALWAYS: - return true; + return BIT(HPAGE_PMD_ORDER); case SHMEM_HUGE_WITHIN_SIZE: index =3D round_up(index + 1, HPAGE_PMD_NR); i_size =3D max(write_end, i_size_read(inode)); i_size =3D round_up(i_size, PAGE_SIZE); if (i_size >> PAGE_SHIFT >=3D 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; } } =20 @@ -774,11 +774,11 @@ static unsigned long shmem_unused_huge_shrink(struct = shmem_sb_info *sbinfo, return 0; } =20 -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 */ =20 @@ -1173,8 +1173,11 @@ static int shmem_getattr(struct mnt_idmap *idmap, generic_fillattr(idmap, request_mask, inode, stat); inode_unlock_shared(inode); =20 - if (shmem_huge_global_enabled(inode, 0, 0, false, 0)) +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (shmem_huge_global_enabled(inode, 0, 0, false, 0) =3D=3D + BIT(HPAGE_PMD_ORDER)) stat->blksize =3D HPAGE_PMD_SIZE; +#endif =20 if (request_mask & STATX_BTIME) { stat->result_mask |=3D STATX_BTIME; @@ -1682,21 +1685,21 @@ unsigned long shmem_allowable_huge_orders(struct in= ode *inode, unsigned long mask =3D READ_ONCE(huge_shmem_orders_always); unsigned long within_size_orders =3D READ_ONCE(huge_shmem_orders_within_s= ize); unsigned long vm_flags =3D vma ? vma->vm_flags : 0; - bool global_huge; + unsigned int global_orders; loff_t i_size; int order; =20 if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags))) return 0; =20 - global_huge =3D shmem_huge_global_enabled(inode, index, write_end, - shmem_huge_force, vm_flags); + global_orders =3D 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; } =20 /* @@ -1729,7 +1732,7 @@ unsigned long shmem_allowable_huge_orders(struct inod= e *inode, if (vm_flags & VM_HUGEPAGE) mask |=3D READ_ONCE(huge_shmem_orders_madvise); =20 - if (global_huge) + if (global_orders > 0) mask |=3D READ_ONCE(huge_shmem_orders_inherit); =20 return THP_ORDERS_ALL_FILE_DEFAULT & mask; --=20 2.39.3