Re: [PATCH v8 13/15] hugetlb: Set mapping folio order

[email protected] Tue, 4 Aug 2026 00:01:45 -0700
Newsgroups gmane.linux.file-systems,gmane.linux.kernel.mm
Message-ID <[email protected]>

On 7/31/2026 1:07 PM, Matthew Wilcox (Oracle) wrote:
> hugetlbfs currently uses an fs-specific way to determine the size of the=
=20
> folios in its page cache. Thanks to the support of block sizes larger=20
> than page sizes, we now support this as part of the page cache. It's=20
> somewhat more efficient as we
>=20
>=20
> hugetlbfs currently uses an fs-specific way to determine the size of
> the folios in its page cache.  Thanks to the support of block sizes
> larger than page sizes, we now support this as part of the page cache.
> It's somewhat more efficient as we have this information directly in the
> mapping rather than going from inode->i_sb->s_fs_info.  We can convert
> the rest of the hugetlb code to use this at our leisure; this is needed
> now so that we can use filemap_get_pages() unmodified.
>=20
> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
> Reviewed-by: Gregory Price <[email protected]>
> ---
>   fs/hugetlbfs/inode.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
>=20
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index dbca3f713bbf..8d15413a67ee 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -883,6 +883,16 @@ static struct inode *hugetlbfs_get_root(struct super=
_block *sb,
>   	return inode;
>   }
>  =20
> +static void hugetlbfs_init_regular_inode(struct inode *inode)
> +{
> +	struct hstate *hstate =3D hstate_inode(inode);
> +	unsigned int order =3D huge_page_order(hstate);
> +
> +	inode->i_op =3D &hugetlbfs_inode_operations;
> +	inode->i_fop =3D &hugetlbfs_file_operations;
> +	mapping_set_folio_order_range(inode->i_mapping, order, order);
> +}
> +
>   /*
>    * Hugetlbfs is not reclaimable; therefore its i_mmap_rwsem will never
>    * be taken from reclaim -- unlike regular filesystems. This needs an
> @@ -926,8 +936,7 @@ static struct inode *hugetlbfs_get_inode(struct super=
_block *sb,
>   			init_special_inode(inode, mode, dev);
>   			break;
>   		case S_IFREG:
> -			inode->i_op =3D &hugetlbfs_inode_operations;
> -			inode->i_fop =3D &hugetlbfs_file_operations;
> +			hugetlbfs_init_regular_inode(inode);
>   			break;
>   		case S_IFDIR:
>   			inode->i_op =3D &hugetlbfs_dir_inode_operations;
> --=20
> 2.47.3
>=20

Good idea!

Reviewed-by: Jane Chu <[email protected]>

thanks,
-jane