Skip to content

Commit 9d3c335

Browse files
rientjestorvalds
authored andcommitted
mm, thp: do not cause memcg oom for thp
Commit 2516035 ("mm, thp: remove __GFP_NORETRY from khugepaged and madvised allocations") changed the page allocator to no longer detect thp allocations based on __GFP_NORETRY. It did not, however, modify the mem cgroup try_charge() path to avoid oom kill for either khugepaged collapsing or thp faulting. It is never expected to oom kill a process to allocate a hugepage for thp; reclaim is governed by the thp defrag mode and MADV_HUGEPAGE, but allocations (and charging) should fallback instead of oom killing processes. Link: http://lkml.kernel.org/r/[email protected] Fixes: 2516035 ("mm, thp: remove __GFP_NORETRY from khugepaged and madvised allocations") Signed-off-by: David Rientjes <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Johannes Weiner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1c610d5 commit 9d3c335

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mm/huge_memory.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ static int __do_huge_pmd_anonymous_page(struct vm_fault *vmf, struct page *page,
555555

556556
VM_BUG_ON_PAGE(!PageCompound(page), page);
557557

558-
if (mem_cgroup_try_charge(page, vma->vm_mm, gfp, &memcg, true)) {
558+
if (mem_cgroup_try_charge(page, vma->vm_mm, gfp | __GFP_NORETRY, &memcg,
559+
true)) {
559560
put_page(page);
560561
count_vm_event(THP_FAULT_FALLBACK);
561562
return VM_FAULT_FALLBACK;
@@ -1316,7 +1317,7 @@ int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd)
13161317
}
13171318

13181319
if (unlikely(mem_cgroup_try_charge(new_page, vma->vm_mm,
1319-
huge_gfp, &memcg, true))) {
1320+
huge_gfp | __GFP_NORETRY, &memcg, true))) {
13201321
put_page(new_page);
13211322
split_huge_pmd(vma, vmf->pmd, vmf->address);
13221323
if (page)

mm/khugepaged.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,9 @@ static void collapse_huge_page(struct mm_struct *mm,
965965
goto out_nolock;
966966
}
967967

968-
if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp, &memcg, true))) {
968+
/* Do not oom kill for khugepaged charges */
969+
if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp | __GFP_NORETRY,
970+
&memcg, true))) {
969971
result = SCAN_CGROUP_CHARGE_FAIL;
970972
goto out_nolock;
971973
}
@@ -1324,7 +1326,9 @@ static void collapse_shmem(struct mm_struct *mm,
13241326
goto out;
13251327
}
13261328

1327-
if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp, &memcg, true))) {
1329+
/* Do not oom kill for khugepaged charges */
1330+
if (unlikely(mem_cgroup_try_charge(new_page, mm, gfp | __GFP_NORETRY,
1331+
&memcg, true))) {
13281332
result = SCAN_CGROUP_CHARGE_FAIL;
13291333
goto out;
13301334
}

0 commit comments

Comments
 (0)