@@ -510,6 +510,21 @@ static inline void get_page(struct page *page)
atomic_inc(&page->_count);
}
+static inline __must_check bool try_get_page(struct page *page)
+{
+ struct page *head = compound_head(page);
+
+ /*
+ * get_page() increases always head page's refcount, either directly or
+ * via __get_page_tail() for tail page, so we check that
+ */
+ if (WARN_ON_ONCE(page_ref_count(head) <= 0))
+ return false;
+
+ get_page(page);
+ return true;
+}
+
static inline struct page *virt_to_head_page(const void *x)
{
struct page *page = virt_to_page(x);