From: John Hubbard <jhubbard@nvidia.com>
To: Joseph Salisbury <joseph.salisbury@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
Hugh Dickins <hughd@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Peter Xu <peterx@redhat.com>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Nhat Pham <nphamcs@gmail.com>, Baoquan He <bhe@redhat.com>,
Barry Song <baohua@kernel.org>,
linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] mm: stress-ng --mremap triggers severe lruvec lock contention in populate/unmap paths
Date: Tue, 7 Apr 2026 15:44:52 -0700 [thread overview]
Message-ID: <4a4f5b48-8a1d-48f8-8760-0f5d43b5d483@nvidia.com> (raw)
In-Reply-To: <a3474fcf-9f20-47ee-9d15-233e5c7e3f83@oracle.com>
On 4/7/26 1:09 PM, Joseph Salisbury wrote:
> Hello,
>
> I would like to ask for feedback on an MM performance issue triggered by
> stress-ng's mremap stressor:
>
> stress-ng --mremap 8192 --mremap-bytes 4K --timeout 30 --metrics-brief
>
> This was first investigated as a possible regression from 0ca0c24e3211
> ("mm: store zero pages to be swapped out in a bitmap"), but the current
> evidence suggests that commit is mostly exposing an older problem for
> this workload rather than directly causing it.
>
Can you try this out? (Adding Hugh to Cc.)
From: John Hubbard <jhubbard@nvidia.com>
Date: Tue, 7 Apr 2026 15:33:47 -0700
Subject: [PATCH] mm/gup: skip lru_add_drain() for non-locked populate
X-NVConfidentiality: public
Cc: John Hubbard <jhubbard@nvidia.com>
populate_vma_page_range() calls lru_add_drain() unconditionally after
__get_user_pages(). With high-frequency single-page MAP_POPULATE/munmap
cycles at high thread counts, this forces a lruvec->lru_lock acquire
per page, defeating per-CPU folio_batch batching.
The drain was added by commit ece369c7e104 ("mm/munlock: add
lru_add_drain() to fix memcg_stat_test") for VM_LOCKED populate, where
unevictable page stats must be accurate after faulting. Non-locked VMAs
have no such requirement. Skip the drain for them.
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
mm/gup.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/mm/gup.c b/mm/gup.c
index 8e7dc2c6ee73..2dd5de1cb5b9 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1816,6 +1816,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,
struct mm_struct *mm = vma->vm_mm;
unsigned long nr_pages = (end - start) / PAGE_SIZE;
int local_locked = 1;
+ bool need_drain;
int gup_flags;
long ret;
@@ -1857,9 +1858,19 @@ long populate_vma_page_range(struct vm_area_struct *vma,
* We made sure addr is within a VMA, so the following will
* not result in a stack expansion that recurses back here.
*/
+ /*
+ * Read VM_LOCKED before __get_user_pages(), which may drop
+ * mmap_lock when FOLL_UNLOCKABLE is set, after which the vma
+ * must not be accessed. The read is stable: mmap_lock is held
+ * for read here, so mlock() (which needs the write lock)
+ * cannot change VM_LOCKED concurrently.
+ */
+ need_drain = vma->vm_flags & VM_LOCKED;
+
ret = __get_user_pages(mm, start, nr_pages, gup_flags,
NULL, locked ? locked : &local_locked);
- lru_add_drain();
+ if (need_drain)
+ lru_add_drain();
return ret;
}
base-commit: 3036cd0d3328220a1858b1ab390be8b562774e8a
--
2.53.0
thanks,
--
John Hubbard
next prev parent reply other threads:[~2026-04-07 22:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 20:09 Joseph Salisbury
2026-04-07 21:47 ` Pedro Falcato
2026-04-08 8:09 ` David Hildenbrand (Arm)
2026-04-08 14:27 ` [External] : " Joseph Salisbury
2026-04-07 22:44 ` John Hubbard [this message]
2026-04-08 0:35 ` Hugh Dickins
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=4a4f5b48-8a1d-48f8-8760-0f5d43b5d483@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=bhe@redhat.com \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hughd@google.com \
--cc=jgg@ziepe.ca \
--cc=joseph.salisbury@oracle.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=peterx@redhat.com \
--cc=shikemeng@huaweicloud.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