[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wiDXxQyzcJ6Xy1t8-4R0uqcanfSYetLoMNeKUTPdCNL0w@mail.gmail.com>
Date: Fri, 7 May 2021 00:39:35 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: John Hubbard <jhubbard@...dia.com>
Cc: Peter Xu <peterx@...hat.com>, Linux-MM <linux-mm@...ck.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Hugh Dickins <hughd@...gle.com>, Jan Kara <jack@...e.cz>,
Kirill Shutemov <kirill@...temov.name>,
Jason Gunthorpe <jgg@...dia.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Kirill Tkhai <ktkhai@...tuozzo.com>,
Michal Hocko <mhocko@...e.com>,
Oleg Nesterov <oleg@...hat.com>, Jann Horn <jannh@...gle.com>,
Matthew Wilcox <willy@...radead.org>,
Andrea Arcangeli <aarcange@...hat.com>
Subject: Re: [PATCH 3/3] mm: gup: pack has_pinned in MMF_HAS_PINNED
On Thu, May 6, 2021 at 11:43 PM John Hubbard <jhubbard@...dia.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
Powered by blists - more mailing lists