linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Li Xinhai <lixinhai.lxh@gmail.com>, <linux-mm@kvack.org>
Cc: <akpm@linux-foundation.org>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH] mm/mremap.c: refactor finding vma and checking vma is alllowed to expand
Date: Sat, 2 Jan 2021 18:59:16 -0800	[thread overview]
Message-ID: <34739469-53ae-f786-509b-2ed9aace3572@nvidia.com> (raw)
In-Reply-To: <d209f236-4541-8b7e-62a2-303b5aeb8fac@gmail.com>

On 1/2/21 4:24 AM, Li Xinhai wrote:
> On 12/31/20 4:52 AM, John Hubbard wrote:
>> On 12/29/20 11:56 PM, Li Xinhai wrote:
>>> Function vma_to_resize)() is called to find the vma to be remapped and
>>> also check if expand size is allowed or not. This function assume that all
>>> call sites should make sure new_len >= old_len, and currently this
>>> assumption is fullfilled at those two call sites, so no real problem at
>>> present.
>>>
>>> After this patch, we explicitly check new_len < old_len case, and separate
>>> a new function for checking if expand size is allowed or not. Also rename
>>> vma_to_resize to vma_to_remap, since the vma to be remapped would not
>>> always require resize.
>>
>> I don't see any clear motivation for this code churn, either above, or
>> implicitly in the patch itself. The new function names are not an improvement.
>>
>> Probably best to just drop this, unless there is some sort of benefit that
>> I'm missing? >
> The main issue is that in vma_to_size() there are code like below
> 
>      if (new_len == old_len)
>          return vma;
> 
>      ...
>      locked += new_len - old_len;
>      ...
> 
> 
>      unsigned long charged = (new_len - old_len) >> PAGE_SHIFT;
>      ...
> 
> the test didn't cover new_len < old_len case, then just do 'new_len - old_len'. That looks like 
> hiding potential bug. So this need be fixed.

This chain of reasoning doesn't work for me. First of all, the callers of vma_to_resize()
already check that new_len >= old_len, right? So I don't think "this needs to be fixed".

Second, if there is a bug that I'm overlooking here, then I'd like to see a fix that
does not also gratuitously refactor this into an unnecessary subroutine. What is the
minimum clean change that you could make to fix the bug?

Here's a bit more detail, in order to guide your future work:

It is true that breaking something that is long and complex into one or more subroutines
can improve some situations. But in this case, vma_to_resize() is already fairly short and
not too complex, and your new subroutine has a somewhat misleading name. That, plus the act
of splitting it up, please the unreadable documentation, actually makes it much harder to
follow.

Also, spend some time trying to write up what you did and why, in the commit log. If the
log is quite difficult to write, then sometimes it means that it wasn't actually a good
move. :)

thanks,
-- 
John Hubbard
NVIDIA


      reply	other threads:[~2021-01-03  2:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30  7:56 Li Xinhai
2020-12-30 20:52 ` John Hubbard
2021-01-02 12:24   ` Li Xinhai
2021-01-03  2:59     ` John Hubbard [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=34739469-53ae-f786-509b-2ed9aace3572@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-mm@kvack.org \
    --cc=lixinhai.lxh@gmail.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