@@ -216,8 +216,10 @@ int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *,
#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
+#define page_nth(head, tail) (page_to_pfn(tail) - page_to_pfn(head))
#else
#define nth_page(page,n) ((page) + (n))
+#define page_nth(head, tail) ((tail) - (head))
#endif
/* to align the pointer to the (next) page boundary */
@@ -263,8 +263,8 @@ static inline struct page *compound_range_next(struct page *start,
next = nth_page(start, i);
page = compound_head(next);
if (PageHead(page))
- nr = min_t(unsigned int,
- page + compound_nr(page) - next, npages - i);
+ nr = min_t(unsigned int, npages - i,
+ compound_nr(page) - page_nth(page, next));
*ntails = nr;
return page;