linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Zi Yan <ziy@nvidia.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
	Jann Horn <jannh@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Lance Yang <ioworker0@gmail.com>, SeongJae Park <sj@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH 3/5] mm/madvise: thread VMA range state through madvise_behavior
Date: Fri, 20 Jun 2025 06:17:45 +0100	[thread overview]
Message-ID: <2718d196-dd11-404e-906a-962629923be6@lucifer.local> (raw)
In-Reply-To: <3651A1A2-6EB0-4731-BDB2-E11FF7E63749@nvidia.com>

On Thu, Jun 19, 2025 at 09:54:11PM -0400, Zi Yan wrote:
> On 19 Jun 2025, at 16:26, Lorenzo Stoakes wrote:
>
> > Rather than updating start and a confusing local parameter 'tmp' in
> > madvise_walk_vmas(), instead store the current range being operated upon in
> > the struct madvise_behavior helper object in a range pair and use this
> > consistently in all operations.
> >
> > This makes it clearer what is going on and opens the door to further
> > cleanup now we store state regarding what is currently being operated upon
> > here.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> > ---
> >  mm/madvise.c | 101 ++++++++++++++++++++++++++++-----------------------
> >  1 file changed, 55 insertions(+), 46 deletions(-)
> >
> > diff --git a/mm/madvise.c b/mm/madvise.c
> > index 47485653c2a1..6faa38b92111 100644
> > --- a/mm/madvise.c
> > +++ b/mm/madvise.c
> > @@ -58,17 +58,26 @@ enum madvise_lock_mode {
> >  	MADVISE_VMA_READ_LOCK,
> >  };
> >
> > +struct madvise_behavior_range {
> > +	unsigned long start, end;
> > +};
> > +
>
> Declare members separately?

Can do, but this is one of those subject things where everyone has different
views, if I did it the other way no doubt somebody else would comment about
declaring together :P

I think as a range here it's not a big deal unless you feel strongly about it?

