From: Yajun Deng <yajun.deng@linux.dev>
To: akpm@linux-foundation.org
Cc: Liam.Howlett@Oracle.com, lstoakes@gmail.com,
viro@zeniv.linux.org.uk, brauner@kernel.org, vbabka@suse.cz,
willy@infradead.org, surenb@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH v2 2/2] mm/mmap: remove find_vma_intersection() in vma_merge()
Date: Thu, 25 Jan 2024 11:49:22 +0800 [thread overview]
Message-ID: <20240125034922.1004671-3-yajun.deng@linux.dev> (raw)
In-Reply-To: <20240125034922.1004671-1-yajun.deng@linux.dev>
We need to find the current vma by find_vma_intersection() in
vma_merge(). Since the src vma was passed, we can add a check to figure
out if the current vma is NULL or the src vma directly.
Remove find_vma_intersection() in vma_merge(). And initialize the next to
NULL when defining it.
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
mm/mmap.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index f19bc53bc08e..ea02fdc91aa2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -869,7 +869,7 @@ static struct vm_area_struct
struct mm_struct *mm = src->vm_mm;
struct anon_vma *anon_vma = src->anon_vma;
struct file *file = src->vm_file;
- struct vm_area_struct *curr, *next, *res;
+ struct vm_area_struct *curr = src, *next = NULL, *res;
struct vm_area_struct *vma, *adjust, *remove, *remove2;
struct vm_area_struct *anon_dup = NULL;
struct vma_prepare vp;
@@ -890,14 +890,18 @@ static struct vm_area_struct
if (vm_flags & VM_SPECIAL)
return NULL;
- /* Does the input range span an existing VMA? (cases 5 - 8) */
- curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end);
+ /*
+ * If the current vma and the prev vma are the same vma, it
+ * means the current vma is NULL.
+ * Does the input range span an existing VMA? (cases 5 - 8)
+ */
+ if (prev == curr || addr != curr->vm_start || end > curr->vm_end)
+ curr = NULL;
if (!curr || /* cases 1 - 4 */
end == curr->vm_end) /* cases 6 - 8, adjacent VMA */
next = vma_lookup(mm, end);
- else
- next = NULL; /* case 5 */
+ /* case 5 set to NULL above */
if (prev) {
vma_start = prev->vm_start;
@@ -921,7 +925,6 @@ static struct vm_area_struct
/* Verify some invariant that must be enforced by the caller. */
VM_WARN_ON(prev && addr <= prev->vm_start);
- VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end));
VM_WARN_ON(addr >= end);
if (!merge_prev && !merge_next)
--
2.25.1
next prev parent reply other threads:[~2024-01-25 3:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 3:49 [PATCH v2 0/2] mm/mmap: simplify vma_merge() Yajun Deng
2024-01-25 3:49 ` [PATCH v2 1/2] mm/mmap: pass vma to vma_merge() Yajun Deng
2024-01-26 2:25 ` Liam R. Howlett
2024-01-25 3:49 ` Yajun Deng [this message]
2024-01-26 2:28 ` [PATCH v2 2/2] mm/mmap: remove find_vma_intersection() in vma_merge() Liam R. Howlett
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=20240125034922.1004671-3-yajun.deng@linux.dev \
--to=yajun.deng@linux.dev \
--cc=Liam.Howlett@Oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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).