From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Oliver Sang <oliver.sang@intel.com>
Cc: oe-lkp@lists.linux.dev, lkp@intel.com,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Mark Brown <broonie@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>,
Bert Karwatzki <spasswolf@web.de>, Jeff Xu <jeffxu@chromium.org>,
Jiri Olsa <olsajiri@gmail.com>, Kees Cook <kees@kernel.org>,
Lorenzo Stoakes <lstoakes@gmail.com>,
Matthew Wilcox <willy@infradead.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Paul Moore <paul@paul-moore.com>,
Sidhartha Kumar <sidhartha.kumar@oracle.com>,
Suren Baghdasaryan <surenb@google.com>,
linux-mm@kvack.org, ying.huang@intel.com, feng.tang@intel.com,
fengwei.yin@intel.com
Subject: Re: [linus:master] [mm] cacded5e42: aim9.brk_test.ops_per_sec -5.0% regression
Date: Wed, 9 Oct 2024 22:24:58 +0100 [thread overview]
Message-ID: <5b7227fa-d0f1-452e-b1b3-9d7b87641522@lucifer.local> (raw)
In-Reply-To: <ZwYmTnWEhgWO702t@xsang-OptiPlex-9020>
On Wed, Oct 09, 2024 at 02:44:30PM +0800, Oliver Sang wrote:
[snip]
> >
> > I will look into this now, if I provide patches would you be able to test
> > them using the same boxes? It'd be much appreciated!
>
> sure! that's our pleasure!
>
Hi Oliver,
Thanks so much for this, could you give the below a try? I've not tried to
seriously test it locally yet, so it'd be good to set your test machines on
it.
If this doesn't help it suggests call stack/branching might be a thing here
in which case I have other approaches I can take before we have to
duplicate this code.
This patch is against the mm-unstable branch in Andrew's tree [0] but
hopefully should apply fine to Linus's too.
[0]:https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/
Thanks again!
Best, Lorenzo
----8<----
From 7eb4aa421b357668bc44405c58b0444abf44334a Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Date: Wed, 9 Oct 2024 21:57:03 +0100
Subject: [PATCH] mm: explicitly enable an expand-only merge mode for brk()
Try to do less work on brk() to improve perf.
---
mm/mmap.c | 1 +
mm/vma.c | 25 ++++++++++++++++---------
mm/vma.h | 11 +++++++++++
3 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 02f7b45c3076..c2c68ef45a3b 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1740,6 +1740,7 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma,
if (vma && vma->vm_end == addr) {
VMG_STATE(vmg, mm, vmi, addr, addr + len, flags, PHYS_PFN(addr));
+ vmg.mode = VMA_MERGE_MODE_EXPAND_ONLY;
vmg.prev = vma;
vma_iter_next_range(vmi);
diff --git a/mm/vma.c b/mm/vma.c
index 749c4881fd60..f525a0750c41 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -561,6 +561,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)
unsigned long end = vmg->end;
pgoff_t pgoff = vmg->pgoff;
pgoff_t pglen = PHYS_PFN(end - start);
+ bool expand_only = vmg_mode_expand_only(vmg);
bool can_merge_left, can_merge_right;
mmap_assert_write_locked(vmg->mm);
@@ -575,7 +576,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)
return NULL;
can_merge_left = can_vma_merge_left(vmg);
- can_merge_right = can_vma_merge_right(vmg, can_merge_left);
+ can_merge_right = !expand_only && can_vma_merge_right(vmg, can_merge_left);
/* If we can merge with the next VMA, adjust vmg accordingly. */
if (can_merge_right) {
@@ -603,13 +604,18 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)
return vmg->vma;
}
- /* If expansion failed, reset state. Allows us to retry merge later. */
- vmg->vma = NULL;
- vmg->start = start;
- vmg->end = end;
- vmg->pgoff = pgoff;
- if (vmg->vma == prev)
- vma_iter_set(vmg->vmi, start);
+ /*
+ * Unless in expand only case and expansion failed, reset state.
+ * Allows us to retry merge later.
+ */
+ if (!expand_only) {
+ vmg->vma = NULL;
+ vmg->start = start;
+ vmg->end = end;
+ vmg->pgoff = pgoff;
+ if (vmg->vma == prev)
+ vma_iter_set(vmg->vmi, start);
+ }
return NULL;
}
@@ -641,7 +647,8 @@ int vma_expand(struct vma_merge_struct *vmg)
mmap_assert_write_locked(vmg->mm);
vma_start_write(vma);
- if (next && (vma != next) && (vmg->end == next->vm_end)) {
+ if (!vmg_mode_expand_only(vmg) && next &&
+ (vma != next) && (vmg->end == next->vm_end)) {
int ret;
remove_next = true;
diff --git a/mm/vma.h b/mm/vma.h
index 82354fe5edd0..14224b36a979 100644
--- a/mm/vma.h
+++ b/mm/vma.h
@@ -52,6 +52,11 @@ struct vma_munmap_struct {
unsigned long data_vm;
};
+enum vma_merge_mode {
+ VMA_MERGE_MODE_NORMAL,
+ VMA_MERGE_MODE_EXPAND_ONLY,
+};
+
enum vma_merge_state {
VMA_MERGE_START,
VMA_MERGE_ERROR_NOMEM,
@@ -75,9 +80,15 @@ struct vma_merge_struct {
struct mempolicy *policy;
struct vm_userfaultfd_ctx uffd_ctx;
struct anon_vma_name *anon_name;
+ enum vma_merge_mode mode;
enum vma_merge_state state;
};
+static inline bool vmg_mode_expand_only(struct vma_merge_struct *vmg)
+{
+ return vmg->mode == VMA_MERGE_MODE_EXPAND_ONLY;
+}
+
static inline bool vmg_nomem(struct vma_merge_struct *vmg)
{
return vmg->state == VMA_MERGE_ERROR_NOMEM;
--
2.46.2
next prev parent reply other threads:[~2024-10-09 21:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 2:21 kernel test robot
2024-09-30 8:21 ` Lorenzo Stoakes
2024-10-08 8:31 ` Oliver Sang
2024-10-08 8:44 ` Lorenzo Stoakes
2024-10-09 6:44 ` Oliver Sang
2024-10-09 9:52 ` Lorenzo Stoakes
2024-10-09 21:24 ` Lorenzo Stoakes [this message]
2024-10-11 2:46 ` Oliver Sang
2024-10-11 7:26 ` Lorenzo Stoakes
2024-10-15 19:56 ` Lorenzo Stoakes
2024-10-17 2:58 ` Oliver Sang
2024-10-17 8:54 ` Lorenzo Stoakes
2024-10-18 0:34 ` Oliver Sang
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=5b7227fa-d0f1-452e-b1b3-9d7b87641522@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=broonie@kernel.org \
--cc=feng.tang@intel.com \
--cc=fengwei.yin@intel.com \
--cc=jeffxu@chromium.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=lstoakes@gmail.com \
--cc=oe-lkp@lists.linux.dev \
--cc=oliver.sang@intel.com \
--cc=olsajiri@gmail.com \
--cc=paul@paul-moore.com \
--cc=paulmck@kernel.org \
--cc=sidhartha.kumar@oracle.com \
--cc=spasswolf@web.de \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ying.huang@intel.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