All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: Pedro Falcato <pfalcato@suse.de>,
	 Andrew Morton <akpm@linux-foundation.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	 Vlastimil Babka <vbabka@kernel.org>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	 David Hildenbrand <david@kernel.org>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	 Jonathan Corbet <corbet@lwn.net>,
	Randy Dunlap <rdunlap@infradead.org>,
	 Jann Horn <jannh@google.com>,
	linux-mm@kvack.org, linux-doc@vger.kernel.org,
	 linux-kernel@vger.kernel.org,
	"Jose A. Perez de Azpillaga" <azpijr@gmail.com>,
	 Daehyeon Ko <4ncienth@gmail.com>
Subject: Re: [PATCH v2] mm/vma: avoid spurious write locks when mm->mm_lock_seq overflows
Date: Thu, 29 Oct 2026 09:18:20 +0000	[thread overview]
Message-ID: <auMHSGBR6SB6HcTZ@gremlin> (raw)
In-Reply-To: <CAJuCfpFVv-t08YGMPR3YHCyiOK4HY-YjMk5rB6tdBa=mq2MvKQ@mail.gmail.com>

On Wed, Oct 28, 2026 at 05:34:38PM -0700, Suren Baghdasaryan wrote:
> Sorry for missing this fix before (due to my vacation) and only now

Never apologise for taking a holiday ;)

> finding it. From a quick look it seems correct but I'll spend some
> more time reviewing and testing it.
> Thanks Lorenzo for the fix! I completely overlooked this overflow
> side-effect. And thanks to Liam for flagging it!

No worries, though it has already been merged -> Linus's tree (lol). Obviously
if you find anything of concern we can chase up!

The general idea is simple, really - though there's nuances with the memory
barriers (ugh).

First off, it turns out we don't have to use UINT_MAX when initialising a
VMA, since commit e5e7fb278e59 ("mm: convert mm_lock_seq to a proper
seqcount"), as 0 works just as well (it's not observed since VMA is
detached at that point).

Then we can simply detect when there's about to be an overflow, and zero
every VMA's write seqcount.

This is done without VMA write lock and with potential concurrent
readers. Which is fine, since the write locks are about to be unlocked
anyway, so any write-locked VMAs can either be encountered as write-locked
or not-write-locked safely.

0 is even, so that marks everything as unlocked. However, to avoid read
locks spuriously failing due to vma->vm_lock_seq == mm->mm_lock_seq, that
check is updated to also test whether the seqlock is odd (write-locked), if
not it allows a read-lock.

Since the 'reset' doesn't acquire VMA write lock (not required and not
really meaningful in the context), nor does it block read locks, it causes
no interruptions on that side.

And, as per the numbers I got the LLM to obtain that I shared with Pedro,
there's no meaningful latency when this happens, which for most workloads
takes ~days/weeks to achieve.

For backports, which lack my anon pgoff stuff, I will simply make the
fields 64-bit which make it practically impossible to hit the issue.

Let me know if you have any questions/concerns, thanks!

-- Cheers, Lorenzo


      reply	other threads:[~2026-10-29  9:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 11:34 [PATCH v2] mm/vma: avoid spurious write locks when mm->mm_lock_seq overflows Lorenzo Stoakes (ARM)
2026-10-16 12:16 ` Jose A. Perez de Azpillaga
2026-10-16 14:55 ` Lorenzo Stoakes (ARM)
2026-10-17  3:12 ` Andrew Morton
2026-10-19  9:53 ` Pedro Falcato
2026-10-19 12:19   ` Lorenzo Stoakes (ARM)
2026-10-19 14:32     ` Andrew Morton
2026-10-19 14:39       ` Lorenzo Stoakes (ARM)
2026-10-19 14:40         ` Lorenzo Stoakes (ARM)
2026-10-28 15:04     ` Lorenzo Stoakes (ARM)
2026-10-28 15:06       ` Pedro Falcato
2026-10-29  0:34         ` Suren Baghdasaryan
2026-10-29  9:18           ` Lorenzo Stoakes (ARM) [this message]

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=auMHSGBR6SB6HcTZ@gremlin \
    --to=ljs@kernel.org \
    --cc=4ncienth@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=azpijr@gmail.com \
    --cc=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=jannh@google.com \
    --cc=liam@infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=pfalcato@suse.de \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.