diff options
-rw-r--r-- | mm/huge_memory.c | 3 | ||||
-rw-r--r-- | mm/memory.c | 18 |
2 files changed, 18 insertions, 3 deletions
diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d7d7165156ca..edfeb8cb23df 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c | |||
@@ -952,6 +952,8 @@ int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
952 | count_vm_event(THP_FAULT_FALLBACK); | 952 | count_vm_event(THP_FAULT_FALLBACK); |
953 | ret = do_huge_pmd_wp_page_fallback(mm, vma, address, | 953 | ret = do_huge_pmd_wp_page_fallback(mm, vma, address, |
954 | pmd, orig_pmd, page, haddr); | 954 | pmd, orig_pmd, page, haddr); |
955 | if (ret & VM_FAULT_OOM) | ||
956 | split_huge_page(page); | ||
955 | put_page(page); | 957 | put_page(page); |
956 | goto out; | 958 | goto out; |
957 | } | 959 | } |
@@ -959,6 +961,7 @@ int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
959 | 961 | ||
960 | if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) { | 962 | if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) { |
961 | put_page(new_page); | 963 | put_page(new_page); |
964 | split_huge_page(page); | ||
962 | put_page(page); | 965 | put_page(page); |
963 | ret |= VM_FAULT_OOM; | 966 | ret |= VM_FAULT_OOM; |
964 | goto out; | 967 | goto out; |
diff --git a/mm/memory.c b/mm/memory.c index 2bf9e110437c..1b7dc662bf9f 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -3486,6 +3486,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |||
3486 | if (unlikely(is_vm_hugetlb_page(vma))) | 3486 | if (unlikely(is_vm_hugetlb_page(vma))) |
3487 | return hugetlb_fault(mm, vma, address, flags); | 3487 | return hugetlb_fault(mm, vma, address, flags); |
3488 | 3488 | ||
3489 | retry: | ||
3489 | pgd = pgd_offset(mm, address); | 3490 | pgd = pgd_offset(mm, address); |
3490 | pud = pud_alloc(mm, pgd, address); | 3491 | pud = pud_alloc(mm, pgd, address); |
3491 | if (!pud) | 3492 | if (!pud) |
@@ -3499,13 +3500,24 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |||
3499 | pmd, flags); | 3500 | pmd, flags); |
3500 | } else { | 3501 | } else { |
3501 | pmd_t orig_pmd = *pmd; | 3502 | pmd_t orig_pmd = *pmd; |
3503 | int ret; | ||
3504 | |||
3502 | barrier(); | 3505 | barrier(); |
3503 | if (pmd_trans_huge(orig_pmd)) { | 3506 | if (pmd_trans_huge(orig_pmd)) { |
3504 | if (flags & FAULT_FLAG_WRITE && | 3507 | if (flags & FAULT_FLAG_WRITE && |
3505 | !pmd_write(orig_pmd) && | 3508 | !pmd_write(orig_pmd) && |
3506 | !pmd_trans_splitting(orig_pmd)) | 3509 | !pmd_trans_splitting(orig_pmd)) { |
3507 | return do_huge_pmd_wp_page(mm, vma, address, | 3510 | ret = do_huge_pmd_wp_page(mm, vma, address, pmd, |
3508 | pmd, orig_pmd); | 3511 | orig_pmd); |
3512 | /* | ||
3513 | * If COW results in an oom, the huge pmd will | ||
3514 | * have been split, so retry the fault on the | ||
3515 | * pte for a smaller charge. | ||
3516 | */ | ||
3517 | if (unlikely(ret & VM_FAULT_OOM)) | ||
3518 | goto retry; | ||
3519 | return ret; | ||
3520 | } | ||
3509 | return 0; | 3521 | return 0; |
3510 | } | 3522 | } |
3511 | } | 3523 | } |