>
> <snip>
>
> > @@ -1425,10 +1437,11 @@ static int madvise_vma_behavior(struct vm_area_struct *vma,
> >  /*
> >   * Error injection support for memory error handling.
> >   */
> > -static int madvise_inject_error(unsigned long start, unsigned long end,
> > -		struct madvise_behavior *madv_behavior)
> > +static int madvise_inject_error(struct madvise_behavior *madv_behavior)
> >  {
> >  	unsigned long size;
> > +	unsigned long start = madv_behavior->range.start;
> > +	unsigned long end = madv_behavior->range.end;
> >
> >  	if (!capable(CAP_SYS_ADMIN))
> >  		return -EPERM;
> > @@ -1482,8 +1495,7 @@ static bool is_memory_failure(struct madvise_behavior *madv_behavior)
> >
> >  #else
> >
> > -static int madvise_inject_error(unsigned long start, unsigned long end,
> > -		struct madvise_behavior *madv_behavior)
> > +static int madvise_inject_error(struct madvise_behavior *madv_behavior)
> >  {
> >  	return 0;
> >  }
>
> OK, now I get why you pass struct madvise_behavior to madvise_inject_error()
> in Patch 2. The changes make sense to me now. Maybe delay that conversation
> in this one.

I think it's valuable there because otherwise all the function invocations were
inconsistent, but after 2/5 become completely consistent. I mention this in the
commit message and I think it's valuable so you're not doing:

if (foo)
	bar(x, y, z)

if (blah)
	baz(y, x, z)

etc.

When you quickly read through it's easy to get confused/lost as to what's going
on, whereas if they all have the same signatures it's very clear you're
offloading the heavy lifting to each function.

>
>
>
> > @@ -1565,20 +1577,20 @@ static bool process_madvise_remote_valid(int behavior)
> >   * If a VMA read lock could not be acquired, we return NULL and expect caller to
> >   * fallback to mmap lock behaviour.
> >   */
> > -static struct vm_area_struct *try_vma_read_lock(struct mm_struct *mm,
> > -		struct madvise_behavior *madv_behavior,
> > -		unsigned long start, unsigned long end)
> > +static
> > +struct vm_area_struct *try_vma_read_lock(struct madvise_behavior *madv_behavior)
> >  {
> > +	struct mm_struct *mm = madv_behavior->mm;
>
> Is the struct mm_struct removal missed in Patch 2?

Yeah, I will go back and put it in on respin.

>
>
> <snip>
>
> > @@ -1846,22 +1854,23 @@ static int madvise_do_behavior(unsigned long start, size_t len_in,
> >  		struct madvise_behavior *madv_behavior)
> >  {
> >  	struct blk_plug plug;
> > -	unsigned long end;
> >  	int error;
> > +	struct madvise_behavior_range *range = &madv_behavior->range;
> >
> >  	if (is_memory_failure(madv_behavior)) {
> > -		end = start + len_in;
> > -		return madvise_inject_error(start, end, madv_behavior);
> > +		range->start = start;
> > +		range->end = start + len_in;
> > +		return madvise_inject_error(madv_behavior);
> >  	}
> >
> > -	start = get_untagged_addr(madv_behavior->mm, start);
> > -	end = start + PAGE_ALIGN(len_in);
> > +	range->start = get_untagged_addr(madv_behavior->mm, start);
> > +	range->end = range->start + PAGE_ALIGN(len_in);
> >
> >  	blk_start_plug(&plug);
> >  	if (is_madvise_populate(madv_behavior))
> > -		error = madvise_populate(start, end, madv_behavior);
> > +		error = madvise_populate(madv_behavior);
> >  	else
> > -		error = madvise_walk_vmas(start, end, madv_behavior);
> > +		error = madvise_walk_vmas(madv_behavior);
> >  	blk_finish_plug(&plug);
> >  	return error;
> >  }
>
> We almost can pass just struct madvise_behavior to madvise_do_behavior().
> I wonder why memory_failure behaves differently.

There's complexity around the start, end stuff (Barry bumped into some of this)
and I don't want to mess with that in this series. This series is meant to have
no functional changes.

>
> --
> Best Regards,
> Yan, Zi


  parent reply	other threads:[~2025-06-20  5:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-19 20:26 [PATCH 0/5] madvise cleanup Lorenzo Stoakes
2025-06-19 20:26 ` [PATCH 1/5] mm/madvise: remove the visitor pattern and thread anon_vma state Lorenzo Stoakes
2025-06-20  1:32   ` Zi Yan
2025-06-20  2:43     ` Lance Yang
2025-06-20  5:10       ` Lorenzo Stoakes
2025-06-20  5:08     ` Lorenzo Stoakes
2025-06-20 13:05   ` Vlastimil Babka
2025-06-20 13:17     ` Lorenzo Stoakes
2025-06-19 20:26 ` [PATCH 2/5] mm/madvise: thread mm_struct through madvise_behavior Lorenzo Stoakes
2025-06-20  1:40   ` Zi Yan
2025-06-20  5:12     ` Lorenzo Stoakes
2025-06-20 13:19   ` Vlastimil Babka
2025-06-19 20:26 ` [PATCH 3/5] mm/madvise: thread VMA range state " Lorenzo Stoakes
2025-06-20  1:54   ` Zi Yan
2025-06-20  2:13     ` Zi Yan
2025-06-20  5:21       ` Lorenzo Stoakes
2025-06-20  5:17     ` Lorenzo Stoakes [this message]
2025-06-20 13:49   ` Vlastimil Babka
2025-06-20 13:51     ` Lorenzo Stoakes
2025-06-20 14:16     ` Lorenzo Stoakes
2025-06-19 20:26 ` [PATCH 4/5] mm/madvise: thread all madvise state through madv_behavior Lorenzo Stoakes
2025-06-20  2:20   ` Zi Yan
2025-06-20  5:21     ` Lorenzo Stoakes
2025-06-20 14:16   ` Vlastimil Babka
2025-06-20 14:17     ` Lorenzo Stoakes
2025-06-20 14:32   ` Vlastimil Babka
2025-06-20 14:58     ` Lorenzo Stoakes
2025-06-19 20:26 ` [PATCH 5/5] mm/madvise: eliminate very confusing manipulation of prev VMA Lorenzo Stoakes
2025-06-20 15:02   ` Vlastimil Babka

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=2718d196-dd11-404e-906a-962629923be6@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=ioworker0@gmail.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=sj@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=ziy@nvidia.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