All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <namit@vmware.com>
To: Peter Xu <peterx@redhat.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Hugh Dickins <hughd@google.com>, Jan Kara <jack@suse.cz>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Matthew Wilcox <willy@infradead.org>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Mike Rapoport <rppt@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Shuah Khan <shuah@kernel.org>,
	James Houghton <jthoughton@google.com>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH v3 2/5] mm: userfaultfd: don't pass around both mm and vma
Date: Tue, 7 Mar 2023 01:44:05 +0000	[thread overview]
Message-ID: <54D49E2C-F2EF-4C1E-AFE9-FD742CEA33EB@vmware.com> (raw)
In-Reply-To: <ZAaNXTXs5ey4QYTl@x1n>



> On Mar 6, 2023, at 5:03 PM, Peter Xu <peterx@redhat.com> wrote:
> 
> !! External Email
> 
> On Mon, Mar 06, 2023 at 02:50:21PM -0800, Axel Rasmussen wrote:
>> Quite a few userfaultfd functions took both mm and vma pointers as
>> arguments. Since the mm is trivially accessible via vma->vm_mm, there's
>> no reason to pass both; it just needlessly extends the already long
>> argument list.
>> 
>> Get rid of the mm pointer, where possible, to shorten the argument list.
>> 
>> Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
> 
> Acked-by: Peter Xu <peterx@redhat.com>
> 
> One nit below:
> 
>> @@ -6277,7 +6276,7 @@ int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm,
>>              folio_in_pagecache = true;
>>      }
>> 
>> -     ptl = huge_pte_lock(h, dst_mm, dst_pte);
>> +     ptl = huge_pte_lock(h, dst_vma->vm_mm, dst_pte);
>> 
>>      ret = -EIO;
>>      if (folio_test_hwpoison(folio))
>> @@ -6319,9 +6318,9 @@ int hugetlb_mfill_atomic_pte(struct mm_struct *dst_mm,
>>      if (wp_copy)
>>              _dst_pte = huge_pte_mkuffd_wp(_dst_pte);
>> 
>> -     set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte);
>> +     set_huge_pte_at(dst_vma->vm_mm, dst_addr, dst_pte, _dst_pte);
>> 
>> -     hugetlb_count_add(pages_per_huge_page(h), dst_mm);
>> +     hugetlb_count_add(pages_per_huge_page(h), dst_vma->vm_mm);
> 
> When vm_mm referenced multiple times (say, >=3?), let's still cache it in a
> temp var?
> 
> I'm not sure whether compiler is smart enough to already do that with a
> reg, even if so it may slightly improve readability too, imho, by avoiding
> the multiple but same indirection for the reader.

I am not sure if you referred to this code specifically or in general. I once
looked into it, and the compiler is really stupid in this regard and super
conservative when it comes to aliasing. Even if you use “restrict” keyword or
“__pure” or “__const” function attributes, in certain cases (function calls
to other compilation units, or inline assembly - I don’t remember) the
compiler might ignore them. Worse, llvm and gcc are inconsistent.

From code-generated perspective, I did not see a clear cut that benefits
caching over not. From performance perspective the impact is negligible. I
mention all of that because I thought it matters too, but it mostly does
not.

That’s all to say that in most cases, I think that whatever makes the code
more readable should be preferred. I think that you are correct in saying
that “caching” it will make the code more readable, but performance-wise
it is probably meaningless.


  reply	other threads:[~2023-03-07  1:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-06 22:50 [PATCH v3 0/5] mm: userfaultfd: refactor and add UFFDIO_CONTINUE_MODE_WP Axel Rasmussen
2023-03-06 22:50 ` [PATCH v3 1/5] mm: userfaultfd: rename functions for clarity + consistency Axel Rasmussen
2023-03-07  1:03   ` Peter Xu
2023-03-06 22:50 ` [PATCH v3 2/5] mm: userfaultfd: don't pass around both mm and vma Axel Rasmussen
2023-03-07  1:03   ` Peter Xu
2023-03-07  1:44     ` Nadav Amit [this message]
2023-03-08 15:08       ` Peter Xu
2023-03-06 22:50 ` [PATCH v3 3/5] mm: userfaultfd: combine 'mode' and 'wp_copy' arguments Axel Rasmussen
2023-03-07  1:00   ` Peter Xu
2023-03-07 23:27     ` Axel Rasmussen
2023-03-08 15:17       ` Peter Xu
2023-03-07  1:54   ` Nadav Amit
2023-03-06 22:50 ` [PATCH v3 4/5] mm: userfaultfd: don't separate addr + len arguments Axel Rasmussen
2023-03-07  1:19   ` Peter Xu
2023-03-07  1:29     ` Nadav Amit
2023-03-07 18:52       ` Axel Rasmussen
2023-03-08  9:51   ` kernel test robot
2023-03-08 18:48     ` Axel Rasmussen
2023-03-06 22:50 ` [PATCH v3 5/5] mm: userfaultfd: add UFFDIO_CONTINUE_MODE_WP to install WP PTEs Axel Rasmussen
2023-03-07  1:23   ` Peter Xu

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=54D49E2C-F2EF-4C1E-AFE9-FD742CEA33EB@vmware.com \
    --to=namit@vmware.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=jthoughton@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=muchun.song@linux.dev \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /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.