aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mm.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/mm.h')
-rw-r--r--include/linux/mm.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 76769749b5a5..6b10c21630f5 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -966,6 +966,10 @@ static inline bool is_pci_p2pdma_page(const struct page *page)
966} 966}
967#endif /* CONFIG_DEV_PAGEMAP_OPS */ 967#endif /* CONFIG_DEV_PAGEMAP_OPS */
968 968
969/* 127: arbitrary random number, small enough to assemble well */
970#define page_ref_zero_or_close_to_overflow(page) \
971 ((unsigned int) page_ref_count(page) + 127u <= 127u)
972
969static inline void get_page(struct page *page) 973static inline void get_page(struct page *page)
970{ 974{
971 page = compound_head(page); 975 page = compound_head(page);
@@ -973,8 +977,17 @@ static inline void get_page(struct page *page)
973 * Getting a normal page or the head of a compound page 977 * Getting a normal page or the head of a compound page
974 * requires to already have an elevated page->_refcount. 978 * requires to already have an elevated page->_refcount.
975 */ 979 */
976 VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page); 980 VM_BUG_ON_PAGE(page_ref_zero_or_close_to_overflow(page), page);
981 page_ref_inc(page);
982}
983
984static inline __must_check bool try_get_page(struct page *page)
985{
986 page = compound_head(page);
987 if (WARN_ON_ONCE(page_ref_count(page) <= 0))
988 return false;
977 page_ref_inc(page); 989 page_ref_inc(page);
990 return true;
978} 991}
979 992
980static inline void put_page(struct page *page) 993static inline void put_page(struct page *page)