From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 276C3C433B4 for ; Fri, 7 May 2021 07:39:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 735E261457 for ; Fri, 7 May 2021 07:39:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 735E261457 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E7A318D0005; Fri, 7 May 2021 03:39:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E18EC8D0002; Fri, 7 May 2021 03:39:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7C848D0005; Fri, 7 May 2021 03:39:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id A93138D0002 for ; Fri, 7 May 2021 03:39:55 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 553D98249980 for ; Fri, 7 May 2021 07:39:55 +0000 (UTC) X-FDA: 78113635950.08.708AF26 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by imf14.hostedemail.com (Postfix) with ESMTP id 5D9ACC0007C6 for ; Fri, 7 May 2021 07:39:33 +0000 (UTC) Received: by mail-lf1-f47.google.com with SMTP id x2so11447599lff.10 for ; Fri, 07 May 2021 00:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=smY86Lmu3R2wzXg9lSwn24IGK7EQT0GTkAK1YtXOofw=; b=HdZaIFSzvUfviaklz1QMJMOLRkfx+w7WAl6Cr+YdO+UzFif+9z6/XVqc8zSbOkDmv4 9anyW7cvVMEZU6TIwdAtuUAlsQQYyZMiTZMuEZna5wDCJUHFeMriZdccreUB0dlU0Czx 1SXMnhllfilxm0UtC29YOkpHy9FeRdjn1z9wY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=smY86Lmu3R2wzXg9lSwn24IGK7EQT0GTkAK1YtXOofw=; b=e/KdjVRl3WUAHPZdf/P25A01FCFVwsxz+MLk5k9n9Qsw2Tm5KykmxOeXZ0OHMwuWzN dTW/K8tjjQc4tLsb3vZFcTwUz6rRoofp7DK96U2Ucnok4IZ6NkmI++W+cxZ1a2LLR48H tl/z4M8Gu/baxa2k2QqLaRVc09hQzbgXUJ4R7MFdTSs6FaTYdNXttc0Zk31hf9p3sx8M kgChZzH33MopfWckw18jJYp1ZDNxsHcOb4C5p6v61DDQpad4wIWDNYEPtY8D30mNzLlN y/2j7F5xwFvkphEbxrJzY+9cUFzp+jDnBR2uU616gvtjawmd1pCfHyYxsIpRfFDmfmIX KgMA== X-Gm-Message-State: AOAM533crAiDNjMiY6wmqHX8HcS14oiVmaTE719t9No+HJEfa6TFERUT 11+eJkGyFvP4Zf8B9v0p1YSYgmYOJs5/zwfZwZo= X-Google-Smtp-Source: ABdhPJzT2zMfxA6/KOcGEsSsGZsduhGzKpSRikkvodSRXxYrCUA/8L3ZYcOnyU/FIXATRgB9vi295w== X-Received: by 2002:ac2:533b:: with SMTP id f27mr5566997lfh.640.1620373193128; Fri, 07 May 2021 00:39:53 -0700 (PDT) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id k11sm1259263lfg.288.2021.05.07.00.39.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 May 2021 00:39:51 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id s25so10403834lji.0 for ; Fri, 07 May 2021 00:39:51 -0700 (PDT) X-Received: by 2002:a05:651c:1311:: with SMTP id u17mr6448216lja.48.1620373191134; Fri, 07 May 2021 00:39:51 -0700 (PDT) MIME-Version: 1.0 References: <20210506232537.165788-1-peterx@redhat.com> <20210506232537.165788-4-peterx@redhat.com> <69055843-185d-20ea-213b-10494a2f7246@nvidia.com> In-Reply-To: <69055843-185d-20ea-213b-10494a2f7246@nvidia.com> From: Linus Torvalds Date: Fri, 7 May 2021 00:39:35 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/3] mm: gup: pack has_pinned in MMF_HAS_PINNED To: John Hubbard Cc: Peter Xu , Linux-MM , Linux Kernel Mailing List , Hugh Dickins , Jan Kara , Kirill Shutemov , Jason Gunthorpe , Andrew Morton , Kirill Tkhai , Michal Hocko , Oleg Nesterov , Jann Horn , Matthew Wilcox , Andrea Arcangeli Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=HdZaIFSz; spf=pass (imf14.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.167.47 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5D9ACC0007C6 X-Stat-Signature: e4hfd4emhtmkoa5cj7quis3s665689g9 Received-SPF: none (linuxfoundation.org>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=mail-lf1-f47.google.com; client-ip=209.85.167.47 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620373173-672315 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, May 6, 2021 at 11:43 PM John Hubbard 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