From patchwork Sun Jan 16 12:18:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 12714554 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 B72B9C433EF for ; Sun, 16 Jan 2022 12:38:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AED196B0078; Sun, 16 Jan 2022 07:38:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A722C6B007B; Sun, 16 Jan 2022 07:38:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93B506B007D; Sun, 16 Jan 2022 07:38:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id 826536B0078 for ; Sun, 16 Jan 2022 07:38:09 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3E0E8824C429 for ; Sun, 16 Jan 2022 12:38:09 +0000 (UTC) X-FDA: 79036102698.06.365125E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id D419E80004 for ; Sun, 16 Jan 2022 12:38:08 +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=vTljgvHhqZG3cT2RqoyXMcY1zZutR0LRzeE9Ah9ayuk=; b=qpCpEjsgcgij2zVHnH1WhH1Opg 5COj5QM3fLjZ62EFFu7Fz/3O7RcjVnqvhubuAolQcCVWIDlTTZM607nQaE76CajV2ILjyMdhUuFbF B07DdDlNrjU2AsmoMiUmk9oyM/iGyjXS6Xnc/K4fZkNydVYJzhEzZQB0oJJSVO5jIQjM1dpQPDhwo YlucFFuseK5sDqCqkpvZwpx3iCoMB3d57MvCEnX/2Q8WAg44whIg/wjHW3RWZ4oucF9LXwInqgpnv tyJ2fCzGXjiwFbEP3NbQo9A7FOS8eZNS1TlfQXX/bDWUJkIU5rfOJDjlxylWXtUfDeSjtb5OI3GE/ wrK5XMnw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n94UM-007FUB-6X; Sun, 16 Jan 2022 12:18:26 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , Christoph Hellwig , John Hubbard , Jason Gunthorpe , William Kucharski Subject: [PATCH 01/12] mm: Add folio_put_refs() Date: Sun, 16 Jan 2022 12:18:11 +0000 Message-Id: <20220116121822.1727633-2-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220116121822.1727633-1-willy@infradead.org> References: <20220116121822.1727633-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: D419E80004 X-Stat-Signature: kh9pwpyriitambsaecy51xut6p1jfw8i Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qpCpEjsg; dmarc=none; 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 X-Rspamd-Server: rspam08 X-HE-Tag: 1642336688-611430 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 Reviewed-by: Jason Gunthorpe Reviewed-by: William Kucharski --- include/linux/mm.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index c768a7c81b0b..cb98f75b245e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1244,6 +1244,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 amount to subtract from the folio's reference count. + * + * 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);