linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Refactor vm_mixed_ok() for more maintainable
@ 2025-10-21  8:53 Zhen Ni
  2025-10-21  9:14 ` Lorenzo Stoakes
  0 siblings, 1 reply; 3+ messages in thread
From: Zhen Ni @ 2025-10-21  8:53 UTC (permalink / raw)
  To: akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb,
	mhocko
  Cc: linux-mm, Zhen Ni

Restructure the function without altering its logic:
- Check the VM_MIXEDMAP flag first as a fast path.
- Consolidate the zero page handling logic into a single, dedicated
block.

These changes improve code organization and maintainability.

Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---
 mm/memory.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 74b45e258323..4f882c58dbc2 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2706,14 +2706,17 @@ EXPORT_SYMBOL(vmf_insert_pfn);
 static bool vm_mixed_ok(struct vm_area_struct *vma, unsigned long pfn,
 			bool mkwrite)
 {
-	if (unlikely(is_zero_pfn(pfn)) &&
-	    (mkwrite || !vm_mixed_zeropage_allowed(vma)))
-		return false;
 	/* these checks mirror the abort conditions in vm_normal_page */
 	if (vma->vm_flags & VM_MIXEDMAP)
 		return true;
-	if (is_zero_pfn(pfn))
+	if (unlikely(is_zero_pfn(pfn))) {
+		/* Zero pages can only be mapped read-only and if VMA
+		 * allows them.
+		 */
+		if (mkwrite || !vm_mixed_zeropage_allowed(vma))
+			return false;
 		return true;
+	}
 	return false;
 }
 
-- 
2.20.1



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

end of thread, other threads:[~2025-10-21 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21  8:53 [PATCH] mm: Refactor vm_mixed_ok() for more maintainable Zhen Ni
2025-10-21  9:14 ` Lorenzo Stoakes
2025-10-21 10:20   ` zhen.ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).