Commit 566d774a authored by John Hubbard's avatar John Hubbard Committed by Linus Torvalds

mm: introduce page_ref_sub_return()

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

Add page_ref_sub_return(), that subtracts a chunk of refcounts atomically,
and returns an atomic snapshot of the result.
Signed-off-by: default avatarJohn Hubbard <>
Signed-off-by: default avatarAndrew Morton <>
Reviewed-by: default avatarJan Kara <>
Acked-by: default avatarKirill A. Shutemov <>
Cc: Ira Weiny <>
Cc: Jérôme Glisse <>
Cc: "Matthew Wilcox (Oracle)" <>
Cc: Al Viro <>
Cc: Christoph Hellwig <>
Cc: Dan Williams <>
Cc: Dave Chinner <>
Cc: Jason Gunthorpe <>
Cc: Jonathan Corbet <>
Cc: Michal Hocko <>
Cc: Mike Kravetz <>
Cc: Shuah Khan <>
Cc: Vlastimil Babka <>
Link: default avatarLinus Torvalds <>
parent 86dfbed4
......@@ -102,6 +102,15 @@ static inline void page_ref_sub(struct page *page, int nr)
__page_ref_mod(page, -nr);
static inline int page_ref_sub_return(struct page *page, int nr)
int ret = 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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment