From patchwork Sun Jan 2 21:57:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12702373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF179C433EF for ; Sun, 2 Jan 2022 21:57:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55C136B0083; Sun, 2 Jan 2022 16:57:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E7396B0085; Sun, 2 Jan 2022 16:57:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 274516B0087; Sun, 2 Jan 2022 16:57:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id F30E56B0083 for ; Sun, 2 Jan 2022 16:57:52 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 97A45180BA546 for ; Sun, 2 Jan 2022 21:57:52 +0000 (UTC) X-FDA: 78986709984.12.77B4775 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id 45AFF80004 for ; Sun, 2 Jan 2022 21:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=eAJUq7P6VyOf1/FXgOre2SEFMK8BDDSP7tINfd7cEAI=; b=pQkrEv3bFOsLxh188Jk1wUuf5b 9zoY20KNFE+fIt5RuXsj3w6HjJTkc63RJj/D7pax03BAcjyvrxSzc4+1d3Rjsu92DVle9/iQxihfP 4MEyVPd+64Ljo2WNJugA+AzN0LuLvA6lt2s/vuiSAxj9zGoDZxSQ2VY+rQsh+Y5ycJYJYrB6q3kFm EuWvmvitRxb4IIaWxh0v0FjZwE032GbArQUgj8kHxIT45BCEk+Hc97wNvSEixYognMUm1725oby/W m4oR8N3gg0bOBABU98yVkPaOgw8QYDWaSbGgt/d7vlSKY+uy1wwvEyukUUy0ALV8ECUhaBt8OPG6W yMbgAW8g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n48r5-00CLnv-TA; Sun, 02 Jan 2022 21:57:31 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , John Hubbard , Andrew Morton Subject: [PATCH 01/17] mm: Add folio_put_refs() Date: Sun, 2 Jan 2022 21:57:13 +0000 Message-Id: <20220102215729.2943705-2-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220102215729.2943705-1-willy@infradead.org> References: <20220102215729.2943705-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: arg1gm9kfoegeq4jucz4wjf4zzrapsg7 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 45AFF80004 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pQkrEv3b; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1641160672-292256 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is like folio_put(), but puts N references at once instead of just one. It's like put_page_refs(), but does one atomic operation instead of two, and is available to more than just gup.c. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- include/linux/mm.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index d8b7d7ed14dd..98a10412d581 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1237,6 +1237,26 @@ static inline void folio_put(struct folio *folio) __put_page(&folio->page); } +/** + * folio_put_refs - Reduce the reference count on a folio. + * @folio: The folio. + * @refs: The number of references to reduce. + * + * If the folio's reference count reaches zero, the memory will be + * released back to the page allocator and may be used by another + * allocation immediately. Do not access the memory or the struct folio + * after calling folio_put_refs() unless you can be sure that these weren't + * the last references. + * + * Context: May be called in process or interrupt context, but not in NMI + * context. May be called while holding a spinlock. + */ +static inline void folio_put_refs(struct folio *folio, int refs) +{ + if (folio_ref_sub_and_test(folio, refs)) + __put_page(&folio->page); +} + static inline void put_page(struct page *page) { struct folio *folio = page_folio(page);