[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4z6d3nxnHfiCjK-sVL=DMgW_CceeFKxvMpzwJ+rHPR=0A@mail.gmail.com>
Date: Tue, 24 Jun 2025 10:38:22 +1200
From: Barry Song <21cnbao@...il.com>
To: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>, David Hildenbrand <david@...hat.com>, Zi Yan <ziy@...dia.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>, Nico Pache <npache@...hat.com>,
Ryan Roberts <ryan.roberts@....com>, Dev Jain <dev.jain@....com>,
Vlastimil Babka <vbabka@...e.cz>, Jann Horn <jannh@...gle.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Lance Yang <ioworker0@...il.com>,
SeongJae Park <sj@...nel.org>, Suren Baghdasaryan <surenb@...gle.com>
Subject: Re: [PATCH v2 1/5] mm/madvise: remove the visitor pattern and thread
anon_vma state
On Sat, Jun 21, 2025 at 3:33 AM Lorenzo Stoakes
<lorenzo.stoakes@...cle.com> wrote:
>
> Now we have the madvise_behavior helper struct we no longer need to mess
> around with void* pointers in order to propagate anon_vma_name, and this
> means we can get rid of the confusing and inconsistent visitor pattern
> implementation in madvise_vma_anon_name().
>
> This means we now have a single state object that threads through most of
> madvise()'s logic and a single code path which executes the majority of
> madvise() behaviour (we maintain separate logic for failure injection and
> memory population for the time being).
>
> We are able to remove the visitor pattern by handling the anon_vma_name
> setting logic via an internal madvise flag - __MADV_SET_ANON_VMA_NAME. This
> uses a negative value so it isn't reasonable that we will ever add this as
> a UAPI flag.
>
> Additionally, the madvise_behavior_valid() check ensures that
> user-specified behaviours are strictly only those we permit which, of
> course, this flag will be excluded from.
>
> We are able to propagate the anon_vma_name object through use of the
> madvise_behavior helper struct.
>
> Doing this results in a can_modify_vma_madv() check for anonymous VMA name
> changes, however this will cause no issues as this operation is not
> prohibited.
>
> We can also then reuse more code and drop the redundant
> madvise_vma_anon_name() function altogether.
>
> Additionally separate out behaviours that update VMAs from those that do
> not.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
LGTM,
Reviewed-by: Barry Song <baohua@...nel.org>
>
> /* We cannot provide prev in this lock mode. */
> - VM_WARN_ON_ONCE(arg->lock_mode == MADVISE_VMA_READ_LOCK);
> - anon_name = anon_vma_name(vma);
> - anon_vma_name_get(anon_name);
> + VM_WARN_ON_ONCE(madv_behavior->lock_mode == MADVISE_MMAP_WRITE_LOCK);
> +
> + /*
I’m wondering whether it would be more accurate to:
VM_WARN_ON_ONCE(madv_behavior->lock_mode != MADVISE_WRITE_LOCK);
Thanks
Barry
Powered by blists - more mailing lists