mirror of
https://github.com/torvalds/linux.git
synced 2024-11-01 04:53:36 +01:00
mm: khugepaged: make khugepaged_enter() void function
The most callers of khugepaged_enter() don't care about the return value. Only dup_mmap(), anonymous THP page fault and MADV_HUGEPAGE handle the error by returning -ENOMEM. Actually it is not harmful for them to ignore the error case either. It also sounds overkilling to fail fork() and page fault early due to khugepaged_enter() error, and MADV_HUGEPAGE does set VM_HUGEPAGE flag regardless of the error. Link: https://lkml.kernel.org/r/20220510203222.24246-6-shy828301@gmail.com Signed-off-by: Yang Shi <shy828301@gmail.com> Acked-by: Song Liu <song@kernel.org> Acked-by: Vlastmil Babka <vbabka@suse.cz> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Rik van Riel <riel@surriel.com> Cc: Song Liu <songliubraving@fb.com> Cc: Theodore Ts'o <tytso@mit.edu> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
78d12c19e0
commit
d2081b2bf8
4 changed files with 22 additions and 34 deletions
|
@ -12,9 +12,9 @@ extern struct attribute_group khugepaged_attr_group;
|
||||||
extern int khugepaged_init(void);
|
extern int khugepaged_init(void);
|
||||||
extern void khugepaged_destroy(void);
|
extern void khugepaged_destroy(void);
|
||||||
extern int start_stop_khugepaged(void);
|
extern int start_stop_khugepaged(void);
|
||||||
extern int __khugepaged_enter(struct mm_struct *mm);
|
extern void __khugepaged_enter(struct mm_struct *mm);
|
||||||
extern void __khugepaged_exit(struct mm_struct *mm);
|
extern void __khugepaged_exit(struct mm_struct *mm);
|
||||||
extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
|
extern void khugepaged_enter_vma_merge(struct vm_area_struct *vma,
|
||||||
unsigned long vm_flags);
|
unsigned long vm_flags);
|
||||||
extern void khugepaged_min_free_kbytes_update(void);
|
extern void khugepaged_min_free_kbytes_update(void);
|
||||||
#ifdef CONFIG_SHMEM
|
#ifdef CONFIG_SHMEM
|
||||||
|
@ -40,11 +40,10 @@ static inline void collapse_pte_mapped_thp(struct mm_struct *mm,
|
||||||
(transparent_hugepage_flags & \
|
(transparent_hugepage_flags & \
|
||||||
(1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG))
|
(1<<TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG))
|
||||||
|
|
||||||
static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
|
static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
|
||||||
{
|
{
|
||||||
if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags))
|
if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags))
|
||||||
return __khugepaged_enter(mm);
|
__khugepaged_enter(mm);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void khugepaged_exit(struct mm_struct *mm)
|
static inline void khugepaged_exit(struct mm_struct *mm)
|
||||||
|
@ -53,7 +52,7 @@ static inline void khugepaged_exit(struct mm_struct *mm)
|
||||||
__khugepaged_exit(mm);
|
__khugepaged_exit(mm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int khugepaged_enter(struct vm_area_struct *vma,
|
static inline void khugepaged_enter(struct vm_area_struct *vma,
|
||||||
unsigned long vm_flags)
|
unsigned long vm_flags)
|
||||||
{
|
{
|
||||||
if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags))
|
if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags))
|
||||||
|
@ -62,27 +61,22 @@ static inline int khugepaged_enter(struct vm_area_struct *vma,
|
||||||
(khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) &&
|
(khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) &&
|
||||||
!(vm_flags & VM_NOHUGEPAGE) &&
|
!(vm_flags & VM_NOHUGEPAGE) &&
|
||||||
!test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))
|
!test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))
|
||||||
if (__khugepaged_enter(vma->vm_mm))
|
__khugepaged_enter(vma->vm_mm);
|
||||||
return -ENOMEM;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
|
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
|
||||||
static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
|
static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
static inline void khugepaged_exit(struct mm_struct *mm)
|
static inline void khugepaged_exit(struct mm_struct *mm)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
static inline int khugepaged_enter(struct vm_area_struct *vma,
|
static inline void khugepaged_enter(struct vm_area_struct *vma,
|
||||||
unsigned long vm_flags)
|
unsigned long vm_flags)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
static inline int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
|
static inline void khugepaged_enter_vma_merge(struct vm_area_struct *vma,
|
||||||
unsigned long vm_flags)
|
unsigned long vm_flags)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
static inline void collapse_pte_mapped_thp(struct mm_struct *mm,
|
static inline void collapse_pte_mapped_thp(struct mm_struct *mm,
|
||||||
unsigned long addr)
|
unsigned long addr)
|
||||||
|
|
|
@ -612,9 +612,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
|
||||||
retval = ksm_fork(mm, oldmm);
|
retval = ksm_fork(mm, oldmm);
|
||||||
if (retval)
|
if (retval)
|
||||||
goto out;
|
goto out;
|
||||||
retval = khugepaged_fork(mm, oldmm);
|
khugepaged_fork(mm, oldmm);
|
||||||
if (retval)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
|
for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
|
||||||
|
|
|
@ -726,8 +726,8 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
|
||||||
return VM_FAULT_FALLBACK;
|
return VM_FAULT_FALLBACK;
|
||||||
if (unlikely(anon_vma_prepare(vma)))
|
if (unlikely(anon_vma_prepare(vma)))
|
||||||
return VM_FAULT_OOM;
|
return VM_FAULT_OOM;
|
||||||
if (unlikely(khugepaged_enter(vma, vma->vm_flags)))
|
khugepaged_enter(vma, vma->vm_flags);
|
||||||
return VM_FAULT_OOM;
|
|
||||||
if (!(vmf->flags & FAULT_FLAG_WRITE) &&
|
if (!(vmf->flags & FAULT_FLAG_WRITE) &&
|
||||||
!mm_forbids_zeropage(vma->vm_mm) &&
|
!mm_forbids_zeropage(vma->vm_mm) &&
|
||||||
transparent_hugepage_use_zero_page()) {
|
transparent_hugepage_use_zero_page()) {
|
||||||
|
|
|
@ -365,8 +365,7 @@ int hugepage_madvise(struct vm_area_struct *vma,
|
||||||
* register it here without waiting a page fault that
|
* register it here without waiting a page fault that
|
||||||
* may not happen any time soon.
|
* may not happen any time soon.
|
||||||
*/
|
*/
|
||||||
if (khugepaged_enter_vma_merge(vma, *vm_flags))
|
khugepaged_enter_vma_merge(vma, *vm_flags);
|
||||||
return -ENOMEM;
|
|
||||||
break;
|
break;
|
||||||
case MADV_NOHUGEPAGE:
|
case MADV_NOHUGEPAGE:
|
||||||
*vm_flags &= ~VM_HUGEPAGE;
|
*vm_flags &= ~VM_HUGEPAGE;
|
||||||
|
@ -475,20 +474,20 @@ static bool hugepage_vma_check(struct vm_area_struct *vma,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __khugepaged_enter(struct mm_struct *mm)
|
void __khugepaged_enter(struct mm_struct *mm)
|
||||||
{
|
{
|
||||||
struct mm_slot *mm_slot;
|
struct mm_slot *mm_slot;
|
||||||
int wakeup;
|
int wakeup;
|
||||||
|
|
||||||
mm_slot = alloc_mm_slot();
|
mm_slot = alloc_mm_slot();
|
||||||
if (!mm_slot)
|
if (!mm_slot)
|
||||||
return -ENOMEM;
|
return;
|
||||||
|
|
||||||
/* __khugepaged_exit() must not run from under us */
|
/* __khugepaged_exit() must not run from under us */
|
||||||
VM_BUG_ON_MM(khugepaged_test_exit(mm), mm);
|
VM_BUG_ON_MM(khugepaged_test_exit(mm), mm);
|
||||||
if (unlikely(test_and_set_bit(MMF_VM_HUGEPAGE, &mm->flags))) {
|
if (unlikely(test_and_set_bit(MMF_VM_HUGEPAGE, &mm->flags))) {
|
||||||
free_mm_slot(mm_slot);
|
free_mm_slot(mm_slot);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&khugepaged_mm_lock);
|
spin_lock(&khugepaged_mm_lock);
|
||||||
|
@ -504,11 +503,9 @@ int __khugepaged_enter(struct mm_struct *mm)
|
||||||
mmgrab(mm);
|
mmgrab(mm);
|
||||||
if (wakeup)
|
if (wakeup)
|
||||||
wake_up_interruptible(&khugepaged_wait);
|
wake_up_interruptible(&khugepaged_wait);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
|
void khugepaged_enter_vma_merge(struct vm_area_struct *vma,
|
||||||
unsigned long vm_flags)
|
unsigned long vm_flags)
|
||||||
{
|
{
|
||||||
unsigned long hstart, hend;
|
unsigned long hstart, hend;
|
||||||
|
@ -519,13 +516,12 @@ int khugepaged_enter_vma_merge(struct vm_area_struct *vma,
|
||||||
* file-private shmem THP is not supported.
|
* file-private shmem THP is not supported.
|
||||||
*/
|
*/
|
||||||
if (!hugepage_vma_check(vma, vm_flags))
|
if (!hugepage_vma_check(vma, vm_flags))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
|
hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
|
||||||
hend = vma->vm_end & HPAGE_PMD_MASK;
|
hend = vma->vm_end & HPAGE_PMD_MASK;
|
||||||
if (hstart < hend)
|
if (hstart < hend)
|
||||||
return khugepaged_enter(vma, vm_flags);
|
khugepaged_enter(vma, vm_flags);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __khugepaged_exit(struct mm_struct *mm)
|
void __khugepaged_exit(struct mm_struct *mm)
|
||||||
|
|
Loading…
Reference in a new issue