mm page_fault: Reduce code complexity
diff mbox series

Message ID 1590663699-4541-1-git-send-email-yanghui.def@gmail.com
State New
Headers show
Series
  • mm page_fault: Reduce code complexity
Related show

Commit Message

hui yang May 28, 2020, 11:01 a.m. UTC
From: YangHui <yanghui.def@gmail.com>

if pte_alloc_one failed alloc a page, do_fault_around will return 0.
and it will come into __do_fault(), it also pte_alloc_one a page.
in __do_fault and do_fault_around, pte_alloc_one did the same thing,
if do_fault_around alloc page filed,we just let it return. there is
no need to come into __do_fault to do repetitive pte_alloc_one.

Signed-off-by: YangHui <yanghui.def@gmail.com>
---
 mm/memory.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Matthew Wilcox May 28, 2020, 11:45 a.m. UTC | #1
On Thu, May 28, 2020 at 07:01:39PM +0800, hui yang wrote:
> From: YangHui <yanghui.def@gmail.com>
> 
> if pte_alloc_one failed alloc a page, do_fault_around will return 0.
> and it will come into __do_fault(), it also pte_alloc_one a page.
> in __do_fault and do_fault_around, pte_alloc_one did the same thing,
> if do_fault_around alloc page filed,we just let it return. there is
> no need to come into __do_fault to do repetitive pte_alloc_one.

This really isn't "Reduce code complexity" though.  It's "Fail early
when memory allocation fails".  And, honestly, I don't see the point
of doing this.  You've optimised an incredibly rare failure path.

Patch
diff mbox series

diff --git a/mm/memory.c b/mm/memory.c
index f703fe8..a2d50a9 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3799,8 +3799,10 @@  static vm_fault_t do_fault_around(struct vm_fault *vmf)
 
 	if (pmd_none(*vmf->pmd)) {
 		vmf->prealloc_pte = pte_alloc_one(vmf->vma->vm_mm);
-		if (!vmf->prealloc_pte)
+		if (!vmf->prealloc_pte) {
+			ret = VM_FAULT_OOM;
 			goto out;
+		}
 		smp_wmb(); /* See comment in __pte_alloc() */
 	}