Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp134649ybv; Thu, 6 Feb 2020 19:39:27 -0800 (PST) X-Google-Smtp-Source: APXvYqxdrU40UrfGS1jb3o0ZC3IF+RHmf/SsnqRNXxHdFfvMNxBnIFA3ZQlW/4du+xjdKrurQEBx X-Received: by 2002:a9d:5786:: with SMTP id q6mr1089105oth.164.1581046767473; Thu, 06 Feb 2020 19:39:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581046767; cv=none; d=google.com; s=arc-20160816; b=ERmaG8CvYGpCryy5ftYCOIagrPPlY8JXmpR/UhsJzF27JV6Fc9q2f05GGZa+wN2g3e d8vYTf18n/rtTepytOKYoLzKdXkrCqS1HQI4Zf0aLAxxQuutgnED0R6S5kK8xEH/Y1pv 7jMfs6goxrCeciQlbYnBHzTwybKqT8bAgJldakySlR6lso/ibqK5dWCdRJuUTCyZac1R mFM0HSQrv3HnglA0doT7+KO7z67WT8Zz2uPZaM2P4hmlfagxZO9/UI4M7b1Kb/nHmJ7C EmxD4JLLcoYjQIPvHmlmmQbt1GyIFtvbbdELgd3CJCCBJ5eSJC9fIu0aKlbY6EPjyJQd GyQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=DhMMWR0L+su36XhWVkaUTT8AIpyvoaCJ7tCBpQiPc3M=; b=SnQXehGf/nFQDWarXEKXelsIIbsxYO++4hqSD5+3d296XYJZLk14t2nE70tcEk7vaK 0yb14r/i5ewtiuQSDLxyXrpeaQBk6TviTq+q0iSrvRMpnaxWg9eCHGQobby0wQvs3RcK GTBNBJjHPjt+lS5P+Eqqqycr5vCRY5+U2PkHgp+8ImIIZle8bY9FCE51xl5w5gVtVCri XrLruFIRA6RbWCW59wLG6Ud3NALt5OD7CGtw94pf82q/pECXtL0SB4s/hHowU+8AZ6gz NuzNL80lPyuIossGtwCVrFtwbaDF5iMJPamFgtbZMCr4Ysf0HW6jBZkdcMi8YQcal5qq 6jiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=qCL7wJvy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si3199832oie.17.2020.02.06.19.39.15; Thu, 06 Feb 2020 19:39:27 -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=@nvidia.com header.s=n1 header.b=qCL7wJvy; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727598AbgBGDhm (ORCPT + 99 others); Thu, 6 Feb 2020 22:37:42 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:13343 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727524AbgBGDhj (ORCPT ); Thu, 6 Feb 2020 22:37:39 -0500 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Thu, 06 Feb 2020 19:37:12 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 06 Feb 2020 19:37:37 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 06 Feb 2020 19:37:37 -0800 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 7 Feb 2020 03:37:36 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 7 Feb 2020 03:37:36 +0000 Received: from blueforge.nvidia.com (Not Verified[10.110.48.28]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Thu, 06 Feb 2020 19:37:36 -0800 From: John Hubbard To: Andrew Morton CC: Al Viro , Christoph Hellwig , Dan Williams , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jonathan Corbet , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , "Kirill A . Shutemov" , Michal Hocko , "Mike Kravetz" , Shuah Khan , "Vlastimil Babka" , Matthew Wilcox , , , , , , LKML , John Hubbard Subject: [PATCH v5 04/12] mm: introduce page_ref_sub_return() Date: Thu, 6 Feb 2020 19:37:27 -0800 Message-ID: <20200207033735.308000-5-jhubbard@nvidia.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200207033735.308000-1-jhubbard@nvidia.com> References: <20200207033735.308000-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1581046632; bh=DhMMWR0L+su36XhWVkaUTT8AIpyvoaCJ7tCBpQiPc3M=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Transfer-Encoding:Content-Type; b=qCL7wJvyuAIwVgPSCBkxszuO0dlj80eWg/EDbClYxweQTRNHL+GTW+zK5ITf9LNig uRb9r+NQmOvLYXjHpxOGosNBSj7qAFzD1Gp/gXOyn3l/7Eqt4KN7cqUq1efOgufStl 7Bea1KDIgNa9pQWBFdc/LdEPKGUGmPWbDZMoxCXH+5lY5tU5TD64FzekAlyXNuUnXd Myo9xS52/un25I1eAeSv6b3cg81SSkeMiPJec39TyWWzQLsEdozMVBZqphrxjT7MNM jkW3BmWsPJ7q587TT4lIOdnmBBkxgFCDUucq88TsdGmsVVI9cKN0B+bb69YA/DJtdV 8Nhet+MSTrAig== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reviewed-by: Jan Kara 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..d27701199a4d 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); } =20 +static inline int page_ref_sub_return(struct page *page, int nr) +{ + int ret =3D atomic_sub_return(nr, &page->_refcount); + + if (page_ref_tracepoint_active(__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); --=20 2.25.0