Support large folios for tmpfs
Subsystems (6)
Baolin Wang
reviewercover Support large folios for tmpfs
Hi,
This RFC patch series attempts to support large folios for tmpfs. The first two patches are based on Daniel's previous patches in [1], mainly using the length in the write and fallocate paths to get a highest order hint for large order allocation. The last patch adds mTHP filter control for tmpfs if mTHP is set for the following reasons:
1. Maintain backward compatibility for the control interface. Tmpfs already has a global 'huge=' mount option and '/sys/kernel/mm/transparent_hugepage/shmem_enabled' interface to control large order allocations. mTHP extends this capability to a per-size basis while maintaining good interface compatibility.
2. For the large order allocation of writable mmap() faults in tmpfs, we need something like the mTHP interfaces to control large orders, as well as ensuring consistent interfaces with shmem.
3. Ryan pointed out that large order allocations based on write length could lead to memory fragmentation issue. Just quoting Ryan's comment [2]:
"And it's possible (likely even, in my opinion) that allocating lots of different folio sizes will exacerbate memory fragmentation, leading to more order-0 fallbacks, which would hurt the overall system performance in the long run, vs restricting to a couple of folio sizes."
4. Some hardware preferences, such as for the ARM64 architecture, can better utilize the cont-pte feature to reduce TLB pressure and optimize performance with a 64K size folio. Using mTHP can better leverage these hardware advantages.
Please correct me if I missed something. Thanks a lot.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Baolin Wang (1):
mm: shmem: use mTHP interface to control huge orders for tmpfs
Daniel Gomez (2):
mm: shmem: add file length arg in shmem_get_folio() path
mm: shmem: add large folio support to the write and fallocate paths
fs/xfs/scrub/xfile.c | 6 +-- fs/xfs/xfs_buf_mem.c | 3 +- include/linux/shmem_fs.h | 6 +-- mm/huge_memory.c | 2 +- mm/khugepaged.c | 3 +- mm/memory.c | 4 +- mm/shmem.c | 101 +++++++++++++++++++++++++++++---------- mm/userfaultfd.c | 2 +- 8 files changed, 91 insertions(+), 36 deletions(-)
Signature · 1 line
2.39.3
Baolin Wang
reviewerRFC PATCH 1/3 mm: shmem: add file length arg in shmem_get_folio() path
From: Daniel Gomez <[email protected]>
In preparation for large folio in the write and fallocate paths, add file length argument in shmem_get_folio() path to be able to calculate the folio order based on the file size. Use of order-0 (PAGE_SIZE) for read, page cache read, and vm fault.
This enables high order folios in the write and fallocate path once the folio order is calculated based on the length.
--- fs/xfs/scrub/xfile.c | 6 +++--- fs/xfs/xfs_buf_mem.c | 3 ++- include/linux/shmem_fs.h | 2 +- mm/khugepaged.c | 3 ++- mm/shmem.c | 28 ++++++++++++++++------------ mm/userfaultfd.c | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-)
fs/xfs/scrub/xfile.c +3 -3
@@ -127,7 +127,7 @@ xfile_load(unsigned int offset;if (shmem_get_folio (inode, pos >>PAGE_SHIFT , &folio, -SGP_READ ) <0 ) +SGP_READ ,PAGE_SIZE ) <0 )break ;if (!folio) {/*
@@ -197,7 +197,7 @@ xfile_store(unsigned int offset;if (shmem_get_folio (inode, pos >>PAGE_SHIFT , &folio, -SGP_CACHE ) <0 ) +SGP_CACHE ,PAGE_SIZE ) <0 )break ;if (filemap_check_wb_err (inode->i_mapping,0 )) {folio_unlock (folio);
@@ -268,7 +268,7 @@ xfile_get_folio( pflags =memalloc_nofs_save (); error =shmem_get_folio (inode, pos >>PAGE_SHIFT , &folio, - (flags &XFILE_ALLOC ) ?SGP_CACHE :SGP_READ ); + (flags &XFILE_ALLOC ) ?SGP_CACHE :SGP_READ ,PAGE_SIZE );memalloc_nofs_restore (pflags);if (error)return ERR_PTR (error);
fs/xfs/xfs_buf_mem.c +2 -1
@@ -149,7 +149,8 @@ xmbuf_map_page(return -ENOMEM ; } - error =shmem_get_folio (inode, pos >>PAGE_SHIFT , &folio,SGP_CACHE ); + error =shmem_get_folio (inode, pos >>PAGE_SHIFT , &folio,SGP_CACHE , +PAGE_SIZE );if (error)return error;
include/linux/shmem_fs.h +1 -1
@@ -144,7 +144,7 @@ enum sgp_type { };int shmem_get_folio (struct inode *inode,pgoff_t index,struct folio **foliop, -enum sgp_type sgp); +enum sgp_type sgp,size_t len);struct folio *shmem_read_folio_gfp (struct address_space *mapping,pgoff_t index,gfp_t gfp);
mm/khugepaged.c +2 -1
@@ -1867,7 +1867,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,xas_unlock_irq (&xas);/* swap in or instantiate fallocated page */ if (shmem_get_folio (mapping->host, index, - &folio,SGP_NOALLOC )) { + &folio,SGP_NOALLOC , +PAGE_SIZE )) { result =SCAN_FAIL ; goto xa_unlocked; }
mm/shmem.c +16 -12
@@ -980,7 +980,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index)* (although in some cases this is just a waste of time). */ folio =NULL ; -shmem_get_folio (inode, index, &folio,SGP_READ ); +shmem_get_folio (inode, index, &folio,SGP_READ ,PAGE_SIZE );return folio; }
@@ -2094,7 +2094,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,*/ static int shmem_get_folio_gfp (struct inode *inode,pgoff_t index,struct folio **foliop,enum sgp_type sgp,gfp_t gfp, -struct vm_fault *vmf,vm_fault_t *fault_type) +struct vm_fault *vmf,vm_fault_t *fault_type,size_t len) {struct vm_area_struct *vma = vmf ? vmf->vma :NULL ;struct mm_struct *fault_mm;
@@ -2297,10 +2297,10 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index,* Return: 0 if successful, else a negative error code. */ int shmem_get_folio (struct inode *inode,pgoff_t index,struct folio **foliop, -enum sgp_type sgp) +enum sgp_type sgp,size_t len) {return shmem_get_folio_gfp (inode, index, foliop, sgp, -mapping_gfp_mask (inode->i_mapping),NULL ,NULL ); +mapping_gfp_mask (inode->i_mapping),NULL ,NULL , len); }EXPORT_SYMBOL_GPL (shmem_get_folio);
@@ -2395,7 +2395,7 @@ static vm_fault_t shmem_fault(struct vm_fault *vmf)WARN_ON_ONCE (vmf->page !=NULL ); err =shmem_get_folio_gfp (inode, vmf->pgoff, &folio,SGP_CACHE , - gfp, vmf, &ret); + gfp, vmf, &ret,PAGE_SIZE );if (err)return vmf_error (err);if (folio) {
@@ -2895,6 +2895,9 @@ shmem_write_begin(struct file *file, struct address_space *mapping,struct folio *folio;int ret =0 ; +if (!mapping_large_folio_support (mapping)) + len =min_t (size_t, len,PAGE_SIZE -offset_in_page (pos)); +/* i_rwsem is held by caller */ if (unlikely (info->seals & (F_SEAL_GROW |F_SEAL_WRITE |F_SEAL_FUTURE_WRITE ))) {
@@ -2904,7 +2907,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping,return -EPERM ; } - ret =shmem_get_folio (inode, index, &folio,SGP_WRITE ); + ret =shmem_get_folio (inode, index, &folio,SGP_WRITE , len);if (ret)return ret;
@@ -2975,7 +2978,7 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to)break ; } - error =shmem_get_folio (inode, index, &folio,SGP_READ ); + error =shmem_get_folio (inode, index, &folio,SGP_READ ,PAGE_SIZE );if (error) {if (error == -EINVAL ) error =0 ;
@@ -3152,7 +3155,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos,break ; error =shmem_get_folio (inode, *ppos /PAGE_SIZE , &folio, -SGP_READ ); +SGP_READ ,PAGE_SIZE );if (error) {if (error == -EINVAL ) error =0 ;
@@ -3339,7 +3342,8 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, error = -ENOMEM ; else error =shmem_get_folio (inode, index, &folio, -SGP_FALLOC ); +SGP_FALLOC , + (end - index) <<PAGE_SHIFT );if (error) { info->fallocend = undo_fallocend;/* Remove the !uptodate folios we added */
@@ -3690,7 +3694,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, }else {inode_nohighmem (inode); inode->i_mapping->a_ops = &shmem_aops; - error =shmem_get_folio (inode,0 , &folio,SGP_WRITE ); + error =shmem_get_folio (inode,0 , &folio,SGP_WRITE ,PAGE_SIZE );if (error) goto out_remove_offset; inode->i_op = &shmem_symlink_inode_operations;
@@ -3736,7 +3740,7 @@ static const char *shmem_get_link(struct dentry *dentry, struct inode *inode,return ERR_PTR (-ECHILD ); } }else { - error =shmem_get_folio (inode,0 , &folio,SGP_READ ); + error =shmem_get_folio (inode,0 , &folio,SGP_READ ,PAGE_SIZE );if (error)return ERR_PTR (error);if (!folio)
@@ -5209,7 +5213,7 @@ struct folio *shmem_read_folio_gfp(struct address_space *mapping,int error; error =shmem_get_folio_gfp (inode, index, &folio,SGP_CACHE , - gfp,NULL ,NULL ); + gfp,NULL ,NULL ,PAGE_SIZE );if (error)return ERR_PTR (error);
mm/userfaultfd.c +1 -1
@@ -391,7 +391,7 @@ static int mfill_atomic_pte_continue(pmd_t *dst_pmd,struct page *page;int ret; - ret =shmem_get_folio (inode, pgoff, &folio,SGP_NOALLOC ); + ret =shmem_get_folio (inode, pgoff, &folio,SGP_NOALLOC ,PAGE_SIZE );/* Our caller expects us to return -EFAULT if we failed to find folio */ if (ret == -ENOENT ) ret = -EFAULT ;
Signature · 1 line
2.39.3
Baolin Wang
reviewerRFC PATCH 2/3 mm: shmem: add large folio support to the write and fallocate paths
In reply to Baolin WangFrom: Daniel Gomez <[email protected]>
Add large folio support for shmem write and fallocate paths matching the same high order preference mechanism used in the iomap buffered IO path as used in __filemap_get_folio().
Add shmem_mapping_size_order() to get a hint for the order of the folio based on the file size which takes care of the mapping requirements.
Swap does not support high order folios for now, so make it order-0 in case swap is enabled.
If the top level huge page (controlled by '/sys/kernel/mm/transparent_hugepage/shmem_enabled') is enabled, we just allow PMD sized THP to keep interface backward compatibility.
--- include/linux/shmem_fs.h | 4 +-- mm/huge_memory.c | 2 +- mm/shmem.c | 57 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 8 deletions(-)
include/linux/shmem_fs.h +2 -2
@@ -113,11 +113,11 @@ int shmem_unuse(unsigned int type);#ifdef CONFIG_TRANSPARENT_HUGEPAGE unsigned long shmem_allowable_huge_orders (struct inode *inode,struct vm_area_struct *vma,pgoff_t index, -bool shmem_huge_force); +bool shmem_huge_force,size_t len);#else static inline unsigned long shmem_allowable_huge_orders (struct inode *inode,struct vm_area_struct *vma,pgoff_t index, -bool shmem_huge_force) +bool shmem_huge_force,size_t len) {return 0 ; }
mm/huge_memory.c +1 -1
@@ -162,7 +162,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,if (!in_pf &&shmem_file (vma->vm_file))return shmem_allowable_huge_orders (file_inode (vma->vm_file), vma, vma->vm_pgoff, - !enforce_sysfs); + !enforce_sysfs,PAGE_SIZE );if (!vma_is_anonymous (vma)) {/*
mm/shmem.c +52 -5
79 lines not on this page · raw message
Signature · 1 line
2.39.3
Re: [RFC PATCH 2/3] mm: shmem: add large folio support to the write and fallocate paths
Quoted 90 lines · Baolin Wang
From: Daniel Gomez <[email protected]>
Add large folio support for shmem write and fallocate paths matching the same high order preference mechanism used in the iomap buffered IO path as used in
__filemap_get_folio().Add
shmem_mapping_size_order()to get a hint for the order of the folio based on the file size which takes care of the mapping requirements.Swap does not support high order folios for now, so make it order-0 in case swap is enabled.
If the top level huge page (controlled by '
/sys/kernel/mm/transparent_hugepage/shmem_enabled') is enabled, we just allow PMD sized THP to keep interface backward compatibility.Co-developed-by Baolin Wang <[email protected]>Signed-off-by Daniel Gomez <[email protected]>Signed-off-by Baolin Wang <[email protected]>--- include/linux/shmem_fs.h | 4 +-- mm/huge_memory.c | 2 +- mm/shmem.c | 57 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 8 deletions(-)include/linux/shmem_fs.h +2
-2@@ -113,11 +113,11 @@ int shmem_unuse(unsigned int type);#ifdef CONFIG_TRANSPARENT_HUGEPAGE unsigned long shmem_allowable_huge_orders (struct inode *inode,struct vm_area_struct *vma,pgoff_t index, -bool shmem_huge_force); +bool shmem_huge_force,size_t len);#else static inline unsigned long shmem_allowable_huge_orders (struct inode *inode,struct vm_area_struct *vma,pgoff_t index, -bool shmem_huge_force) +bool shmem_huge_force,size_t len) {return 0 ; }mm/huge_memory.c +1
-1@@ -162,7 +162,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,if (!in_pf &&shmem_file (vma->vm_file))return shmem_allowable_huge_orders (file_inode (vma->vm_file), vma, vma->vm_pgoff, - !enforce_sysfs); + !enforce_sysfs,PAGE_SIZE );if (!vma_is_anonymous (vma)) {/* mm/shmem.c +26
-0@@ -1630,10 +1630,47 @@ static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp)return result; } +/** +* shmem_mapping_size_order - Get maximum folio order for the given file size. +* @mapping: Target address_space. +* @index: The page index. +* @size: The suggested size of the folio to create. +* +* This returns a high order for folios (when supported) based on the file size +* which the mapping currently allows at the given index. The index is relevant +* due to alignment considerations the mapping might have. The returned order +* may be less than the size passed. +* +* Like __filemap_get_folio order calculation. +* +* Return: The order. +*/ +static inline unsigned int +shmem_mapping_size_order (struct address_space *mapping,pgoff_t index, +size_t size,struct shmem_sb_info *sbinfo) +{ +unsigned int order =ilog2 (size); + +if ((order <=PAGE_SHIFT ) || + (!mapping_large_folio_support (mapping) || !sbinfo->noswap)) +return 0 ; + + order -=PAGE_SHIFT ;
mm/shmem.c static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp) · line 1668
Quoted 10 lines
mm/shmem.c +10
-0+ +/* If we're not aligned, allocate a smaller folio */ +if (index & ((1UL << order) -1 )) + order =__ffs (index); + + order =min_t (size_t, order,MAX_PAGECACHE_ORDER ); + +/* Order-1 not supported due to THP dependency */ +return (order ==1 ) ?0 : order; +}
I have an updated version of shmem_mapping_size_order() that I didn't posted but uses get_order() instead as suggested in [1]:
[1] https://lore.kernel.org/all/[email protected]/
/**
* shmem_mapping_size_order - Get maximum folio order for the given file size.
* @mapping: Target address_space.
* @index: The page index.
* @size: The suggested size of the folio to create.
*
* This returns a high order for folios (when supported) based on the file size
* which the mapping currently allows at the given index. The index is relevant
* due to alignment considerations the mapping might have. The returned order
* may be less than the size passed.
*
* Like __filemap_get_folio order calculation.
*
* Return: The order.
*/
static inline unsigned int
shmem_mapping_size_order(struct address_space *mapping, pgoff_t index,
size_t size)
* Return: The order.
*/
static inline unsigned int
shmem_mapping_size_order(struct address_space *mapping, pgoff_t index,
size_t size)
{
unsigned int order = get_order(max_t(size_t, size, PAGE_SIZE));
if (!mapping_large_folio_support(mapping))
return 0;
/* If we're not aligned, allocate a smaller folio */
if (index & ((1UL << order) - 1))
order = __ffs(index);
return min_t(size_t, order, MAX_PAGECACHE_ORDER);
}order-1 is already supported by commit [2], so I've removed that condition as well.
[2] 8897277acfef7f70fdecc054073bea2542fc7a1b ("mm: support order-1 folios in the page cache").
Quoted 45 lines
mm/shmem.c +16
-5+#ifdef CONFIG_TRANSPARENT_HUGEPAGE unsigned long shmem_allowable_huge_orders (struct inode *inode,struct vm_area_struct *vma,pgoff_t index, -bool shmem_huge_force) +bool shmem_huge_force,size_t len) {unsigned long mask =READ_ONCE (huge_shmem_orders_always);unsigned long within_size_orders =READ_ONCE (huge_shmem_orders_within_size);@@ -1659,10 +1696,20 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, 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. +* For tmpfs, if top level huge page is enabled, we just allow +* PMD size THP to keep interface backward compatibility. +*/ +if (global_huge) +return BIT (HPAGE_PMD_ORDER ); + +/* +* Otherwise, get a highest order hint based on the size of +* write and fallocate paths, then will try each allowable +* huge orders. */ -return global_huge ?BIT (HPAGE_PMD_ORDER ) :0 ; + order =shmem_mapping_size_order (inode->i_mapping, index, + len,SHMEM_SB (inode->i_sb)); +return BIT (order +1 ) -1 ; }/* @@ -2174,7 +2221,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, }/* Find hugepage orders that are allowed for anonymous shmem and tmpfs. */ - orders =shmem_allowable_huge_orders (inode, vma, index, false); + orders =shmem_allowable_huge_orders (inode, vma, index, false, len);if (orders >0 ) {gfp_t huge_gfp;Signature · 1 line
2.39.3
Baolin Wang
reviewerRe: [RFC PATCH 2/3] mm: shmem: add large folio support to the write and fallocate paths
Quoted 143 lines · Daniel Gomez
Quoted 90 lines · Baolin Wang
From: Daniel Gomez <[email protected]>
Add large folio support for shmem write and fallocate paths matching the same high order preference mechanism used in the iomap buffered IO path as used in
__filemap_get_folio().Add
shmem_mapping_size_order()to get a hint for the order of the folio based on the file size which takes care of the mapping requirements.Swap does not support high order folios for now, so make it order-0 in case swap is enabled.
If the top level huge page (controlled by '
/sys/kernel/mm/transparent_hugepage/shmem_enabled') is enabled, we just allow PMD sized THP to keep interface backward compatibility.Co-developed-by Baolin Wang <[email protected]>Signed-off-by Daniel Gomez <[email protected]>Signed-off-by Baolin Wang <[email protected]>--- include/linux/shmem_fs.h | 4 +-- mm/huge_memory.c | 2 +- mm/shmem.c | 57 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 8 deletions(-)include/linux/shmem_fs.h +2
-2@@ -113,11 +113,11 @@ int shmem_unuse(unsigned int type);#ifdef CONFIG_TRANSPARENT_HUGEPAGE unsigned long shmem_allowable_huge_orders (struct inode *inode,struct vm_area_struct *vma,pgoff_t index, -bool shmem_huge_force); +bool shmem_huge_force,size_t len);#else static inline unsigned long shmem_allowable_huge_orders (struct inode *inode,struct vm_area_struct *vma,pgoff_t index, -bool shmem_huge_force) +bool shmem_huge_force,size_t len) {return 0 ; }mm/huge_memory.c +1
-1@@ -162,7 +162,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,if (!in_pf &&shmem_file (vma->vm_file))return shmem_allowable_huge_orders (file_inode (vma->vm_file), vma, vma->vm_pgoff, - !enforce_sysfs); + !enforce_sysfs,PAGE_SIZE );if (!vma_is_anonymous (vma)) {/* mm/shmem.c +26
-0@@ -1630,10 +1630,47 @@ static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp)return result; } +/** +* shmem_mapping_size_order - Get maximum folio order for the given file size. +* @mapping: Target address_space. +* @index: The page index. +* @size: The suggested size of the folio to create. +* +* This returns a high order for folios (when supported) based on the file size +* which the mapping currently allows at the given index. The index is relevant +* due to alignment considerations the mapping might have. The returned order +* may be less than the size passed. +* +* Like __filemap_get_folio order calculation. +* +* Return: The order. +*/ +static inline unsigned int +shmem_mapping_size_order (struct address_space *mapping,pgoff_t index, +size_t size,struct shmem_sb_info *sbinfo) +{ +unsigned int order =ilog2 (size); + +if ((order <=PAGE_SHIFT ) || + (!mapping_large_folio_support (mapping) || !sbinfo->noswap)) +return 0 ; + + order -=PAGE_SHIFT ;mm/shmem.c static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp) · line 1668
Quoted 10 lines
mm/shmem.c +10
-0+ +/* If we're not aligned, allocate a smaller folio */ +if (index & ((1UL << order) -1 )) + order =__ffs (index); + + order =min_t (size_t, order,MAX_PAGECACHE_ORDER ); + +/* Order-1 not supported due to THP dependency */ +return (order ==1 ) ?0 : order; +}I have an updated version of
shmem_mapping_size_order()that I didn't posted but usesget_order()instead as suggested in [1]:[1] https://lore.kernel.org/all/[email protected]/
/**
*shmem_mapping_size_order- Get maximum folio order for the given file size.
* @mapping: Targetaddress_space.
* @index: The page index.
* @size: The suggested size of the folio to create.
*
* This returns a high order for folios (when supported) based on the file size
* which the mapping currently allows at the given index. The index is relevant
* due to alignment considerations the mapping might have. The returned order
* may be less than the size passed.
*
* Like__filemap_get_folioorder calculation.
*
* Return: The order.
*/
static inline unsigned int
shmem_mapping_size_order(structaddress_space*mapping,pgoff_tindex,
size_tsize)
* Return: The order.
*/
static inline unsigned int
shmem_mapping_size_order(structaddress_space*mapping,pgoff_tindex,
size_tsize){ unsigned int order = get_order(max_t(size_t, size, PAGE_SIZE)); if (!mapping_large_folio_support(mapping)) return 0; /* If we're not aligned, allocate a smaller folio */ if (index & ((1UL << order) - 1)) order = __ffs(index); return min_t(size_t, order, MAX_PAGECACHE_ORDER); }
Quoted 5 lines
order-1 is already supported by commit [2], so I've removed that condition as well.
[2]
8897277acfef7f70fdecc054073bea2542fc7a1b("mm: support order-1 folios in the page cache").
Great. Thanks Daniel.
I will include your new version if there are no obvious objections to this patchset.
Baolin Wang
reviewerRFC PATCH 3/3 mm: shmem: use mTHP interface to control huge orders for tmpfs
In reply to Baolin WangFor the huge orders allowed by writable mmap() faults on tmpfs, the mTHP interface is used to control the allowable huge orders, while 'huge_shmem_orders_inherit' maintains backward compatibility with top-level interface.
For the huge orders allowed by write() and fallocate() paths on tmpfs, getting a highest order hint based on the size of write and fallocate paths, then will try each allowable huge orders filtered by the mTHP interfaces if set.
--- mm/memory.c | 4 ++-- mm/shmem.c | 42 ++++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-)
mm/memory.c +2 -2
@@ -4877,10 +4877,10 @@ vm_fault_t finish_fault(struct vm_fault *vmf)/* * Using per-page fault to maintain the uffd semantics, and same -* approach also applies to non-anonymous-shmem faults to avoid +* approach also applies to non shmem/tmpfs faults to avoid * inflating the RSS of the process. */ -if (!vma_is_anon_shmem (vma) ||unlikely (userfaultfd_armed (vma))) { +if (!vma_is_shmem (vma) ||unlikely (userfaultfd_armed (vma))) { nr_pages =1 ; }else if (nr_pages >1 ) {pgoff_t idx =folio_page_idx (folio, page);
mm/shmem.c +22 -20
57 lines not on this page · raw message
Signature · 1 line
2.39.3