All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-mm@kvack.org, Shuah Khan <shuah@kernel.org>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	Lorenzo Stoakes <lstoakes@gmail.com>,
	Kirill A Shutemov <kirill@shutemov.name>,
	"Liam R. Howlett" <liam.howlett@oracle.com>,
	"Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [PATCH RFC 1/4] mm/mremap: Optimize the start addresses in move_page_tables()
Date: Thu, 18 May 2023 14:44:40 +0000	[thread overview]
Message-ID: <20230518144440.GA813364@google.com> (raw)
In-Reply-To: <CAHk-=wi20GzWeK=vUoreX6AXOEmeJKczou1McCOC9JytVO=TQg@mail.gmail.com>

On Wed, May 17, 2023 at 09:12:07PM -0700, Linus Torvalds wrote:
> On Wed, May 17, 2023 at 7:18 PM Joel Fernandes (Google)
> <joel@joelfernandes.org> wrote:
> >
> > This warning will only trigger when there is mutual alignment in the
> > move operation. A solution, as suggested by Linus Torvalds [2], is to
> > initiate the copy process at the PMD level whenever such alignment is
> > present.
> 
> So this patch is actually simpler than I thought it would be.
> 
> But I'm a bit nervous about it. In particular, it ends doing
> 
>         old_end = old_addr + len;
>         ... expand old_addr/new_addr down to the pmd boundary ..
>         return len + old_addr - old_end;        /* how much done */
> 
> doesn't that return value end up being nonsensical now?

Aargh, Sorry to miss that. Yes, it ends up being bogus in the case where the
loop broke out early due to failure (but only on the first PMD move failure
AFAICS). In the success case (or failures after the first PMD move), it does
not matter because old_addr is updated to what it was without the
optimization.

> In particular, I think it can return a *negative* value, because of
> how old_addr was moved down, and the "now much done" might indeed be
> "negative" in the sense that it failed the move even "before" the
> original starting point.
> 
> And that negative value then ends up being a large positive one as an
> "unsigned long", of course.
> 
> So I get the feeling that it wants something like
> 
>         if (old_addr + len < old_end)
>                 return 0;

I think that will fix it (thanks!). The main thing I think is to not mess up
the second call to move_page_tables() in mremap where it tries to move the
half-moved stuff back:

  move_page_tables(new_vma, new_addr, vma, old_addr, moved_len,  true);

There moved_len comes from the return value of the first call to
move_page_tables().

If we realigned, and then the first PMD alloc failed, moved_len might be
negative as you pointed. If the first PMD move passed, then there is no
issue as I mentioned above.

I will fix this in the next revision and also add a test case for this, I am
wondering how to test it without some kind of error-injection to make the
first PMD copy fail. In any case, I will try to hack my local kernel to test
that.

thanks,

 - Joel


> there at the end.
> 
> But maybe there is something in there that guarantees that that case
> never happens. I didn't think too deeply about it, I just felt this
> looked odd.
> 
>                Linus

  reply	other threads:[~2023-05-18 14:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18  2:18 [PATCH RFC 0/4] Optimize mremap during mutual alignment within PMD Joel Fernandes (Google)
2023-05-18  2:18 ` [PATCH RFC 1/4] mm/mremap: Optimize the start addresses in move_page_tables() Joel Fernandes (Google)
2023-05-18  4:12   ` Linus Torvalds
2023-05-18 14:44     ` Joel Fernandes [this message]
2023-05-18  2:18 ` [PATCH RFC 2/4] selftests: mm: Fix failure case when new remap region was not found Joel Fernandes (Google)
2023-05-18  2:18 ` [PATCH RFC 3/4] selftests: mm: Add a test for mutually aligned moves > PMD size Joel Fernandes (Google)
2023-05-18  2:18 ` [PATCH RFC 4/4] selftests: mm: Add a test for remapping to area immediately after existing mapping Joel Fernandes (Google)

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=20230518144440.GA813364@google.com \
    --to=joel@joelfernandes.org \
    --cc=kirill@shutemov.name \
    --cc=liam.howlett@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=mhocko@suse.com \
    --cc=paulmck@kernel.org \
    --cc=shuah@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    /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.