Skip to content

Commit 26c7d84

Browse files
Bang Liakpm00
authored andcommitted
mm: thp: support "THPeligible" semantics for mTHP with anonymous shmem
After the commit 7fb1b25 ("mm: shmem: add mTHP support for anonymous shmem"), we can configure different policies through the multi-size THP sysfs interface for anonymous shmem. But currently "THPeligible" indicates only whether the mapping is eligible for allocating THP-pages as well as the THP is PMD mappable or not for anonymous shmem, we need to support semantics for mTHP with anonymous shmem similar to those for mTHP with anonymous memory. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Bang Li <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Lance Yang <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4c8763e commit 26c7d84

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

include/linux/shmem_fs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,21 @@ int shmem_unuse(unsigned int type);
113113
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
114114
extern bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force,
115115
struct mm_struct *mm, unsigned long vm_flags);
116+
unsigned long shmem_allowable_huge_orders(struct inode *inode,
117+
struct vm_area_struct *vma, pgoff_t index,
118+
bool global_huge);
116119
#else
117120
static __always_inline bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force,
118121
struct mm_struct *mm, unsigned long vm_flags)
119122
{
120123
return false;
121124
}
125+
static inline unsigned long shmem_allowable_huge_orders(struct inode *inode,
126+
struct vm_area_struct *vma, pgoff_t index,
127+
bool global_huge)
128+
{
129+
return 0;
130+
}
122131
#endif
123132

124133
#ifdef CONFIG_SHMEM

mm/huge_memory.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,15 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
151151
* Must be done before hugepage flags check since shmem has its
152152
* own flags.
153153
*/
154-
if (!in_pf && shmem_file(vma->vm_file))
155-
return shmem_is_huge(file_inode(vma->vm_file), vma->vm_pgoff,
156-
!enforce_sysfs, vma->vm_mm, vm_flags)
157-
? orders : 0;
154+
if (!in_pf && shmem_file(vma->vm_file)) {
155+
bool global_huge = shmem_is_huge(file_inode(vma->vm_file), vma->vm_pgoff,
156+
!enforce_sysfs, vma->vm_mm, vm_flags);
157+
158+
if (!vma_is_anon_shmem(vma))
159+
return global_huge ? orders : 0;
160+
return shmem_allowable_huge_orders(file_inode(vma->vm_file),
161+
vma, vma->vm_pgoff, global_huge);
162+
}
158163

159164
if (!vma_is_anonymous(vma)) {
160165
/*

mm/shmem.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ static gfp_t limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp)
16221622
}
16231623

16241624
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1625-
static unsigned long shmem_allowable_huge_orders(struct inode *inode,
1625+
unsigned long shmem_allowable_huge_orders(struct inode *inode,
16261626
struct vm_area_struct *vma, pgoff_t index,
16271627
bool global_huge)
16281628
{
@@ -1707,13 +1707,6 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
17071707
return orders;
17081708
}
17091709
#else
1710-
static unsigned long shmem_allowable_huge_orders(struct inode *inode,
1711-
struct vm_area_struct *vma, pgoff_t index,
1712-
bool global_huge)
1713-
{
1714-
return 0;
1715-
}
1716-
17171710
static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault *vmf,
17181711
struct address_space *mapping, pgoff_t index,
17191712
unsigned long orders)

0 commit comments

Comments
 (0)