Skip to content

Commit 3fe7fa5

Browse files
author
Matthew Wilcox (Oracle)
committed
mm: Add folio_put_refs()
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) <willy@infradead.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: William Kucharski <william.kucharski@oracle.com>
1 parent 6840f90 commit 3fe7fa5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/linux/mm.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,26 @@ static inline void folio_put(struct folio *folio)
12441244
__put_page(&folio->page);
12451245
}
12461246

1247+
/**
1248+
* folio_put_refs - Reduce the reference count on a folio.
1249+
* @folio: The folio.
1250+
* @refs: The amount to subtract from the folio's reference count.
1251+
*
1252+
* If the folio's reference count reaches zero, the memory will be
1253+
* released back to the page allocator and may be used by another
1254+
* allocation immediately. Do not access the memory or the struct folio
1255+
* after calling folio_put_refs() unless you can be sure that these weren't
1256+
* the last references.
1257+
*
1258+
* Context: May be called in process or interrupt context, but not in NMI
1259+
* context. May be called while holding a spinlock.
1260+
*/
1261+
static inline void folio_put_refs(struct folio *folio, int refs)
1262+
{
1263+
if (folio_ref_sub_and_test(folio, refs))
1264+
__put_page(&folio->page);
1265+
}
1266+
12471267
static inline void put_page(struct page *page)
12481268
{
12491269
struct folio *folio = page_folio(page);

0 commit comments

Comments
 (0)