diff --git a/include/linux/mm.h b/include/linux/mm.h index 461a01c8e4b3e0b77d857395996c2c8a1adeaa22..3c7c2dc176839285f271a3719203a7354240b65b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -921,6 +921,10 @@ static inline bool is_device_public_page(const struct page *page) } #endif /* CONFIG_DEV_PAGEMAP_OPS */ +/* 127: arbitrary random number, small enough to assemble well */ +#define page_ref_zero_or_close_to_overflow(page) \ + ((unsigned int) page_ref_count(page) + 127u <= 127u) + static inline void get_page(struct page *page) { page = compound_head(page); @@ -928,7 +932,7 @@ static inline void get_page(struct page *page) * Getting a normal page or the head of a compound page * requires to already have an elevated page->_refcount. */ - VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page); + VM_BUG_ON_PAGE(page_ref_zero_or_close_to_overflow(page), page); page_ref_inc(page); }