Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp45563pxj; Fri, 7 May 2021 03:24:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk4AZZYRRzRs9G57uri4CdBI7ga5j9whdYEB9VqoiE7YWH/n0LJCj2zBY1XAsa/X5K5jJb X-Received: by 2002:a17:90b:1e4e:: with SMTP id pi14mr22827469pjb.120.1620383065103; Fri, 07 May 2021 03:24:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620383065; cv=none; d=google.com; s=arc-20160816; b=ywnUTDSQAk2S+/7WyHA5Y4NqOydr9tNM4xfDeVKNOYzRX9vsUIvRPI2nZia0HHEg7i IJKT0mu/xgbghDR6X8BbSEW5pATWUpczA7zX/4n6OtM3qzoghIuiZpbo/HbBCSwFj29E 3oRCCHhZTOjHhKnOzEZOsC9U2Z4vkmduStYvAMQvJ5p+XrCy7bvvCk7VP3ufvzyb31Gd lm7b6vfPEGQZMxQqFUz66PlCHNX36OZJSHcASm7sXN1F8ce8KIxeLOuE/bzuifAESU2i Wq/5eq5ABcNCS4mrlMs5FreARywn84z2apinb3VEPj9nxEyYleNmnjwfcgq34qYmENPb hjMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=smY86Lmu3R2wzXg9lSwn24IGK7EQT0GTkAK1YtXOofw=; b=BBrNUW51WcprVrENCVdCcua2Lf0VQm/0K3MhS6XAU77ioByFyrsItHbGrbgzc0Paiv cH52E49EmaBZxjrtsF8H0/zONPMydp5iSyDWWq6ieGybJGeAz1S2cpqGMTiTx5mDgLqL jhwRxFeajZySphGW7HytdteXhcmhjRM3vIuLEuQ53fI7wUGPGDUBRGXGRbJoh8HLHBjt 65+1lPPcE7DTyV4jAc+t0RAzruqnt4Iw1bHpxOkk12gqQgLduI54X8UXBIqRdT6RPj4r G+6Vs8n9S1q1om8evQCwmcqaVJW0quVHvr6FgP9mTCkipDTrEw1iIf93tR7NLrSCgTJs vVMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HdZaIFSz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si8592506pjo.145.2021.05.07.03.24.12; Fri, 07 May 2021 03:24:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HdZaIFSz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235513AbhEGHky (ORCPT + 99 others); Fri, 7 May 2021 03:40:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231179AbhEGHkx (ORCPT ); Fri, 7 May 2021 03:40:53 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D42C061574 for ; Fri, 7 May 2021 00:39:54 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id z13so11509906lft.1 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=hCAbpqLsaRhV62iswuHicbnFxj7G0NSUMVfCQJ6jPubM3i71fEgOykDR9iKaQawHsh zoGQnXgh3mHohQ9hR6SIKEIv/A+mF+xPybdbUe2dy5zA3B0trNHiLPFXubJ4okVgz/MT ce6JgD6Rrtpv+0hTTtfgaUS6iTgirftv+QOqjMtf+7+nyNnZItQIXbnutYhio8wmTuYP ksWHztDKpdPIG8oZHrx+t2DwnMDl/U8RJKuTIrwpV0VFgANsh+DVEs2K4qCKuvI/qC8k 9qudpCzwE2IKlIBvw6PBsMpd0wRUkqU2yyE+FIwxCg8NJ83pp0HQ0zMz9tgRZ+i1W5ew JM9w== X-Gm-Message-State: AOAM532Qgb2+HF/2c00nNDM28yTP16bSQMHZE3QYr7pkXd6KGJ++NsYv YKYBVnMBUMs0IAZuXYE0FwiQHK9BqrVjPaSoNgo= X-Received: by 2002:ac2:5471:: with SMTP id e17mr5428587lfn.630.1620373192589; Fri, 07 May 2021 00:39:52 -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 h7sm1296912lfu.199.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 u25so10361469ljg.7 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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