Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp27331ybv; Tue, 4 Feb 2020 15:44:45 -0800 (PST) X-Google-Smtp-Source: APXvYqy/onaptFwfNiwn2PeHeti6nx+1iqMHVfXVa03+HEvcQg3yFqLNRYFjEgL7u1MCvpRf5xHy X-Received: by 2002:aca:4b0f:: with SMTP id y15mr979778oia.153.1580859885103; Tue, 04 Feb 2020 15:44:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580859885; cv=none; d=google.com; s=arc-20160816; b=AZxJMcKoIaVjfmzD2Z+iaBtQZLzZZEFme3V7XQMH57oL4U2lYxl1Mb5E3SoUbaKYt+ +3D0MikGS5ZKTn/ItVhz0H9qIVi8Omo6Efg6PAyu5Y+o867cOuLNal5E2EXFhix6dDng FUmNlexmlFTZrs/SFmwHpS0h8kK6CC1EIJQExppCjxJfsKiSYcBjPzZAhqG3ivRZPrui ROzp8HKjUayqI2XqW5zW/WHF2Mqx/ejFe7qmcPN3lEvQKJSpeRpFjTznTM7CN4is1ejs EjaEPG4neDcvl7TwOfM9oAcW7PeUOfLcrizjQc7Nkh1q2BmhWiZqbfA2GD+vZnwDI+kv rX2A== 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=eGaNN16zOGlpqgBYnD+qS5CoX6lMktFz46tjMpWu0K4=; b=EPdBF4hbQeybuAqzJc0S1F39ija96cVIFUXUVp/YkaZ9tLJxqr8GLBe3hhPbWS2j9v 6ENPSkw0PF3yY5fql+1UzBa9mtDIIUvVYiEyOCrZ4xbkOMuUsHSC7HHA2qG6EwGNAO1u eBKXPnH8XLjEqtQ3jWJIN+3kMI+5jBTP4p5pZhnWT+++79mBWEtYtXpi3lIWuQmwkeQJ d3OYefAxJb5gt+IhOaWRBN5PMVf8ZE/T5Qw6TYjKgsy8Br/Y24spzYsoI4qFxdCPkLkq /YuSBlndcNhUAA/JK+etVx8hLrB5B9O26CqLbpMkPUZ158n9P88hbVaXfwKGHYjpQ4hM gKHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=m3DL424c; 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 c64si11417248oig.178.2020.02.04.15.44.32; Tue, 04 Feb 2020 15:44:45 -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=m3DL424c; 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 S1727945AbgBDXmR (ORCPT + 99 others); Tue, 4 Feb 2020 18:42:17 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4040 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727664AbgBDXlV (ORCPT ); Tue, 4 Feb 2020 18:41:21 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 04 Feb 2020 15:41:06 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 04 Feb 2020 15:41:20 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 04 Feb 2020 15:41:20 -0800 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 4 Feb 2020 23:41:20 +0000 Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 4 Feb 2020 23:41:19 +0000 Received: from blueforge.nvidia.com (Not Verified[10.110.48.28]) by rnnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Tue, 04 Feb 2020 15:41:19 -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 v4 04/12] mm: introduce page_ref_sub_return() Date: Tue, 4 Feb 2020 15:41:09 -0800 Message-ID: <20200204234117.2974687-5-jhubbard@nvidia.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200204234117.2974687-1-jhubbard@nvidia.com> References: <20200204234117.2974687-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=1580859666; bh=eGaNN16zOGlpqgBYnD+qS5CoX6lMktFz46tjMpWu0K4=; 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=m3DL424ceOUdqPIcEv4fvFteh7CP3YVJXATD1jE4kBe/uqOBlVoeMZJnpG54qLPqi LS4h54t2eUR+P11uvSih3VuwVd8jf/B3Q+TI7dbaEIcsJIx5Kxlxek9hX7M58hkiiw N43uwtFs4tgl/n63rhFntpjRP3ZeMlMhhV67NNMOMpB0SEUf3HKSWTHQWFhdWEXB6+ HQ/jrVmgnB0jGlJ9rU0cDt3U1cux8KoQIFdR0rUDFYkYVppvb1SfSPFVV/eUdzK4TX Zs7wDNjspwR6vj9vWmJaedKN3dBZdkBEI/G/hcY6nprBOuCdgCq7vrZqv1IxOMEb+S mLC9EgDmYvetw== 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. 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); } =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)) + __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