Lines Matching +full:row +full:- +full:stride
1 // SPDX-License-Identifier: GPL-2.0
9 * Copyright IBM Corp. 2007-2010 Mel Gorman <mel@csn.ul.ie>
17 #include <linux/backing-dev.h>
20 #include <linux/page-isolation.h>
46 * order == -1 is expected when compacting proactively via
53 return order == -1; in is_via_compact_memory()
71 * Page order with-respect-to which proactive compaction
80 #define COMPACTION_HPAGE_ORDER (PMD_SHIFT - PAGE_SHIFT)
102 list_del(&page->lru); in release_free_list()
136 page->mapping = (void *)((unsigned long)mops | PAGE_MAPPING_MOVABLE); in __SetPageMovable()
147 page->mapping = (void *)PAGE_MAPPING_MOVABLE; in __ClearPageMovable()
161 zone->compact_considered = 0; in defer_compaction()
162 zone->compact_defer_shift++; in defer_compaction()
164 if (order < zone->compact_order_failed) in defer_compaction()
165 zone->compact_order_failed = order; in defer_compaction()
167 if (zone->compact_defer_shift > COMPACT_MAX_DEFER_SHIFT) in defer_compaction()
168 zone->compact_defer_shift = COMPACT_MAX_DEFER_SHIFT; in defer_compaction()
176 unsigned long defer_limit = 1UL << zone->compact_defer_shift; in compaction_deferred()
178 if (order < zone->compact_order_failed) in compaction_deferred()
182 if (++zone->compact_considered >= defer_limit) { in compaction_deferred()
183 zone->compact_considered = defer_limit; in compaction_deferred()
201 zone->compact_considered = 0; in compaction_defer_reset()
202 zone->compact_defer_shift = 0; in compaction_defer_reset()
204 if (order >= zone->compact_order_failed) in compaction_defer_reset()
205 zone->compact_order_failed = order + 1; in compaction_defer_reset()
213 if (order < zone->compact_order_failed) in compaction_restarting()
216 return zone->compact_defer_shift == COMPACT_MAX_DEFER_SHIFT && in compaction_restarting()
217 zone->compact_considered >= 1UL << zone->compact_defer_shift; in compaction_restarting()
224 if (cc->ignore_skip_hint) in isolation_suitable()
232 zone->compact_cached_migrate_pfn[0] = zone->zone_start_pfn; in reset_cached_positions()
233 zone->compact_cached_migrate_pfn[1] = zone->zone_start_pfn; in reset_cached_positions()
234 zone->compact_cached_free_pfn = in reset_cached_positions()
235 pageblock_start_pfn(zone_end_pfn(zone) - 1); in reset_cached_positions()
271 while (start_nr-- > 0) { in skip_offline_sections_reverse()
333 * non-movable pageblock as the starting point. in __reset_isolation_pfn()
341 block_pfn = max(block_pfn, zone->zone_start_pfn); in __reset_isolation_pfn()
349 block_pfn = pageblock_end_pfn(pfn) - 1; in __reset_isolation_pfn()
350 block_pfn = min(block_pfn, zone_end_pfn(zone) - 1); in __reset_isolation_pfn()
384 unsigned long migrate_pfn = zone->zone_start_pfn; in __reset_isolation_suitable()
385 unsigned long free_pfn = zone_end_pfn(zone) - 1; in __reset_isolation_suitable()
392 if (!zone->compact_blockskip_flush) in __reset_isolation_suitable()
395 zone->compact_blockskip_flush = false; in __reset_isolation_suitable()
404 free_pfn -= pageblock_nr_pages) { in __reset_isolation_suitable()
412 zone->compact_init_migrate_pfn = reset_migrate; in __reset_isolation_suitable()
413 zone->compact_cached_migrate_pfn[0] = reset_migrate; in __reset_isolation_suitable()
414 zone->compact_cached_migrate_pfn[1] = reset_migrate; in __reset_isolation_suitable()
422 zone->compact_init_free_pfn = reset_free; in __reset_isolation_suitable()
423 zone->compact_cached_free_pfn = reset_free; in __reset_isolation_suitable()
429 zone->compact_cached_migrate_pfn[0] = migrate_pfn; in __reset_isolation_suitable()
430 zone->compact_cached_migrate_pfn[1] = migrate_pfn; in __reset_isolation_suitable()
431 zone->compact_cached_free_pfn = free_pfn; in __reset_isolation_suitable()
440 struct zone *zone = &pgdat->node_zones[zoneid]; in reset_isolation_suitable()
457 if (cc->ignore_skip_hint) in test_and_set_skip()
461 if (!skip && !cc->no_set_skip_hint) in test_and_set_skip()
469 struct zone *zone = cc->zone; in update_cached_migrate()
472 if (cc->no_set_skip_hint) in update_cached_migrate()
478 if (pfn > zone->compact_cached_migrate_pfn[0]) in update_cached_migrate()
479 zone->compact_cached_migrate_pfn[0] = pfn; in update_cached_migrate()
480 if (cc->mode != MIGRATE_ASYNC && in update_cached_migrate()
481 pfn > zone->compact_cached_migrate_pfn[1]) in update_cached_migrate()
482 zone->compact_cached_migrate_pfn[1] = pfn; in update_cached_migrate()
492 struct zone *zone = cc->zone; in update_pageblock_skip()
494 if (cc->no_set_skip_hint) in update_pageblock_skip()
499 if (pfn < zone->compact_cached_free_pfn) in update_pageblock_skip()
500 zone->compact_cached_free_pfn = pfn; in update_pageblock_skip()
543 if (cc->mode == MIGRATE_ASYNC && !cc->contended) { in compact_lock_irqsave()
547 cc->contended = true; in compact_lock_irqsave()
575 cc->contended = true; in compact_unlock_should_abort()
586 * returning 0 on any invalid PFNs or non-free pages inside of the pageblock
593 unsigned int stride, in isolate_freepages_block() argument
605 stride = 1; in isolate_freepages_block()
610 for (; blockpfn < end_pfn; blockpfn += stride, page += stride) { in isolate_freepages_block()
619 && compact_unlock_should_abort(&cc->zone->lock, flags, in isolate_freepages_block()
636 blockpfn += (1UL << order) - 1; in isolate_freepages_block()
637 page += (1UL << order) - 1; in isolate_freepages_block()
638 nr_scanned += (1UL << order) - 1; in isolate_freepages_block()
649 locked = compact_lock_irqsave(&cc->zone->lock, in isolate_freepages_block()
657 /* Found a free page, will break it into order-0 pages */ in isolate_freepages_block()
664 nr_scanned += isolated - 1; in isolate_freepages_block()
666 cc->nr_freepages += isolated; in isolate_freepages_block()
667 list_add_tail(&page->lru, &freelist[order]); in isolate_freepages_block()
669 if (!strict && cc->nr_migratepages <= cc->nr_freepages) { in isolate_freepages_block()
674 blockpfn += isolated - 1; in isolate_freepages_block()
675 page += isolated - 1; in isolate_freepages_block()
685 spin_unlock_irqrestore(&cc->zone->lock, flags); in isolate_freepages_block()
707 cc->total_free_scanned += nr_scanned; in isolate_freepages_block()
714 * isolate_freepages_range() - isolate free pages.
717 * @end_pfn: The one-past-last PFN.
719 * Non-free pages, invalid PFNs, or zone boundaries within the
721 * undo its actions and return zero. cc->freepages[] are empty.
723 * Otherwise, function returns one-past-the-last PFN of isolated page
725 * a free page). cc->freepages[] contain free pages isolated.
735 INIT_LIST_HEAD(&cc->freepages[order]); in isolate_freepages_range()
739 if (block_start_pfn < cc->zone->zone_start_pfn) in isolate_freepages_range()
740 block_start_pfn = cc->zone->zone_start_pfn; in isolate_freepages_range()
762 block_end_pfn, cc->zone)) in isolate_freepages_range()
766 block_end_pfn, cc->freepages, 0, true); in isolate_freepages_range()
771 * non-free pages). in isolate_freepages_range()
778 * pageblock_nr_pages for some non-negative n. (Max order in isolate_freepages_range()
785 release_free_list(cc->freepages); in isolate_freepages_range()
796 pg_data_t *pgdat = cc->zone->zone_pgdat; in too_many_isolated()
814 if (cc->gfp_mask & __GFP_FS) { in too_many_isolated()
827 * skip_isolation_on_order() - determine when to skip folio isolation based on
829 * @order: to-be-isolated folio order
853 * isolate_migratepages_block() - isolate all migrate-able pages within
857 * @end_pfn: The one-past-the-last PFN to isolate, within same pageblock
862 * Returns errno, like -EAGAIN or -EINTR in case e.g signal pending or congestion,
863 * -ENOMEM in case we could not allocate a page, or 0.
864 * cc->migrate_pfn will contain the next pfn to scan.
866 * The pages are isolated on cc->migratepages list (not required to be empty),
867 * and cc->nr_migratepages is updated accordingly.
873 pg_data_t *pgdat = cc->zone->zone_pgdat; in isolate_migratepages_block()
887 cc->migrate_pfn = low_pfn; in isolate_migratepages_block()
896 if (cc->nr_migratepages) in isolate_migratepages_block()
897 return -EAGAIN; in isolate_migratepages_block()
900 if (cc->mode == MIGRATE_ASYNC) in isolate_migratepages_block()
901 return -EAGAIN; in isolate_migratepages_block()
906 return -EINTR; in isolate_migratepages_block()
911 if (cc->direct_compaction && (cc->mode == MIGRATE_ASYNC)) { in isolate_migratepages_block()
913 next_skip_pfn = block_end_pfn(low_pfn, cc->order); in isolate_migratepages_block()
923 * previous order-aligned block, and did not skip it due in isolate_migratepages_block()
931 * We failed to isolate in the previous order-aligned in isolate_migratepages_block()
936 * a compound or a high-order buddy page in the in isolate_migratepages_block()
939 next_skip_pfn = block_end_pfn(low_pfn, cc->order); in isolate_migratepages_block()
954 cc->contended = true; in isolate_migratepages_block()
955 ret = -EINTR; in isolate_migratepages_block()
974 low_pfn == cc->zone->zone_start_pfn)) { in isolate_migratepages_block()
989 if (!cc->alloc_contig) { in isolate_migratepages_block()
993 low_pfn += (1UL << order) - 1; in isolate_migratepages_block()
994 nr_scanned += (1UL << order) - 1; in isolate_migratepages_block()
1004 ret = isolate_or_dissolve_huge_page(page, &cc->migratepages); in isolate_migratepages_block()
1008 * reports an error. In case of -ENOMEM, abort right away. in isolate_migratepages_block()
1011 /* Do not report -EBUSY down the chain */ in isolate_migratepages_block()
1012 if (ret == -EBUSY) in isolate_migratepages_block()
1014 low_pfn += compound_nr(page) - 1; in isolate_migratepages_block()
1015 nr_scanned += compound_nr(page) - 1; in isolate_migratepages_block()
1022 * on the cc->migratepages list. in isolate_migratepages_block()
1025 low_pfn += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1031 * Buddy and cannot be re-allocated because they are in isolate_migratepages_block()
1032 * isolated. Fall-through as the check below handles in isolate_migratepages_block()
1052 low_pfn += (1UL << freepage_order) - 1; in isolate_migratepages_block()
1053 nr_scanned += (1UL << freepage_order) - 1; in isolate_migratepages_block()
1066 if (PageCompound(page) && !cc->alloc_contig) { in isolate_migratepages_block()
1070 if (skip_isolation_on_order(order, cc->order)) { in isolate_migratepages_block()
1072 low_pfn += (1UL << order) - 1; in isolate_migratepages_block()
1073 nr_scanned += (1UL << order) - 1; in isolate_migratepages_block()
1081 * It's possible to migrate LRU and non-lru movable pages. in isolate_migratepages_block()
1107 * sure the page is not being freed elsewhere -- the in isolate_migratepages_block()
1120 if (!mapping && (folio_ref_count(folio) - 1) > folio_mapcount(folio)) in isolate_migratepages_block()
1127 if (!(cc->gfp_mask & __GFP_FS) && mapping) in isolate_migratepages_block()
1143 * it will be able to migrate without blocking - clean pages in isolate_migratepages_block()
1158 * a ->migrate_folio callback are possible to migrate in isolate_migratepages_block()
1180 mapping->a_ops->migrate_folio; in isolate_migratepages_block()
1199 compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); in isolate_migratepages_block()
1212 !cc->finish_pageblock) { in isolate_migratepages_block()
1222 cc->order) && in isolate_migratepages_block()
1223 !cc->alloc_contig)) { in isolate_migratepages_block()
1224 low_pfn += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1225 nr_scanned += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1233 low_pfn += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1242 list_add(&folio->lru, &cc->migratepages); in isolate_migratepages_block()
1244 cc->nr_migratepages += folio_nr_pages(folio); in isolate_migratepages_block()
1246 nr_scanned += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1254 if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX && in isolate_migratepages_block()
1255 !cc->finish_pageblock && !cc->contended) { in isolate_migratepages_block()
1271 if (!skip_on_failure && ret != -ENOMEM) in isolate_migratepages_block()
1276 * instead of migrating, as we cannot form the cc->order buddy in isolate_migratepages_block()
1284 putback_movable_pages(&cc->migratepages); in isolate_migratepages_block()
1285 cc->nr_migratepages = 0; in isolate_migratepages_block()
1290 low_pfn = next_skip_pfn - 1; in isolate_migratepages_block()
1295 next_skip_pfn += 1UL << cc->order; in isolate_migratepages_block()
1298 if (ret == -ENOMEM) in isolate_migratepages_block()
1325 * rescanned twice in a row. in isolate_migratepages_block()
1327 if (low_pfn == end_pfn && (!nr_isolated || cc->finish_pageblock)) { in isolate_migratepages_block()
1328 if (!cc->no_set_skip_hint && valid_page && !skip_updated) in isolate_migratepages_block()
1337 cc->total_migrate_scanned += nr_scanned; in isolate_migratepages_block()
1341 cc->migrate_pfn = low_pfn; in isolate_migratepages_block()
1347 * isolate_migratepages_range() - isolate migrate-able pages in a PFN range
1350 * @end_pfn: The one-past-last PFN.
1352 * Returns -EAGAIN when contented, -EINTR in case of a signal pending, -ENOMEM
1365 if (block_start_pfn < cc->zone->zone_start_pfn) in isolate_migratepages_range()
1366 block_start_pfn = cc->zone->zone_start_pfn; in isolate_migratepages_range()
1376 block_end_pfn, cc->zone)) in isolate_migratepages_range()
1385 if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX) in isolate_migratepages_range()
1403 if ((cc->mode != MIGRATE_ASYNC) || !cc->direct_compaction) in suitable_migration_source()
1408 if (cc->migratetype == MIGRATE_MOVABLE) in suitable_migration_source()
1411 return block_mt == cc->migratetype; in suitable_migration_source()
1420 int order = cc->order > 0 ? cc->order : pageblock_order; in suitable_migration_target()
1423 * We are checking page_order without zone->lock taken. But in suitable_migration_target()
1431 if (cc->ignore_block_suitable) in suitable_migration_target()
1445 unsigned short shift = BITS_PER_LONG - 1; in freelist_scan_limit()
1447 return (COMPACT_CLUSTER_MAX >> min(shift, cc->fast_search_fail)) + 1; in freelist_scan_limit()
1456 return (cc->free_pfn >> pageblock_order) in compact_scanners_met()
1457 <= (cc->migrate_pfn >> pageblock_order); in compact_scanners_met()
1470 if (!list_is_first(&freepage->buddy_list, freelist)) { in move_freelist_head()
1471 list_cut_before(&sublist, freelist, &freepage->buddy_list); in move_freelist_head()
1487 if (!list_is_last(&freepage->buddy_list, freelist)) { in move_freelist_tail()
1488 list_cut_position(&sublist, freelist, &freepage->buddy_list); in move_freelist_tail()
1500 if (cc->nr_freepages >= cc->nr_migratepages) in fast_isolate_around()
1504 if (cc->direct_compaction && cc->mode == MIGRATE_ASYNC) in fast_isolate_around()
1508 start_pfn = max(pageblock_start_pfn(pfn), cc->zone->zone_start_pfn); in fast_isolate_around()
1509 end_pfn = min(pageblock_end_pfn(pfn), zone_end_pfn(cc->zone)); in fast_isolate_around()
1511 page = pageblock_pfn_to_page(start_pfn, end_pfn, cc->zone); in fast_isolate_around()
1515 isolate_freepages_block(cc, &start_pfn, end_pfn, cc->freepages, 1, false); in fast_isolate_around()
1518 if (start_pfn == end_pfn && !cc->no_set_skip_hint) in fast_isolate_around()
1522 /* Search orders in round-robin fashion */
1525 order--; in next_search_order()
1527 order = cc->order - 1; in next_search_order()
1530 if (order == cc->search_order) { in next_search_order()
1531 cc->search_order--; in next_search_order()
1532 if (cc->search_order < 0) in next_search_order()
1533 cc->search_order = cc->order - 1; in next_search_order()
1534 return -1; in next_search_order()
1552 if (cc->order <= 0) in fast_isolate_freepages()
1559 if (cc->free_pfn >= cc->zone->compact_init_free_pfn) { in fast_isolate_freepages()
1568 distance = (cc->free_pfn - cc->migrate_pfn); in fast_isolate_freepages()
1569 low_pfn = pageblock_start_pfn(cc->free_pfn - (distance >> 2)); in fast_isolate_freepages()
1570 min_pfn = pageblock_start_pfn(cc->free_pfn - (distance >> 1)); in fast_isolate_freepages()
1579 cc->search_order = min_t(unsigned int, cc->order - 1, cc->search_order); in fast_isolate_freepages()
1581 for (order = cc->search_order; in fast_isolate_freepages()
1584 struct free_area *area = &cc->zone->free_area[order]; in fast_isolate_freepages()
1591 if (!area->nr_free) in fast_isolate_freepages()
1594 spin_lock_irqsave(&cc->zone->lock, flags); in fast_isolate_freepages()
1595 freelist = &area->free_list[MIGRATE_MOVABLE]; in fast_isolate_freepages()
1605 cc->zone->zone_start_pfn); in fast_isolate_freepages()
1608 cc->fast_search_fail = 0; in fast_isolate_freepages()
1609 cc->search_order = order; in fast_isolate_freepages()
1641 nr_scanned += nr_isolated - 1; in fast_isolate_freepages()
1643 cc->nr_freepages += nr_isolated; in fast_isolate_freepages()
1644 list_add_tail(&page->lru, &cc->freepages[order]); in fast_isolate_freepages()
1648 order = cc->search_order + 1; in fast_isolate_freepages()
1653 spin_unlock_irqrestore(&cc->zone->lock, flags); in fast_isolate_freepages()
1656 if (cc->nr_freepages >= cc->nr_migratepages) in fast_isolate_freepages()
1667 trace_mm_compaction_fast_isolate_freepages(min_pfn, cc->free_pfn, in fast_isolate_freepages()
1671 cc->fast_search_fail++; in fast_isolate_freepages()
1680 cc->free_pfn = highest; in fast_isolate_freepages()
1682 if (cc->direct_compaction && pfn_valid(min_pfn)) { in fast_isolate_freepages()
1685 zone_end_pfn(cc->zone)), in fast_isolate_freepages()
1686 cc->zone); in fast_isolate_freepages()
1690 cc->free_pfn = min_pfn; in fast_isolate_freepages()
1696 if (highest && highest >= cc->zone->compact_cached_free_pfn) { in fast_isolate_freepages()
1697 highest -= pageblock_nr_pages; in fast_isolate_freepages()
1698 cc->zone->compact_cached_free_pfn = highest; in fast_isolate_freepages()
1701 cc->total_free_scanned += nr_scanned; in fast_isolate_freepages()
1715 struct zone *zone = cc->zone; in isolate_freepages()
1721 unsigned int stride; in isolate_freepages() local
1725 if (cc->nr_freepages) in isolate_freepages()
1730 * successfully isolated from, zone-cached value, or the end of the in isolate_freepages()
1733 * block_start_pfn -= pageblock_nr_pages in the for loop. in isolate_freepages()
1739 isolate_start_pfn = cc->free_pfn; in isolate_freepages()
1743 low_pfn = pageblock_end_pfn(cc->migrate_pfn); in isolate_freepages()
1744 stride = cc->mode == MIGRATE_ASYNC ? COMPACT_CLUSTER_MAX : 1; in isolate_freepages()
1748 * pages on cc->migratepages. We stop searching if the migrate in isolate_freepages()
1753 block_start_pfn -= pageblock_nr_pages, in isolate_freepages()
1786 block_end_pfn, cc->freepages, stride, false); in isolate_freepages()
1790 update_pageblock_skip(cc, page, block_start_pfn - in isolate_freepages()
1794 if (cc->nr_freepages >= cc->nr_migratepages) { in isolate_freepages()
1801 block_start_pfn - pageblock_nr_pages; in isolate_freepages()
1812 /* Adjust stride depending on isolation */ in isolate_freepages()
1814 stride = 1; in isolate_freepages()
1817 stride = min_t(unsigned int, COMPACT_CLUSTER_MAX, stride << 1); in isolate_freepages()
1826 cc->free_pfn = isolate_start_pfn; in isolate_freepages()
1830 * This is a migrate-callback that "allocates" freepages by taking pages
1845 if (!list_empty(&cc->freepages[start_order])) in compaction_alloc_noprof()
1857 freepage = list_first_entry(&cc->freepages[start_order], struct page, in compaction_alloc_noprof()
1861 list_del(&freepage->lru); in compaction_alloc_noprof()
1864 start_order--; in compaction_alloc_noprof()
1867 list_add(&freepage[size].lru, &cc->freepages[start_order]); in compaction_alloc_noprof()
1872 post_alloc_hook(&dst->page, order, __GFP_MOVABLE); in compaction_alloc_noprof()
1873 set_page_refcounted(&dst->page); in compaction_alloc_noprof()
1875 prep_compound_page(&dst->page, order); in compaction_alloc_noprof()
1876 cc->nr_freepages -= 1 << order; in compaction_alloc_noprof()
1877 cc->nr_migratepages -= 1 << order; in compaction_alloc_noprof()
1878 return page_rmappable_folio(&dst->page); in compaction_alloc_noprof()
1887 * This is a migrate-callback that "frees" freepages back to the isolated
1895 struct page *page = &dst->page; in compaction_free()
1899 list_add(&dst->lru, &cc->freepages[order]); in compaction_free()
1900 cc->nr_freepages += 1 << order; in compaction_free()
1902 cc->nr_migratepages += 1 << order; in compaction_free()
1933 if (cc->fast_start_pfn == ULONG_MAX) in update_fast_start_pfn()
1936 if (!cc->fast_start_pfn) in update_fast_start_pfn()
1937 cc->fast_start_pfn = pfn; in update_fast_start_pfn()
1939 cc->fast_start_pfn = min(cc->fast_start_pfn, pfn); in update_fast_start_pfn()
1945 if (!cc->fast_start_pfn || cc->fast_start_pfn == ULONG_MAX) in reinit_migrate_pfn()
1946 return cc->migrate_pfn; in reinit_migrate_pfn()
1948 cc->migrate_pfn = cc->fast_start_pfn; in reinit_migrate_pfn()
1949 cc->fast_start_pfn = ULONG_MAX; in reinit_migrate_pfn()
1951 return cc->migrate_pfn; in reinit_migrate_pfn()
1964 unsigned long pfn = cc->migrate_pfn; in fast_find_migrateblock()
1970 if (cc->ignore_skip_hint) in fast_find_migrateblock()
1977 if (cc->finish_pageblock) in fast_find_migrateblock()
1985 if (pfn != cc->zone->zone_start_pfn && pfn != pageblock_start_pfn(pfn)) in fast_find_migrateblock()
1993 if (cc->order <= PAGE_ALLOC_COSTLY_ORDER) in fast_find_migrateblock()
2002 if (cc->direct_compaction && cc->migratetype != MIGRATE_MOVABLE) in fast_find_migrateblock()
2011 distance = (cc->free_pfn - cc->migrate_pfn) >> 1; in fast_find_migrateblock()
2012 if (cc->migrate_pfn != cc->zone->zone_start_pfn) in fast_find_migrateblock()
2014 high_pfn = pageblock_start_pfn(cc->migrate_pfn + distance); in fast_find_migrateblock()
2016 for (order = cc->order - 1; in fast_find_migrateblock()
2018 order--) { in fast_find_migrateblock()
2019 struct free_area *area = &cc->zone->free_area[order]; in fast_find_migrateblock()
2024 if (!area->nr_free) in fast_find_migrateblock()
2027 spin_lock_irqsave(&cc->zone->lock, flags); in fast_find_migrateblock()
2028 freelist = &area->free_list[MIGRATE_MOVABLE]; in fast_find_migrateblock()
2053 if (pfn < cc->zone->zone_start_pfn) in fast_find_migrateblock()
2054 pfn = cc->zone->zone_start_pfn; in fast_find_migrateblock()
2055 cc->fast_search_fail = 0; in fast_find_migrateblock()
2060 spin_unlock_irqrestore(&cc->zone->lock, flags); in fast_find_migrateblock()
2063 cc->total_migrate_scanned += nr_scanned; in fast_find_migrateblock()
2070 cc->fast_search_fail++; in fast_find_migrateblock()
2089 (cc->mode != MIGRATE_SYNC ? ISOLATE_ASYNC_MIGRATE : 0); in isolate_migratepages()
2099 if (block_start_pfn < cc->zone->zone_start_pfn) in isolate_migratepages()
2100 block_start_pfn = cc->zone->zone_start_pfn; in isolate_migratepages()
2107 fast_find_block = low_pfn != cc->migrate_pfn && !cc->fast_search_fail; in isolate_migratepages()
2116 for (; block_end_pfn <= cc->free_pfn; in isolate_migratepages()
2118 cc->migrate_pfn = low_pfn = block_end_pfn, in isolate_migratepages()
2131 block_end_pfn, cc->zone); in isolate_migratepages()
2137 block_end_pfn = min(next_pfn, cc->free_pfn); in isolate_migratepages()
2149 low_pfn == cc->zone->zone_start_pfn) && in isolate_migratepages()
2179 return cc->nr_migratepages ? ISOLATE_SUCCESS : ISOLATE_NONE; in isolate_migratepages()
2185 * pgdat_kswapd_lock() pins pgdat->kswapd, so a concurrent kswapd_stop() can't
2193 running = pgdat->kswapd && task_is_running(pgdat->kswapd); in kswapd_is_running()
2222 score = zone->present_pages * fragmentation_score_zone(zone); in fragmentation_score_zone_weighted()
2223 return div64_ul(score, zone->zone_pgdat->node_present_pages + 1); in fragmentation_score_zone_weighted()
2227 * The per-node proactive (background) compaction process is started by its
2230 * the node's score falls below the low threshold, or one of the back-off
2241 zone = &pgdat->node_zones[zoneid]; in fragmentation_score_node()
2259 wmark_low = max(100U - sysctl_compaction_proactiveness, 5U); in fragmentation_score_wmark()
2277 const int migratetype = cc->migratetype; in __compact_finished()
2283 reset_cached_positions(cc->zone); in __compact_finished()
2291 if (cc->direct_compaction) in __compact_finished()
2292 cc->zone->compact_blockskip_flush = true; in __compact_finished()
2294 if (cc->whole_zone) in __compact_finished()
2300 if (cc->proactive_compaction) { in __compact_finished()
2304 pgdat = cc->zone->zone_pgdat; in __compact_finished()
2308 score = fragmentation_score_zone(cc->zone); in __compact_finished()
2319 if (is_via_compact_memory(cc->order)) in __compact_finished()
2328 if (!pageblock_aligned(cc->migrate_pfn)) in __compact_finished()
2333 for (order = cc->order; order < NR_PAGE_ORDERS; order++) { in __compact_finished()
2334 struct free_area *area = &cc->zone->free_area[order]; in __compact_finished()
2352 true, &can_steal) != -1) in __compact_finished()
2355 * stealing for a non-movable allocation, make sure in __compact_finished()
2365 if (cc->contended || fatal_signal_pending(current)) in __compact_finished()
2376 trace_mm_compaction_finished(cc->zone, cc->order, ret); in compact_finished()
2389 * Watermarks for order-0 must be met for compaction to be able to in __compaction_suitable()
2423 * index of -1000 would imply allocations might succeed depending on in compaction_suitable()
2424 * watermarks, but we already failed the high-order watermark check in compaction_suitable()
2429 * ignore fragindex for non-costly orders where the alternative to in compaction_suitable()
2465 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in compaction_zonelist_suitable()
2466 ac->highest_zoneidx, ac->nodemask) { in compaction_zonelist_suitable()
2477 if (__compaction_suitable(zone, order, ac->highest_zoneidx, in compaction_zonelist_suitable()
2506 * free memory in the non-CMA pageblocks. Otherwise compaction could form in compaction_suit_allocation_order()
2507 * the high-order page in CMA pageblocks, which would not help the in compaction_suit_allocation_order()
2510 * possibility that compaction would migrate pages from non-CMA to CMA in compaction_suit_allocation_order()
2531 unsigned long start_pfn = cc->zone->zone_start_pfn; in compact_zone()
2532 unsigned long end_pfn = zone_end_pfn(cc->zone); in compact_zone()
2534 const bool sync = cc->mode != MIGRATE_ASYNC; in compact_zone()
2543 cc->total_migrate_scanned = 0; in compact_zone()
2544 cc->total_free_scanned = 0; in compact_zone()
2545 cc->nr_migratepages = 0; in compact_zone()
2546 cc->nr_freepages = 0; in compact_zone()
2548 INIT_LIST_HEAD(&cc->freepages[order]); in compact_zone()
2549 INIT_LIST_HEAD(&cc->migratepages); in compact_zone()
2551 cc->migratetype = gfp_migratetype(cc->gfp_mask); in compact_zone()
2553 if (!is_via_compact_memory(cc->order)) { in compact_zone()
2554 ret = compaction_suit_allocation_order(cc->zone, cc->order, in compact_zone()
2555 cc->highest_zoneidx, in compact_zone()
2556 cc->alloc_flags, in compact_zone()
2557 cc->mode == MIGRATE_ASYNC); in compact_zone()
2566 if (compaction_restarting(cc->zone, cc->order)) in compact_zone()
2567 __reset_isolation_suitable(cc->zone); in compact_zone()
2575 cc->fast_start_pfn = 0; in compact_zone()
2576 if (cc->whole_zone) { in compact_zone()
2577 cc->migrate_pfn = start_pfn; in compact_zone()
2578 cc->free_pfn = pageblock_start_pfn(end_pfn - 1); in compact_zone()
2580 cc->migrate_pfn = cc->zone->compact_cached_migrate_pfn[sync]; in compact_zone()
2581 cc->free_pfn = cc->zone->compact_cached_free_pfn; in compact_zone()
2582 if (cc->free_pfn < start_pfn || cc->free_pfn >= end_pfn) { in compact_zone()
2583 cc->free_pfn = pageblock_start_pfn(end_pfn - 1); in compact_zone()
2584 cc->zone->compact_cached_free_pfn = cc->free_pfn; in compact_zone()
2586 if (cc->migrate_pfn < start_pfn || cc->migrate_pfn >= end_pfn) { in compact_zone()
2587 cc->migrate_pfn = start_pfn; in compact_zone()
2588 cc->zone->compact_cached_migrate_pfn[0] = cc->migrate_pfn; in compact_zone()
2589 cc->zone->compact_cached_migrate_pfn[1] = cc->migrate_pfn; in compact_zone()
2592 if (cc->migrate_pfn <= cc->zone->compact_init_migrate_pfn) in compact_zone()
2593 cc->whole_zone = true; in compact_zone()
2607 cc->zone->compact_cached_migrate_pfn[0] == cc->zone->compact_cached_migrate_pfn[1]; in compact_zone()
2616 unsigned long iteration_start_pfn = cc->migrate_pfn; in compact_zone()
2626 cc->finish_pageblock = false; in compact_zone()
2629 cc->finish_pageblock = true; in compact_zone()
2636 putback_movable_pages(&cc->migratepages); in compact_zone()
2637 cc->nr_migratepages = 0; in compact_zone()
2641 cc->zone->compact_cached_migrate_pfn[1] = in compact_zone()
2642 cc->zone->compact_cached_migrate_pfn[0]; in compact_zone()
2648 * previous cc->order aligned block. in compact_zone()
2653 last_migrated_pfn = max(cc->zone->zone_start_pfn, in compact_zone()
2654 pageblock_start_pfn(cc->migrate_pfn - 1)); in compact_zone()
2659 * compaction_alloc/free() will update cc->nr_migratepages in compact_zone()
2662 nr_migratepages = cc->nr_migratepages; in compact_zone()
2663 err = migrate_pages(&cc->migratepages, compaction_alloc, in compact_zone()
2664 compaction_free, (unsigned long)cc, cc->mode, in compact_zone()
2670 cc->nr_migratepages = 0; in compact_zone()
2672 putback_movable_pages(&cc->migratepages); in compact_zone()
2674 * migrate_pages() may return -ENOMEM when scanners meet in compact_zone()
2677 if (err == -ENOMEM && !compact_scanners_met(cc)) { in compact_zone()
2683 * within the pageblock_order-aligned block and in compact_zone()
2692 if (!pageblock_aligned(cc->migrate_pfn) && in compact_zone()
2693 !cc->ignore_skip_hint && !cc->finish_pageblock && in compact_zone()
2694 (cc->mode < MIGRATE_SYNC)) { in compact_zone()
2695 cc->finish_pageblock = true; in compact_zone()
2702 if (cc->order == COMPACTION_HPAGE_ORDER) in compact_zone()
2710 if (capc && capc->page) { in compact_zone()
2718 * cc->order aligned block where we migrated from? If yes, in compact_zone()
2723 if (cc->order > 0 && last_migrated_pfn) { in compact_zone()
2725 block_start_pfn(cc->migrate_pfn, cc->order); in compact_zone()
2728 lru_add_drain_cpu_zone(cc->zone); in compact_zone()
2740 if (cc->nr_freepages > 0) { in compact_zone()
2741 unsigned long free_pfn = release_free_list(cc->freepages); in compact_zone()
2743 cc->nr_freepages = 0; in compact_zone()
2751 if (free_pfn > cc->zone->compact_cached_free_pfn) in compact_zone()
2752 cc->zone->compact_cached_free_pfn = free_pfn; in compact_zone()
2755 count_compact_events(COMPACTMIGRATE_SCANNED, cc->total_migrate_scanned); in compact_zone()
2756 count_compact_events(COMPACTFREE_SCANNED, cc->total_free_scanned); in compact_zone()
2760 VM_BUG_ON(!list_empty(&cc->migratepages)); in compact_zone()
2796 WRITE_ONCE(current->capture_control, &capc); in compact_zone_order()
2805 WRITE_ONCE(current->capture_control, NULL); in compact_zone_order()
2820 * try_to_compact_pages - Direct compact to satisfy a high-order allocation
2844 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in try_to_compact_pages()
2845 ac->highest_zoneidx, ac->nodemask) { in try_to_compact_pages()
2860 alloc_flags, ac->highest_zoneidx, capture); in try_to_compact_pages()
2899 * compact_node() - compact all zones within a node
2906 * reaching score targets due to various back-off conditions, such as,
2907 * contention on per-node or per-zone locks.
2914 .order = -1, in compact_node()
2923 zone = &pgdat->node_zones[zoneid]; in compact_node()
2928 return -EINTR; in compact_node()
2975 if (pgdat->proactive_compact_trigger) in compaction_proactiveness_sysctl_handler()
2978 pgdat->proactive_compact_trigger = true; in compaction_proactiveness_sysctl_handler()
2979 trace_mm_compaction_wakeup_kcompactd(pgdat->node_id, -1, in compaction_proactiveness_sysctl_handler()
2980 pgdat->nr_zones - 1); in compaction_proactiveness_sysctl_handler()
2981 wake_up_interruptible(&pgdat->kcompactd_wait); in compaction_proactiveness_sysctl_handler()
3002 return -EINVAL; in sysctl_compaction_handler()
3015 int nid = dev->id; in compact_store()
3030 return device_create_file(&node->dev, &dev_attr_compact); in compaction_register_node()
3035 device_remove_file(&node->dev, &dev_attr_compact); in compaction_unregister_node()
3041 return pgdat->kcompactd_max_order > 0 || kthread_should_stop() || in kcompactd_work_requested()
3042 pgdat->proactive_compact_trigger; in kcompactd_work_requested()
3049 enum zone_type highest_zoneidx = pgdat->kcompactd_highest_zoneidx; in kcompactd_node_suitable()
3053 zone = &pgdat->node_zones[zoneid]; in kcompactd_node_suitable()
3059 pgdat->kcompactd_max_order, in kcompactd_node_suitable()
3078 .order = pgdat->kcompactd_max_order, in kcompactd_do_work()
3079 .search_order = pgdat->kcompactd_max_order, in kcompactd_do_work()
3080 .highest_zoneidx = pgdat->kcompactd_highest_zoneidx, in kcompactd_do_work()
3087 trace_mm_compaction_kcompactd_wake(pgdat->node_id, cc.order, in kcompactd_do_work()
3094 zone = &pgdat->node_zones[zoneid]; in kcompactd_do_work()
3142 if (pgdat->kcompactd_max_order <= cc.order) in kcompactd_do_work()
3143 pgdat->kcompactd_max_order = 0; in kcompactd_do_work()
3144 if (pgdat->kcompactd_highest_zoneidx >= cc.highest_zoneidx) in kcompactd_do_work()
3145 pgdat->kcompactd_highest_zoneidx = pgdat->nr_zones - 1; in kcompactd_do_work()
3153 if (pgdat->kcompactd_max_order < order) in wakeup_kcompactd()
3154 pgdat->kcompactd_max_order = order; in wakeup_kcompactd()
3156 if (pgdat->kcompactd_highest_zoneidx > highest_zoneidx) in wakeup_kcompactd()
3157 pgdat->kcompactd_highest_zoneidx = highest_zoneidx; in wakeup_kcompactd()
3163 if (!wq_has_sleeper(&pgdat->kcompactd_wait)) in wakeup_kcompactd()
3169 trace_mm_compaction_wakeup_kcompactd(pgdat->node_id, order, in wakeup_kcompactd()
3171 wake_up_interruptible(&pgdat->kcompactd_wait); in wakeup_kcompactd()
3184 current->flags |= PF_KCOMPACTD; in kcompactd()
3187 pgdat->kcompactd_max_order = 0; in kcompactd()
3188 pgdat->kcompactd_highest_zoneidx = pgdat->nr_zones - 1; in kcompactd()
3199 trace_mm_compaction_kcompactd_sleep(pgdat->node_id); in kcompactd()
3200 if (wait_event_freezable_timeout(pgdat->kcompactd_wait, in kcompactd()
3202 !pgdat->proactive_compact_trigger) { in kcompactd()
3237 if (unlikely(pgdat->proactive_compact_trigger)) in kcompactd()
3238 pgdat->proactive_compact_trigger = false; in kcompactd()
3241 current->flags &= ~PF_KCOMPACTD; in kcompactd()
3247 * This kcompactd start function will be called by init and node-hot-add.
3248 * On node-hot-add, kcompactd will moved to proper cpus if cpus are hot-added.
3254 if (pgdat->kcompactd) in kcompactd_run()
3257 pgdat->kcompactd = kthread_create_on_node(kcompactd, pgdat, nid, "kcompactd%d", nid); in kcompactd_run()
3258 if (IS_ERR(pgdat->kcompactd)) { in kcompactd_run()
3260 pgdat->kcompactd = NULL; in kcompactd_run()
3262 wake_up_process(pgdat->kcompactd); in kcompactd_run()
3272 struct task_struct *kcompactd = NODE_DATA(nid)->kcompactd; in kcompactd_stop()
3276 NODE_DATA(nid)->kcompactd = NULL; in kcompactd_stop()
3288 old = *(int *)table->data; in proc_dointvec_minmax_warn_RT_change()
3292 if (old != *(int *)table->data) in proc_dointvec_minmax_warn_RT_change()
3294 table->procname, current->comm, in proc_dointvec_minmax_warn_RT_change()