From: Zhen Ni <zhen.ni@easystack.cn>
To: akpm@linux-foundation.org, david@redhat.com,
lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com,
vbabka@suse.cz, rppt@kernel.org, surenb@google.com,
mhocko@suse.com
Cc: linux-mm@kvack.org, Zhen Ni <zhen.ni@easystack.cn>
Subject: [PATCH] mm: Refactor vm_mixed_ok() for more maintainable
Date: Tue, 21 Oct 2025 16:53:28 +0800 [thread overview]
Message-ID: <20251021085328.1900589-1-zhen.ni@easystack.cn> (raw)
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
next reply other threads:[~2025-10-21 8:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-21 8:53 Zhen Ni [this message]
2025-10-21 9:14 ` [PATCH] mm: Refactor vm_mixed_ok() for more maintainable Lorenzo Stoakes
2025-10-21 10:20 ` zhen.ni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251021085328.1900589-1-zhen.ni@easystack.cn \
--to=zhen.ni@easystack.cn \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).