From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
Suren Baghdasaryan <surenb@google.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>
Subject: [PATCH v3 06/15] mm: Remove re-walk from mmap_region()
Date: Mon, 24 Jul 2023 14:31:48 -0400 [thread overview]
Message-ID: <20230724183157.3939892-7-Liam.Howlett@oracle.com> (raw)
In-Reply-To: <20230724183157.3939892-1-Liam.Howlett@oracle.com>
Using vma_iter_set() will reset the tree and cause a re-walk. Use
vmi_iter_config() to set the write to a sub-set of the range. Change
the file case to also use vmi_iter_config() so that the end is correctly
set.
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
mm/internal.h | 8 ++++++++
mm/mmap.c | 15 ++++++++++-----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/mm/internal.h b/mm/internal.h
index 7d11ebe5d11c..c5ba08f55deb 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1041,6 +1041,14 @@ static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma)
return !(vma->vm_flags & VM_SOFTDIRTY);
}
+static inline void vma_iter_config(struct vma_iterator *vmi,
+ unsigned long index, unsigned long last)
+{
+ MAS_BUG_ON(&vmi->mas, vmi->mas.node != MAS_START &&
+ (vmi->mas.index > index || vmi->mas.last < index));
+ __mas_set_range(&vmi->mas, index, last - 1);
+}
+
/*
* VMA Iterator functions shared between nommu and mmap
*/
diff --git a/mm/mmap.c b/mm/mmap.c
index d4056d1de7fa..f518e4c70a7b 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2675,8 +2675,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
next = vma_next(&vmi);
prev = vma_prev(&vmi);
- if (vm_flags & VM_SPECIAL)
+ if (vm_flags & VM_SPECIAL) {
+ if (prev)
+ vma_iter_next_range(&vmi);
goto cannot_expand;
+ }
/* Attempt to expand an old mapping */
/* Check next */
@@ -2697,6 +2700,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
merge_start = prev->vm_start;
vma = prev;
vm_pgoff = prev->vm_pgoff;
+ } else if (prev) {
+ vma_iter_next_range(&vmi);
}
@@ -2707,9 +2712,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
goto expanded;
}
+ if (vma == prev)
+ vma_iter_set(&vmi, addr);
cannot_expand:
- if (prev)
- vma_iter_next_range(&vmi);
/*
* Determine the object being mapped and call the appropriate
@@ -2722,7 +2727,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
goto unacct_error;
}
- vma_iter_set(&vmi, addr);
+ vma_iter_config(&vmi, addr, end);
vma->vm_start = addr;
vma->vm_end = end;
vm_flags_init(vma, vm_flags);
@@ -2749,7 +2754,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
if (WARN_ON((addr != vma->vm_start)))
goto close_and_free_vma;
- vma_iter_set(&vmi, addr);
+ vma_iter_config(&vmi, addr, end);
/*
* If vm_flags changed after call_mmap(), we should try merge
* vma again as we may succeed this time.
--
2.39.2
next prev parent reply other threads:[~2023-07-24 18:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 18:31 [PATCH v3 00/15] Reduce preallocations for maple tree Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 01/15] maple_tree: Add benchmarking for mas_for_each Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 02/15] maple_tree: Add benchmarking for mas_prev() Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 03/15] mm: Change do_vmi_align_munmap() tracking of VMAs to remove Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 04/15] mm: Remove prev check from do_vmi_align_munmap() Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 05/15] maple_tree: Introduce __mas_set_range() Liam R. Howlett
2023-07-24 18:31 ` Liam R. Howlett [this message]
2023-07-24 18:31 ` [PATCH v3 07/15] maple_tree: Re-introduce entry to mas_preallocate() arguments Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 08/15] maple_tree: Adjust node allocation on mas_rebalance() Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 09/15] mm: Use vma_iter_clear_gfp() in nommu Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 10/15] mm: Set up vma iterator for vma_iter_prealloc() calls Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 11/15] maple_tree: Move mas_wr_end_piv() below mas_wr_extend_null() Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 12/15] maple_tree: Update mas_preallocate() testing Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 13/15] maple_tree: Refine mas_preallocate() node calculations Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 14/15] maple_tree: Reduce resets during store setup Liam R. Howlett
2023-07-24 18:31 ` [PATCH v3 15/15] mm/mmap: Change vma iteration order in do_vmi_align_munmap() Liam R. Howlett
2023-08-14 15:43 ` Jann Horn
2023-08-14 19:10 ` Andrew Morton
2023-08-14 19:18 ` Liam R. Howlett
2023-08-14 21:22 ` Jann Horn
2023-08-15 7:29 ` Liam R. Howlett
2023-08-15 14:19 ` Jann Horn
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=20230724183157.3939892-7-Liam.Howlett@oracle.com \
--to=liam.howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maple-tree@lists.infradead.org \
--cc=surenb@google.com \
/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