Skip to content

Commit 9845cbb

Browse files
kiryltorvalds
authored andcommitted
mm, thp: fix infinite loop on memcg OOM
Masayoshi Mizuma reported a bug with the hang of an application under the memcg limit. It happens on write-protection fault to huge zero page If we successfully allocate a huge page to replace zero page but hit the memcg limit we need to split the zero page with split_huge_page_pmd() and fallback to small pages. The other part of the problem is that VM_FAULT_OOM has special meaning in do_huge_pmd_wp_page() context. __handle_mm_fault() expects the page to be split if it sees VM_FAULT_OOM and it will will retry page fault handling. This causes an infinite loop if the page was not split. do_huge_pmd_wp_zero_page_fallback() can return VM_FAULT_OOM if it failed to allocate one small page, so fallback to small pages will not help. The solution for this part is to replace VM_FAULT_OOM with VM_FAULT_FALLBACK is fallback required. Signed-off-by: Kirill A. Shutemov <[email protected]> Reported-by: Masayoshi Mizuma <[email protected]> Reviewed-by: Michal Hocko <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: David Rientjes <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0141288 commit 9845cbb

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

mm/huge_memory.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,10 @@ int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
11661166
} else {
11671167
ret = do_huge_pmd_wp_page_fallback(mm, vma, address,
11681168
pmd, orig_pmd, page, haddr);
1169-
if (ret & VM_FAULT_OOM)
1169+
if (ret & VM_FAULT_OOM) {
11701170
split_huge_page(page);
1171+
ret |= VM_FAULT_FALLBACK;
1172+
}
11711173
put_page(page);
11721174
}
11731175
count_vm_event(THP_FAULT_FALLBACK);
@@ -1179,9 +1181,10 @@ int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
11791181
if (page) {
11801182
split_huge_page(page);
11811183
put_page(page);
1182-
}
1184+
} else
1185+
split_huge_page_pmd(vma, address, pmd);
1186+
ret |= VM_FAULT_FALLBACK;
11831187
count_vm_event(THP_FAULT_FALLBACK);
1184-
ret |= VM_FAULT_OOM;
11851188
goto out;
11861189
}
11871190

mm/memory.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,7 +3704,6 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
37043704
if (unlikely(is_vm_hugetlb_page(vma)))
37053705
return hugetlb_fault(mm, vma, address, flags);
37063706

3707-
retry:
37083707
pgd = pgd_offset(mm, address);
37093708
pud = pud_alloc(mm, pgd, address);
37103709
if (!pud)
@@ -3742,20 +3741,13 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
37423741
if (dirty && !pmd_write(orig_pmd)) {
37433742
ret = do_huge_pmd_wp_page(mm, vma, address, pmd,
37443743
orig_pmd);
3745-
/*
3746-
* If COW results in an oom, the huge pmd will
3747-
* have been split, so retry the fault on the
3748-
* pte for a smaller charge.
3749-
*/
3750-
if (unlikely(ret & VM_FAULT_OOM))
3751-
goto retry;
3752-
return ret;
3744+
if (!(ret & VM_FAULT_FALLBACK))
3745+
return ret;
37533746
} else {
37543747
huge_pmd_set_accessed(mm, vma, address, pmd,
37553748
orig_pmd, dirty);
3749+
return 0;
37563750
}
3757-
3758-
return 0;
37593751
}
37603752
}
37613753

0 commit comments

Comments
 (0)