@@ -1812,9 +1812,43 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data)
struct compact_control *cc = (struct compact_control *)data;
struct folio *dst;
int order = folio_order(src);
+ bool has_isolated_pages = false;
+again:
if (!cc->freepages[order].nr_pages) {
- isolate_freepages(cc);
+ int i;
+
+ for (i = order + 1; i < NR_PAGE_ORDERS; i++) {
+ if (cc->freepages[i].nr_pages) {
+ struct page *freepage =
+ list_first_entry(&cc->freepages[i].pages,
+ struct page, lru);
+
+ int start_order = i;
+ unsigned long size = 1 << start_order;
+
+ list_del(&freepage->lru);
+ cc->freepages[i].nr_pages--;
+
+ while (start_order > order) {
+ start_order--;
+ size >>= 1;
+
+ list_add(&freepage[size].lru,
+ &cc->freepages[start_order].pages);
+ cc->freepages[start_order].nr_pages++;
+ set_page_private(&freepage[size], start_order);
+ }
+ dst = (struct folio *)freepage;
+ goto done;
+ }
+ }
+ if (!has_isolated_pages) {
+ isolate_freepages(cc);
+ has_isolated_pages = true;
+ goto again;
+ }
+
if (!cc->freepages[order].nr_pages)
return NULL;
}
@@ -1822,6 +1856,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data)
dst = list_first_entry(&cc->freepages[order].pages, struct folio, lru);
cc->freepages[order].nr_pages--;
list_del(&dst->lru);
+done:
post_alloc_hook(&dst->page, order, __GFP_MOVABLE);
if (order)
prep_compound_page(&dst->page, order);