Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp167213ybv; Wed, 5 Feb 2020 03:26:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxuzHWZ5ZjAsLb1oA8/Zn9JipvMOpczSM2hP/7MGGGSb/7upLOhPgHmEXpsLYn7okIqWa+q X-Received: by 2002:aca:ebcb:: with SMTP id j194mr2496841oih.154.1580901986821; Wed, 05 Feb 2020 03:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580901986; cv=none; d=google.com; s=arc-20160816; b=iAamzC44gY4CyKW+NfheqZBBJSYH5s2DVjZsvZGRvVWd8gdbQtg+rkheRST38WrdIv lLYLB4+0eDSBzvtD6cc/8UuzhGK9+JHOhe2c/3ezqJSUezycDdAlQN8lpPAKSb4HlQtn 4S8BAsEKubJNuu/0j2+IQHVkaPp8F8O8H5RjZPtn68KrdYjOxjmB61koA1s2c3UAfApJ jFtGLPkTcClyRb6KwiC4KjnCyZcgRL0upvGVDPnjGWWEHVN36UtnCAvFFWnLOoxE9oDQ kF0cSUvy1r7jW6DGsecQ/PF5dmeeDjs+X1tWSPNYdBFGqzaCvekgd5or7fmCAUq0Dm2F ArAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=dh5KVm5NVZR7B6kV3CkfPxftpb+A9muCzSxY5f+by0k=; b=p+HBo5Kvd0TTseXL9p8BFWaZIcD4XINcE7KghHgnTGQqf6gHFb+BDpK/RezqqbMKKn Nx9HQKfVfuGDeed8rq68r+jAV+z4deBUTm7YXGsM74ciLus5JnsV75RjsZFEwDEaySUZ +/TnYe7FewOetWtk2Zze+TVw0k6KEGh1qPTvZjx2oXF58K2mh0vI6t4O5173ov7Mh1iA 7B7342p5UvAzCxvdLjK61eYn5V9SbqtTkm9AUkgJo2d4YfiX77qgInbbw2zQl6H+nHJd QCLHxTAD/55VlTIBeXUsv8hvasA/tiBcNC/Gqhzru9Pgr3KI7CfO3SDZl/RzaJTHfkql vKcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=tFQv4blG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si13456727otq.238.2020.02.05.03.26.14; Wed, 05 Feb 2020 03:26:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=tFQv4blG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728393AbgBELXd (ORCPT + 99 others); Wed, 5 Feb 2020 06:23:33 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43892 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727522AbgBELXc (ORCPT ); Wed, 5 Feb 2020 06:23:32 -0500 Received: by mail-lj1-f194.google.com with SMTP id a13so1885998ljm.10 for ; Wed, 05 Feb 2020 03:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dh5KVm5NVZR7B6kV3CkfPxftpb+A9muCzSxY5f+by0k=; b=tFQv4blGi1NukrKVKLKM9a5yWogak2ERntocChs0vWrya9lUNK3FSyatnKS1MLPDrt p+3KZiUybS59AUws2x8n3rybFtHSU3qsaP38wMgFaDNTG/usGncV2+gIcDPWZaTihn2x IT0s2ZIQkgy6nZw6cmza+jvP3jviAy+EvvnJ4AOSPcmWvi3H07xyPGK9XfmmYHOdOfBr i64GsDmqMsxzDMDTMf2POxCYF3RjYkxUsa1AEq/CUhlFdErzLlXMxmx6vvsrYmjq/W1E 0uNIM8buRrHTOj7xD45gFWXrseGaMzB/dqpGKw77ntg+wPel+osm/zIX+A2PVoNrN2AX dPxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dh5KVm5NVZR7B6kV3CkfPxftpb+A9muCzSxY5f+by0k=; b=STNrH+2pRIXPfRRGaNuRJ+6eRRGTFefUxO6IMJ3dUSB+Nxse/wckrnKYTpBKmqPifx CagUWBLstdon7VfLshf18WTvuHf1aazz8QJnYs/P1IpywCFu2XVmzdmkhJwWy1wEar7t Plk0lxO4uxaY9CNq68WV9lWlK8KRpPLaH0hk/omsTvnWU5KmY3iVJjJJTR2mdaTvOr1L AlGYUIaUAEBbVlZV66nT2S1qmsOe4g2vQSi459TNE/uqphqeSObiawZTgIsuxVj1n+nB CXvGK3bkG0Y5icQDLrBOeGmY7/zLdlz34CJAOyhyzru/gR0gM5HCQDHJGkAUlwcxvVXC ztEA== X-Gm-Message-State: APjAAAVNmbr1SRLUtZ0ITHgIHkT0P6Ob8DMjcrMLk169wOpFueeInjLD ybLXqIJb0SpZS4IhB26RLe0PQQ== X-Received: by 2002:a2e:918c:: with SMTP id f12mr18604844ljg.66.1580901810333; Wed, 05 Feb 2020 03:23:30 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id y18sm12786085ljm.93.2020.02.05.03.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 03:23:29 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id AE293100AF6; Wed, 5 Feb 2020 14:23:43 +0300 (+03) Date: Wed, 5 Feb 2020 14:23:43 +0300 From: "Kirill A. Shutemov" To: John Hubbard Cc: Andrew Morton , Al Viro , Christoph Hellwig , Dan Williams , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jonathan Corbet , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Michal Hocko , Mike Kravetz , Shuah Khan , Vlastimil Babka , Matthew Wilcox , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rdma@vger.kernel.org, linux-mm@kvack.org, LKML Subject: Re: [PATCH v4 04/12] mm: introduce page_ref_sub_return() Message-ID: <20200205112343.e2vpcylgrobfcxlo@box> References: <20200204234117.2974687-1-jhubbard@nvidia.com> <20200204234117.2974687-5-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200204234117.2974687-5-jhubbard@nvidia.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 04, 2020 at 03:41:09PM -0800, John Hubbard wrote: > An upcoming patch requires subtracting a large chunk of refcounts from > a page, and checking what the resulting refcount is. This is a little > different than the usual "check for zero refcount" that many of the > page ref functions already do. However, it is similar to a few other > routines that (like this one) are generally useful for things such as > 1-based refcounting. > > Add page_ref_sub_return(), that subtracts a chunk of refcounts > atomically, and returns an atomic snapshot of the result. > > Signed-off-by: John Hubbard > --- > include/linux/page_ref.h | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h > index 14d14beb1f7f..a0e171265b79 100644 > --- a/include/linux/page_ref.h > +++ b/include/linux/page_ref.h > @@ -102,6 +102,15 @@ static inline void page_ref_sub(struct page *page, int nr) > __page_ref_mod(page, -nr); > } > > +static inline int page_ref_sub_return(struct page *page, int nr) > +{ > + int ret = atomic_sub_return(nr, &page->_refcount); > + > + if (page_ref_tracepoint_active(__tracepoint_page_ref_mod)) s/__tracepoint_page_ref_mod/__tracepoint_page_ref_mod_and_return/ > + __page_ref_mod_and_return(page, -nr, ret); > + return ret; > +} > + > static inline void page_ref_inc(struct page *page) > { > atomic_inc(&page->_refcount); > -- > 2.25.0 > -- Kirill A. Shutemov