Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp76399ybv; Wed, 5 Feb 2020 01:27:08 -0800 (PST) X-Google-Smtp-Source: APXvYqy5UI+pUXoRvpZCVRkKR5i9dW6UKNxdArRSc6wZuOy1sQDTy3ZgKjJWQjR2qn+ejBLklKHe X-Received: by 2002:a05:6830:1d55:: with SMTP id p21mr25229535oth.145.1580894828767; Wed, 05 Feb 2020 01:27:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580894828; cv=none; d=google.com; s=arc-20160816; b=mJzlK1YguidtxPsK691J1tYcLEre+IBgx0o5RyLWBWDvpkK3CzA1029n7myFAH68x5 1vaCOaW04RVW1uyzYQcVG+sgszEl+0+RAhn4U27XcqTvNQaZVfoCAAoxMHilvkQX3EKQ 5rVUUgNU+RtLyWM2AgDIDA/m5o8Omt0kayydzU5wbdvombFd5DrzUpk7by50gpaUsXzu q02V7Z4vSPypzTvWQrrmcqcYgSt2c7xua2szu5Pzkskw5wY9JiKjUab98zQcnghyxvP1 r1jDEFN51etcmHH2m4KN7ijBuYFWnxSj04QueGyH4UVN7aTm1+xpUcv9u7SyfBhBz7vT Qkkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=1oAm3oSTWvtYn1FnZFed/7jqz8Z49yS8E22vZ0E1q64=; b=C4CufGJp+rqZ+u1MtkXmg8u/hMMIrfUWlEF4EFuzPSpROJxwCrP7V4vB0WUrCTbjGX iQua6BQgOEbEbojQp9FNwVPedN0bXhYvAQ2Vpq7agBvwApjcGopNFjOTSw1ojqtm7mSK eExyICENy4S00/tfnHGOv2J995ZcMtWabT8vfOe5Y03Fi3v2D9JjhWqEb4OuxVxXaKp6 qBe2WUq+faDigKww0ntFWVm7S1eh2uXpzLn4NRjyr3sh/mD5ZmRAVzD/l12w+6ePolTa MBfNm8dCIHawtmFvLanWlQ5dwD0kPfzonZ2D2LlzBuSTSN5OlnnRY418pdxhqyzM7TeI 9IMg== ARC-Authentication-Results: i=1; mx.google.com; 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 z199si8495818oia.192.2020.02.05.01.26.57; Wed, 05 Feb 2020 01:27:08 -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; 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 S1728212AbgBEJXX (ORCPT + 99 others); Wed, 5 Feb 2020 04:23:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:49146 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728083AbgBEJXX (ORCPT ); Wed, 5 Feb 2020 04:23:23 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3962EB242; Wed, 5 Feb 2020 09:23:20 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 61F351E0A51; Wed, 5 Feb 2020 10:23:13 +0100 (CET) Date: Wed, 5 Feb 2020 10:23:13 +0100 From: Jan Kara To: John Hubbard Cc: Andrew Morton , Al Viro , Christoph Hellwig , Dan Williams , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jonathan Corbet , =?iso-8859-1?B?Suly9G1l?= Glisse , "Kirill A . Shutemov" , 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: <20200205092313.GA28058@quack2.suse.cz> 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> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 04-02-20 15:41:09, 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 Looks good to me. You can add: Reviewed-by: Jan Kara Honza > --- > 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)) > + __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 > -- Jan Kara SUSE Labs, CR