linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	David Hildenbrand <david@redhat.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-mm@kvack.org,
	linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, Andrei Vagin <avagin@gmail.com>
Subject: Re: [PATCH v2 3/5] mm: implement sticky, copy on fork VMA flags
Date: Thu, 6 Nov 2025 15:33:36 +0100	[thread overview]
Message-ID: <3ba49b47-91a5-4a73-9dbd-b27f3956ae16@suse.cz> (raw)
In-Reply-To: <402256c9-8cfe-4943-9b3f-40f21c17292e@lucifer.local>

On 11/6/25 15:18, Lorenzo Stoakes wrote:
> On Thu, Nov 06, 2025 at 02:46:38PM +0100, Vlastimil Babka wrote:
>> On 11/6/25 11:46, Lorenzo Stoakes wrote:
>> > diff --git a/include/linux/mm.h b/include/linux/mm.h
>> > index 2ea65c646212..4d80eaf4ef3b 100644
>> > --- a/include/linux/mm.h
>> > +++ b/include/linux/mm.h
>> > @@ -527,6 +527,38 @@ extern unsigned int kobjsize(const void *objp);
>> >  #endif
>> >  #define VM_FLAGS_CLEAR	(ARCH_VM_PKEY_FLAGS | VM_ARCH_CLEAR)
>> >
>> > +/* Flags which should result in page tables being copied on fork. */
>> > +#define VM_COPY_ON_FORK VM_MAYBE_GUARD
>> > +
>> > +/*
>> > + * Flags which should be 'sticky' on merge - that is, flags which, when one VMA
>> > + * possesses it but the other does not, the merged VMA should nonetheless have
>> > + * applied to it:
>> > + *
>> > + * VM_COPY_ON_FORK - These flags indicates that a VMA maps a range that contains
>> > + *                   metadata which should be unconditionally propagated upon
>> > + *                   fork. When merging two VMAs, we encapsulate this range in
>> > + *                   the merged VMA, so the flag should be 'sticky' as a result.
>> > + */
>> > +#define VM_STICKY VM_COPY_ON_FORK
>>
>> TBH I don't see why there should be always an implication that copying on
>> fork implies stickiness in merging. Yeah, VM_MAYBE_GUARD is both, but in
>> general, is there any underlying property that makes this a rule?
> 
> Why do you copy on fork? It's because the page tables contain data that won't be
> reconstructed on fault.
> 
> If that is the case, that applies to any VMA which is merged, and also - since
> you can't be sure precisely which page tables contain the data we need to
> propagate - on split too.
> 
> This is why copy on fork implies sticky IMO.

Hmm I guess that makes some sense.
> I can update the commit message to make this clear if this makes sense?

It would help, thanks. Let's see if future will surprise us with some flag
where this won't be true :)

>>
>> > +/*
>> > + * VMA flags we ignore for the purposes of merge, i.e. one VMA possessing one
>> > + * of these flags and the other not does not preclude a merge.
>> > + *
>> > + * VM_SOFTDIRTY - Should not prevent from VMA merging, if we match the flags but
>> > + *                dirty bit -- the caller should mark merged VMA as dirty. If
>> > + *                dirty bit won't be excluded from comparison, we increase
>> > + *                pressure on the memory system forcing the kernel to generate
>> > + *                new VMAs when old one could be extended instead.
> 
> Note that I'm literally just moving the comment from is_mergeable_vma():
> 
> -	 * VM_SOFTDIRTY should not prevent from VMA merging, if we
> -	 * match the flags but dirty bit -- the caller should mark
> -	 * merged VMA as dirty. If dirty bit won't be excluded from
> -	 * comparison, we increase pressure on the memory system forcing
> -	 * the kernel to generate new VMAs when old one could be
> -	 * extended instead.
> 
> (OK I see you realised that below :P)
> 
>>
>> So I wonder if VM_SOFTDIRTY should be actually also sticky and not just
>> VM_IGNORE_MERGE. The way I understand the flag suggests it should.
>> Right now AFAICS its rather undefined if the result of vma merge has the
>> flag - depending on which of the two VMA's stays and which is removed by the
>> merge. "the caller should mark merged VMA as dirty" in the comment you're
>> moving here seems not really happening or I'm missing it. __mmap_complete()
> 
> No it's not happening, but I can't be blamed for existing incorrect comments :)
> 
>> and do_brk_flags() do it, so any new areas are marked, but on pure merge of
>> two vma's due to e.g. mprotect() this is really nondetermintic? AFAICT the
>> sticky flag behavior would work perfectly for VM_SOFTDIRTY.
> 
> Maybe we inavertantly changed this somehow or maybe it was just wrong, but we're
> not doing this on merge in general afaict.

Yeah wouldn't surprised me if we subtly changed it during some refactoring
and it's not causing such obvious issues to be noticed easily.

> I think you're right that we should make this sticky, but I'd rather deal with
> that in a follow-up series/patch as this is out of scope here.
> 
> Equally so I'd rather fix the comment in a follow up too for the same reason.

Sure it's just something I noticed and seems like a good fit for the new
concept.



  reply	other threads:[~2025-11-06 14:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06 10:46 [PATCH v2 0/5] introduce VM_MAYBE_GUARD and make it sticky Lorenzo Stoakes
2025-11-06 10:46 ` [PATCH v2 1/5] mm: introduce VM_MAYBE_GUARD and make visible in /proc/$pid/smaps Lorenzo Stoakes
2025-11-06 11:12   ` Vlastimil Babka
2025-11-06 13:56     ` Lorenzo Stoakes
2025-11-06 14:27   ` Pedro Falcato
2025-11-06 14:54     ` Lorenzo Stoakes
2025-11-06 14:58       ` Lorenzo Stoakes
2025-11-07  9:13       ` Alice Ryhl
2025-11-07  9:44         ` Lorenzo Stoakes
2025-11-07 12:12           ` Alice Ryhl
2025-11-07 12:40             ` Lorenzo Stoakes
2025-11-06 10:46 ` [PATCH v2 2/5] mm: add atomic VMA flags, use VM_MAYBE_GUARD as such Lorenzo Stoakes
2025-11-06 11:31   ` Vlastimil Babka
2025-11-06 14:03     ` Lorenzo Stoakes
2025-11-06 14:45   ` Pedro Falcato
2025-11-06 15:03     ` Lorenzo Stoakes
2025-11-06 10:46 ` [PATCH v2 3/5] mm: implement sticky, copy on fork VMA flags Lorenzo Stoakes
2025-11-06 13:46   ` Vlastimil Babka
2025-11-06 14:18     ` Lorenzo Stoakes
2025-11-06 14:33       ` Vlastimil Babka [this message]
2025-11-06 15:03   ` Pedro Falcato
2025-11-06 10:46 ` [PATCH v2 4/5] tools/testing/vma: add VMA sticky userland tests Lorenzo Stoakes
2025-11-06 10:46 ` [PATCH v2 5/5] selftests/mm/guard-regions: add smaps visibility test Lorenzo Stoakes

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=3ba49b47-91a5-4a73-9dbd-b27f3956ae16@suse.cz \
    --to=vbabka@suse.cz \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=avagin@gmail.com \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=jannh@google.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@suse.com \
    --cc=pfalcato@suse.de \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.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