[6/6] mm: memory: use folio_prealloc() in do_anonymous_page()

Message ID 20231107135216.415926-7-wangkefeng.wang@huawei.com
State New
Headers
Series mm: cleanup and use more folio in page fault |

Commit Message

Kefeng Wang Nov. 7, 2023, 1:52 p.m. UTC
  Use folio_prealloc() to simplify code a bit.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/memory.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
  

Patch

diff --git a/mm/memory.c b/mm/memory.c
index 1a7dc19bd35d..e4deab750a51 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4167,14 +4167,10 @@  static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
 
 	/* Allocate our own private page. */
 	if (unlikely(anon_vma_prepare(vma)))
-		goto oom;
-	folio = vma_alloc_zeroed_movable_folio(vma, vmf->address);
+		return VM_FAULT_OOM;
+	folio = folio_prealloc(vma->vm_mm, vma, vmf->address, true);
 	if (!folio)
-		goto oom;
-
-	if (mem_cgroup_charge(folio, vma->vm_mm, GFP_KERNEL))
-		goto oom_free_page;
-	folio_throttle_swaprate(folio, GFP_KERNEL);
+		return VM_FAULT_OOM;
 
 	/*
 	 * The memory barrier inside __folio_mark_uptodate makes sure that
@@ -4225,10 +4221,6 @@  static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
 release:
 	folio_put(folio);
 	goto unlock;
-oom_free_page:
-	folio_put(folio);
-oom:
-	return VM_FAULT_OOM;
 }
 
 /*