linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: John Hubbard <jhubbard@nvidia.com>
Cc: Peter Xu <peterx@redhat.com>, Linux-MM <linux-mm@kvack.org>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Hugh Dickins <hughd@google.com>, Jan Kara <jack@suse.cz>,
	 Kirill Shutemov <kirill@shutemov.name>,
	Jason Gunthorpe <jgg@nvidia.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Kirill Tkhai <ktkhai@virtuozzo.com>,
	 Michal Hocko <mhocko@suse.com>, Oleg Nesterov <oleg@redhat.com>,
	Jann Horn <jannh@google.com>,
	 Matthew Wilcox <willy@infradead.org>,
	Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH 3/3] mm: gup: pack has_pinned in MMF_HAS_PINNED
Date: Fri, 7 May 2021 00:39:35 -0700	[thread overview]
Message-ID: <CAHk-=wiDXxQyzcJ6Xy1t8-4R0uqcanfSYetLoMNeKUTPdCNL0w@mail.gmail.com> (raw)
In-Reply-To: <69055843-185d-20ea-213b-10494a2f7246@nvidia.com>

On Thu, May 6, 2021 at 11:43 PM John Hubbard <jhubbard@nvidia.com> wrote:
>
> +static void set_mm_has_pinned_flag(unsigned long *mm_flags)
> +{
> +       /*
> +        * Avoid setting the bit unless necessary. This matters a lot with
> +        * large SMP machines.
> +        */
> +       if (!test_bit(MMF_HAS_PINNED, mm_flags))
> +               set_bit(MMF_HAS_PINNED, mm_flags);
> +}

Yes, please do split it up like this.

But please make it explicitly inline, and move the comment to above
the function.

And add the important key part to it: that the bit is never cleared.

That idempotent behavior of the "set_bit()" is what makes it safe to
do this non-atomic test-and-set (yes, the "set_bit()" itself is
atomic, but the sequence above is not).

Side note: we do have a few other places where this kind of thing
happens, so it *might* make sense to even make this a generic pattern
in case somebody can come up with a good descriptive name for that
("set_bit_if_not_set()" sounds descriptive, but the subtle
non-atomicity should probably be part of it).

> +       if (flags & FOLL_PIN)
> +               set_mm_has_pinned_flag(&mm->flags);
>
> ...which is now very readable, once again.

Yes, that does look much better.

Thanks,

              Linus


  reply	other threads:[~2021-05-07  7:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 23:25 [PATCH 0/3] mm/gup: Fix pin page write cache bouncing on has_pinned Peter Xu
2021-05-06 23:25 ` [PATCH 1/3] mm/gup_benchmark: Support threading Peter Xu
2021-05-07  4:37   ` John Hubbard
2021-05-07 14:04     ` Peter Xu
2021-05-06 23:25 ` [PATCH 2/3] mm: gup: allow FOLL_PIN to scale in SMP Peter Xu
2021-05-07  2:34   ` Linus Torvalds
2021-05-07  6:07   ` John Hubbard
2021-05-07 14:13     ` Peter Xu
2021-05-06 23:25 ` [PATCH 3/3] mm: gup: pack has_pinned in MMF_HAS_PINNED Peter Xu
2021-05-07  6:42   ` John Hubbard
2021-05-07  7:39     ` Linus Torvalds [this message]
2021-05-07 11:14     ` Matthew Wilcox
2021-05-07 14:34     ` 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='CAHk-=wiDXxQyzcJ6Xy1t8-4R0uqcanfSYetLoMNeKUTPdCNL0w@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=jannh@google.com \
    --cc=jgg@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=kirill@shutemov.name \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=oleg@redhat.com \
    --cc=peterx@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox