linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] mm: do not increment pgfault stats when page fault handler retries
@ 2023-04-14 17:54 Suren Baghdasaryan
  2023-04-14 18:11 ` Matthew Wilcox
  2023-04-14 21:47 ` Peter Xu
  0 siblings, 2 replies; 8+ messages in thread
From: Suren Baghdasaryan @ 2023-04-14 17:54 UTC (permalink / raw)
  To: akpm
  Cc: willy, hannes, mhocko, josef, jack, ldufour, laurent.dufour,
	michel, liam.howlett, jglisse, vbabka, minchan, dave,
	punit.agrawal, lstoakes, surenb, linux-mm, linux-kernel,
	kernel-team

If the page fault handler requests a retry, we will count the fault
multiple times.  This is a relatively harmless problem as the retry paths
are not often requested, and the only user-visible problem is that the
fault counter will be slightly higher than it should be.  Nevertheless,
userspace only took one fault, and should not see the fact that the
kernel had to retry the fault multiple times.

Fixes: 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
Patch applies cleanly over linux-next and mm-unstable

 mm/memory.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 1c5b231fe6e3..d88f370eacd1 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5212,17 +5212,16 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
 
 	__set_current_state(TASK_RUNNING);
 
-	count_vm_event(PGFAULT);
-	count_memcg_event_mm(vma->vm_mm, PGFAULT);
-
 	ret = sanitize_fault_flags(vma, &flags);
 	if (ret)
-		return ret;
+		goto out;
 
 	if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE,
 					    flags & FAULT_FLAG_INSTRUCTION,
-					    flags & FAULT_FLAG_REMOTE))
-		return VM_FAULT_SIGSEGV;
+					    flags & FAULT_FLAG_REMOTE)) {
+		ret = VM_FAULT_SIGSEGV;
+		goto out;
+	}
 
 	/*
 	 * Enable the memcg OOM handling for faults triggered in user
@@ -5253,6 +5252,11 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
 	}
 
 	mm_account_fault(regs, address, flags, ret);
+out:
+	if (!(ret & VM_FAULT_RETRY)) {
+		count_vm_event(PGFAULT);
+		count_memcg_event_mm(vma->vm_mm, PGFAULT);
+	}
 
 	return ret;
 }
-- 
2.40.0.634.g4ca3ef3211-goog



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-15  0:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-14 17:54 [PATCH 1/1] mm: do not increment pgfault stats when page fault handler retries Suren Baghdasaryan
2023-04-14 18:11 ` Matthew Wilcox
2023-04-14 21:47 ` Peter Xu
2023-04-14 22:14   ` Suren Baghdasaryan
2023-04-14 22:26     ` Suren Baghdasaryan
2023-04-14 22:34     ` Peter Xu
2023-04-14 23:49       ` Suren Baghdasaryan
2023-04-15  0:11         ` Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox