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>
57 * Page order with-respect-to which proactive compaction
66 #define COMPACTION_HPAGE_ORDER (PMD_SHIFT - PAGE_SHIFT)
76 list_del(&page->lru); in release_freepages()
92 list_del(&page->lru); in split_map_pages()
102 list_add(&page->lru, &tmp_list); in split_map_pages()
130 page->mapping = (void *)((unsigned long)mops | PAGE_MAPPING_MOVABLE); in __SetPageMovable()
141 page->mapping = (void *)PAGE_MAPPING_MOVABLE; in __ClearPageMovable()
155 zone->compact_considered = 0; in defer_compaction()
156 zone->compact_defer_shift++; in defer_compaction()
158 if (order < zone->compact_order_failed) in defer_compaction()
159 zone->compact_order_failed = order; in defer_compaction()
161 if (zone->compact_defer_shift > COMPACT_MAX_DEFER_SHIFT) in defer_compaction()
162 zone->compact_defer_shift = COMPACT_MAX_DEFER_SHIFT; in defer_compaction()
170 unsigned long defer_limit = 1UL << zone->compact_defer_shift; in compaction_deferred()
172 if (order < zone->compact_order_failed) in compaction_deferred()
176 if (++zone->compact_considered >= defer_limit) { in compaction_deferred()
177 zone->compact_considered = defer_limit; in compaction_deferred()
195 zone->compact_considered = 0; in compaction_defer_reset()
196 zone->compact_defer_shift = 0; in compaction_defer_reset()
198 if (order >= zone->compact_order_failed) in compaction_defer_reset()
199 zone->compact_order_failed = order + 1; in compaction_defer_reset()
207 if (order < zone->compact_order_failed) in compaction_restarting()
210 return zone->compact_defer_shift == COMPACT_MAX_DEFER_SHIFT && in compaction_restarting()
211 zone->compact_considered >= 1UL << zone->compact_defer_shift; in compaction_restarting()
218 if (cc->ignore_skip_hint) in isolation_suitable()
226 zone->compact_cached_migrate_pfn[0] = zone->zone_start_pfn; in reset_cached_positions()
227 zone->compact_cached_migrate_pfn[1] = zone->zone_start_pfn; in reset_cached_positions()
228 zone->compact_cached_free_pfn = in reset_cached_positions()
229 pageblock_start_pfn(zone_end_pfn(zone) - 1); in reset_cached_positions()
265 while (start_nr-- > 0) { in skip_offline_sections_reverse()
327 * non-movable pageblock as the starting point. in __reset_isolation_pfn()
335 block_pfn = max(block_pfn, zone->zone_start_pfn); in __reset_isolation_pfn()
343 block_pfn = pageblock_end_pfn(pfn) - 1; in __reset_isolation_pfn()
344 block_pfn = min(block_pfn, zone_end_pfn(zone) - 1); in __reset_isolation_pfn()
378 unsigned long migrate_pfn = zone->zone_start_pfn; in __reset_isolation_suitable()
379 unsigned long free_pfn = zone_end_pfn(zone) - 1; in __reset_isolation_suitable()
386 if (!zone->compact_blockskip_flush) in __reset_isolation_suitable()
389 zone->compact_blockskip_flush = false; in __reset_isolation_suitable()
398 free_pfn -= pageblock_nr_pages) { in __reset_isolation_suitable()
406 zone->compact_init_migrate_pfn = reset_migrate; in __reset_isolation_suitable()
407 zone->compact_cached_migrate_pfn[0] = reset_migrate; in __reset_isolation_suitable()
408 zone->compact_cached_migrate_pfn[1] = reset_migrate; in __reset_isolation_suitable()
416 zone->compact_init_free_pfn = reset_free; in __reset_isolation_suitable()
417 zone->compact_cached_free_pfn = reset_free; in __reset_isolation_suitable()
423 zone->compact_cached_migrate_pfn[0] = migrate_pfn; in __reset_isolation_suitable()
424 zone->compact_cached_migrate_pfn[1] = migrate_pfn; in __reset_isolation_suitable()
425 zone->compact_cached_free_pfn = free_pfn; in __reset_isolation_suitable()
434 struct zone *zone = &pgdat->node_zones[zoneid]; in reset_isolation_suitable()
451 if (cc->ignore_skip_hint) in test_and_set_skip()
455 if (!skip && !cc->no_set_skip_hint) in test_and_set_skip()
463 struct zone *zone = cc->zone; in update_cached_migrate()
466 if (cc->no_set_skip_hint) in update_cached_migrate()
472 if (pfn > zone->compact_cached_migrate_pfn[0]) in update_cached_migrate()
473 zone->compact_cached_migrate_pfn[0] = pfn; in update_cached_migrate()
474 if (cc->mode != MIGRATE_ASYNC && in update_cached_migrate()
475 pfn > zone->compact_cached_migrate_pfn[1]) in update_cached_migrate()
476 zone->compact_cached_migrate_pfn[1] = pfn; in update_cached_migrate()
486 struct zone *zone = cc->zone; in update_pageblock_skip()
488 if (cc->no_set_skip_hint) in update_pageblock_skip()
493 if (pfn < zone->compact_cached_free_pfn) in update_pageblock_skip()
494 zone->compact_cached_free_pfn = pfn; in update_pageblock_skip()
537 if (cc->mode == MIGRATE_ASYNC && !cc->contended) { in compact_lock_irqsave()
541 cc->contended = true; in compact_lock_irqsave()
569 cc->contended = true; in compact_unlock_should_abort()
580 * returning 0 on any invalid PFNs or non-free pages inside of the pageblock
587 unsigned int stride, in isolate_freepages_block() argument
599 stride = 1; in isolate_freepages_block()
604 for (; blockpfn < end_pfn; blockpfn += stride, page += stride) { in isolate_freepages_block()
613 && compact_unlock_should_abort(&cc->zone->lock, flags, in isolate_freepages_block()
629 blockpfn += (1UL << order) - 1; in isolate_freepages_block()
630 page += (1UL << order) - 1; in isolate_freepages_block()
631 nr_scanned += (1UL << order) - 1; in isolate_freepages_block()
642 locked = compact_lock_irqsave(&cc->zone->lock, in isolate_freepages_block()
650 /* Found a free page, will break it into order-0 pages */ in isolate_freepages_block()
657 nr_scanned += isolated - 1; in isolate_freepages_block()
659 cc->nr_freepages += isolated; in isolate_freepages_block()
660 list_add_tail(&page->lru, freelist); in isolate_freepages_block()
662 if (!strict && cc->nr_migratepages <= cc->nr_freepages) { in isolate_freepages_block()
667 blockpfn += isolated - 1; in isolate_freepages_block()
668 page += isolated - 1; in isolate_freepages_block()
678 spin_unlock_irqrestore(&cc->zone->lock, flags); in isolate_freepages_block()
700 cc->total_free_scanned += nr_scanned; in isolate_freepages_block()
707 * isolate_freepages_range() - isolate free pages.
710 * @end_pfn: The one-past-last PFN.
712 * Non-free pages, invalid PFNs, or zone boundaries within the
716 * Otherwise, function returns one-past-the-last PFN of isolated page
729 if (block_start_pfn < cc->zone->zone_start_pfn) in isolate_freepages_range()
730 block_start_pfn = cc->zone->zone_start_pfn; in isolate_freepages_range()
752 block_end_pfn, cc->zone)) in isolate_freepages_range()
761 * non-free pages). in isolate_freepages_range()
768 * pageblock_nr_pages for some non-negative n. (Max order in isolate_freepages_range()
789 pg_data_t *pgdat = cc->zone->zone_pgdat; in too_many_isolated()
807 if (cc->gfp_mask & __GFP_FS) { in too_many_isolated()
820 * isolate_migratepages_block() - isolate all migrate-able pages within
824 * @end_pfn: The one-past-the-last PFN to isolate, within same pageblock
829 * Returns errno, like -EAGAIN or -EINTR in case e.g signal pending or congestion,
830 * -ENOMEM in case we could not allocate a page, or 0.
831 * cc->migrate_pfn will contain the next pfn to scan.
833 * The pages are isolated on cc->migratepages list (not required to be empty),
834 * and cc->nr_migratepages is updated accordingly.
840 pg_data_t *pgdat = cc->zone->zone_pgdat; in isolate_migratepages_block()
854 cc->migrate_pfn = low_pfn; in isolate_migratepages_block()
863 if (cc->nr_migratepages) in isolate_migratepages_block()
864 return -EAGAIN; in isolate_migratepages_block()
867 if (cc->mode == MIGRATE_ASYNC) in isolate_migratepages_block()
868 return -EAGAIN; in isolate_migratepages_block()
873 return -EINTR; in isolate_migratepages_block()
878 if (cc->direct_compaction && (cc->mode == MIGRATE_ASYNC)) { in isolate_migratepages_block()
880 next_skip_pfn = block_end_pfn(low_pfn, cc->order); in isolate_migratepages_block()
890 * previous order-aligned block, and did not skip it due in isolate_migratepages_block()
898 * We failed to isolate in the previous order-aligned in isolate_migratepages_block()
903 * a compound or a high-order buddy page in the in isolate_migratepages_block()
906 next_skip_pfn = block_end_pfn(low_pfn, cc->order); in isolate_migratepages_block()
921 cc->contended = true; in isolate_migratepages_block()
922 ret = -EINTR; in isolate_migratepages_block()
941 low_pfn == cc->zone->zone_start_pfn)) { in isolate_migratepages_block()
950 if (PageHuge(page) && cc->alloc_contig) { in isolate_migratepages_block()
956 ret = isolate_or_dissolve_huge_page(page, &cc->migratepages); in isolate_migratepages_block()
960 * reports an error. In case of -ENOMEM, abort right away. in isolate_migratepages_block()
963 /* Do not report -EBUSY down the chain */ in isolate_migratepages_block()
964 if (ret == -EBUSY) in isolate_migratepages_block()
966 low_pfn += compound_nr(page) - 1; in isolate_migratepages_block()
967 nr_scanned += compound_nr(page) - 1; in isolate_migratepages_block()
974 * on the cc->migratepages list. in isolate_migratepages_block()
977 low_pfn += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
983 * Buddy and cannot be re-allocated because they are in isolate_migratepages_block()
984 * isolated. Fall-through as the check below handles in isolate_migratepages_block()
1004 low_pfn += (1UL << freepage_order) - 1; in isolate_migratepages_block()
1005 nr_scanned += (1UL << freepage_order) - 1; in isolate_migratepages_block()
1018 if (PageCompound(page) && !cc->alloc_contig) { in isolate_migratepages_block()
1022 low_pfn += (1UL << order) - 1; in isolate_migratepages_block()
1023 nr_scanned += (1UL << order) - 1; in isolate_migratepages_block()
1030 * It's possible to migrate LRU and non-lru movable pages. in isolate_migratepages_block()
1056 * sure the page is not being freed elsewhere -- the in isolate_migratepages_block()
1069 if (!mapping && (folio_ref_count(folio) - 1) > folio_mapcount(folio)) in isolate_migratepages_block()
1076 if (!(cc->gfp_mask & __GFP_FS) && mapping) in isolate_migratepages_block()
1092 * it will be able to migrate without blocking - clean pages in isolate_migratepages_block()
1107 * a ->migrate_folio callback are possible to migrate in isolate_migratepages_block()
1129 mapping->a_ops->migrate_folio; in isolate_migratepages_block()
1148 compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); in isolate_migratepages_block()
1161 !cc->finish_pageblock) { in isolate_migratepages_block()
1168 * folio become large since the non-locked check, in isolate_migratepages_block()
1171 if (unlikely(folio_test_large(folio) && !cc->alloc_contig)) { in isolate_migratepages_block()
1172 low_pfn += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1173 nr_scanned += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1181 low_pfn += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1190 list_add(&folio->lru, &cc->migratepages); in isolate_migratepages_block()
1192 cc->nr_migratepages += folio_nr_pages(folio); in isolate_migratepages_block()
1194 nr_scanned += folio_nr_pages(folio) - 1; in isolate_migratepages_block()
1202 if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX && in isolate_migratepages_block()
1203 !cc->finish_pageblock && !cc->contended) { in isolate_migratepages_block()
1219 if (!skip_on_failure && ret != -ENOMEM) in isolate_migratepages_block()
1224 * instead of migrating, as we cannot form the cc->order buddy in isolate_migratepages_block()
1232 putback_movable_pages(&cc->migratepages); in isolate_migratepages_block()
1233 cc->nr_migratepages = 0; in isolate_migratepages_block()
1238 low_pfn = next_skip_pfn - 1; in isolate_migratepages_block()
1243 next_skip_pfn += 1UL << cc->order; in isolate_migratepages_block()
1246 if (ret == -ENOMEM) in isolate_migratepages_block()
1273 * rescanned twice in a row. in isolate_migratepages_block()
1275 if (low_pfn == end_pfn && (!nr_isolated || cc->finish_pageblock)) { in isolate_migratepages_block()
1276 if (!cc->no_set_skip_hint && valid_page && !skip_updated) in isolate_migratepages_block()
1285 cc->total_migrate_scanned += nr_scanned; in isolate_migratepages_block()
1289 cc->migrate_pfn = low_pfn; in isolate_migratepages_block()
1295 * isolate_migratepages_range() - isolate migrate-able pages in a PFN range
1298 * @end_pfn: The one-past-last PFN.
1300 * Returns -EAGAIN when contented, -EINTR in case of a signal pending, -ENOMEM
1313 if (block_start_pfn < cc->zone->zone_start_pfn) in isolate_migratepages_range()
1314 block_start_pfn = cc->zone->zone_start_pfn; in isolate_migratepages_range()
1324 block_end_pfn, cc->zone)) in isolate_migratepages_range()
1333 if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX) in isolate_migratepages_range()
1351 if ((cc->mode != MIGRATE_ASYNC) || !cc->direct_compaction) in suitable_migration_source()
1356 if (cc->migratetype == MIGRATE_MOVABLE) in suitable_migration_source()
1359 return block_mt == cc->migratetype; in suitable_migration_source()
1369 * We are checking page_order without zone->lock taken. But in suitable_migration_target()
1377 if (cc->ignore_block_suitable) in suitable_migration_target()
1391 unsigned short shift = BITS_PER_LONG - 1; in freelist_scan_limit()
1393 return (COMPACT_CLUSTER_MAX >> min(shift, cc->fast_search_fail)) + 1; in freelist_scan_limit()
1402 return (cc->free_pfn >> pageblock_order) in compact_scanners_met()
1403 <= (cc->migrate_pfn >> pageblock_order); in compact_scanners_met()
1416 if (!list_is_first(&freepage->buddy_list, freelist)) { in move_freelist_head()
1417 list_cut_before(&sublist, freelist, &freepage->buddy_list); in move_freelist_head()
1433 if (!list_is_last(&freepage->buddy_list, freelist)) { in move_freelist_tail()
1434 list_cut_position(&sublist, freelist, &freepage->buddy_list); in move_freelist_tail()
1446 if (cc->nr_freepages >= cc->nr_migratepages) in fast_isolate_around()
1450 if (cc->direct_compaction && cc->mode == MIGRATE_ASYNC) in fast_isolate_around()
1454 start_pfn = max(pageblock_start_pfn(pfn), cc->zone->zone_start_pfn); in fast_isolate_around()
1455 end_pfn = min(pageblock_end_pfn(pfn), zone_end_pfn(cc->zone)); in fast_isolate_around()
1457 page = pageblock_pfn_to_page(start_pfn, end_pfn, cc->zone); in fast_isolate_around()
1461 isolate_freepages_block(cc, &start_pfn, end_pfn, &cc->freepages, 1, false); in fast_isolate_around()
1464 if (start_pfn == end_pfn && !cc->no_set_skip_hint) in fast_isolate_around()
1468 /* Search orders in round-robin fashion */
1471 order--; in next_search_order()
1473 order = cc->order - 1; in next_search_order()
1476 if (order == cc->search_order) { in next_search_order()
1477 cc->search_order--; in next_search_order()
1478 if (cc->search_order < 0) in next_search_order()
1479 cc->search_order = cc->order - 1; in next_search_order()
1480 return -1; in next_search_order()
1498 if (cc->order <= 0) in fast_isolate_freepages()
1505 if (cc->free_pfn >= cc->zone->compact_init_free_pfn) { in fast_isolate_freepages()
1514 distance = (cc->free_pfn - cc->migrate_pfn); in fast_isolate_freepages()
1515 low_pfn = pageblock_start_pfn(cc->free_pfn - (distance >> 2)); in fast_isolate_freepages()
1516 min_pfn = pageblock_start_pfn(cc->free_pfn - (distance >> 1)); in fast_isolate_freepages()
1525 cc->search_order = min_t(unsigned int, cc->order - 1, cc->search_order); in fast_isolate_freepages()
1527 for (order = cc->search_order; in fast_isolate_freepages()
1530 struct free_area *area = &cc->zone->free_area[order]; in fast_isolate_freepages()
1537 if (!area->nr_free) in fast_isolate_freepages()
1540 spin_lock_irqsave(&cc->zone->lock, flags); in fast_isolate_freepages()
1541 freelist = &area->free_list[MIGRATE_MOVABLE]; in fast_isolate_freepages()
1551 cc->zone->zone_start_pfn); in fast_isolate_freepages()
1554 cc->fast_search_fail = 0; in fast_isolate_freepages()
1555 cc->search_order = order; in fast_isolate_freepages()
1587 nr_scanned += nr_isolated - 1; in fast_isolate_freepages()
1589 cc->nr_freepages += nr_isolated; in fast_isolate_freepages()
1590 list_add_tail(&page->lru, &cc->freepages); in fast_isolate_freepages()
1594 order = cc->search_order + 1; in fast_isolate_freepages()
1599 spin_unlock_irqrestore(&cc->zone->lock, flags); in fast_isolate_freepages()
1602 if (cc->nr_freepages >= cc->nr_migratepages) in fast_isolate_freepages()
1613 trace_mm_compaction_fast_isolate_freepages(min_pfn, cc->free_pfn, in fast_isolate_freepages()
1617 cc->fast_search_fail++; in fast_isolate_freepages()
1626 cc->free_pfn = highest; in fast_isolate_freepages()
1628 if (cc->direct_compaction && pfn_valid(min_pfn)) { in fast_isolate_freepages()
1631 zone_end_pfn(cc->zone)), in fast_isolate_freepages()
1632 cc->zone); in fast_isolate_freepages()
1636 cc->free_pfn = min_pfn; in fast_isolate_freepages()
1642 if (highest && highest >= cc->zone->compact_cached_free_pfn) { in fast_isolate_freepages()
1643 highest -= pageblock_nr_pages; in fast_isolate_freepages()
1644 cc->zone->compact_cached_free_pfn = highest; in fast_isolate_freepages()
1647 cc->total_free_scanned += nr_scanned; in fast_isolate_freepages()
1661 struct zone *zone = cc->zone; in isolate_freepages()
1667 struct list_head *freelist = &cc->freepages; in isolate_freepages()
1668 unsigned int stride; in isolate_freepages() local
1672 if (cc->nr_freepages) in isolate_freepages()
1677 * successfully isolated from, zone-cached value, or the end of the in isolate_freepages()
1680 * block_start_pfn -= pageblock_nr_pages in the for loop. in isolate_freepages()
1686 isolate_start_pfn = cc->free_pfn; in isolate_freepages()
1690 low_pfn = pageblock_end_pfn(cc->migrate_pfn); in isolate_freepages()
1691 stride = cc->mode == MIGRATE_ASYNC ? COMPACT_CLUSTER_MAX : 1; in isolate_freepages()
1695 * pages on cc->migratepages. We stop searching if the migrate in isolate_freepages()
1700 block_start_pfn -= pageblock_nr_pages, in isolate_freepages()
1733 block_end_pfn, freelist, stride, false); in isolate_freepages()
1737 update_pageblock_skip(cc, page, block_start_pfn - in isolate_freepages()
1741 if (cc->nr_freepages >= cc->nr_migratepages) { in isolate_freepages()
1748 block_start_pfn - pageblock_nr_pages; in isolate_freepages()
1759 /* Adjust stride depending on isolation */ in isolate_freepages()
1761 stride = 1; in isolate_freepages()
1764 stride = min_t(unsigned int, COMPACT_CLUSTER_MAX, stride << 1); in isolate_freepages()
1773 cc->free_pfn = isolate_start_pfn; in isolate_freepages()
1781 * This is a migrate-callback that "allocates" freepages by taking pages
1789 if (list_empty(&cc->freepages)) { in compaction_alloc()
1792 if (list_empty(&cc->freepages)) in compaction_alloc()
1796 dst = list_entry(cc->freepages.next, struct folio, lru); in compaction_alloc()
1797 list_del(&dst->lru); in compaction_alloc()
1798 cc->nr_freepages--; in compaction_alloc()
1804 * This is a migrate-callback that "frees" freepages back to the isolated
1812 list_add(&dst->lru, &cc->freepages); in compaction_free()
1813 cc->nr_freepages++; in compaction_free()
1840 if (cc->fast_start_pfn == ULONG_MAX) in update_fast_start_pfn()
1843 if (!cc->fast_start_pfn) in update_fast_start_pfn()
1844 cc->fast_start_pfn = pfn; in update_fast_start_pfn()
1846 cc->fast_start_pfn = min(cc->fast_start_pfn, pfn); in update_fast_start_pfn()
1852 if (!cc->fast_start_pfn || cc->fast_start_pfn == ULONG_MAX) in reinit_migrate_pfn()
1853 return cc->migrate_pfn; in reinit_migrate_pfn()
1855 cc->migrate_pfn = cc->fast_start_pfn; in reinit_migrate_pfn()
1856 cc->fast_start_pfn = ULONG_MAX; in reinit_migrate_pfn()
1858 return cc->migrate_pfn; in reinit_migrate_pfn()
1871 unsigned long pfn = cc->migrate_pfn; in fast_find_migrateblock()
1877 if (cc->ignore_skip_hint) in fast_find_migrateblock()
1884 if (cc->finish_pageblock) in fast_find_migrateblock()
1892 if (pfn != cc->zone->zone_start_pfn && pfn != pageblock_start_pfn(pfn)) in fast_find_migrateblock()
1900 if (cc->order <= PAGE_ALLOC_COSTLY_ORDER) in fast_find_migrateblock()
1909 if (cc->direct_compaction && cc->migratetype != MIGRATE_MOVABLE) in fast_find_migrateblock()
1918 distance = (cc->free_pfn - cc->migrate_pfn) >> 1; in fast_find_migrateblock()
1919 if (cc->migrate_pfn != cc->zone->zone_start_pfn) in fast_find_migrateblock()
1921 high_pfn = pageblock_start_pfn(cc->migrate_pfn + distance); in fast_find_migrateblock()
1923 for (order = cc->order - 1; in fast_find_migrateblock()
1925 order--) { in fast_find_migrateblock()
1926 struct free_area *area = &cc->zone->free_area[order]; in fast_find_migrateblock()
1931 if (!area->nr_free) in fast_find_migrateblock()
1934 spin_lock_irqsave(&cc->zone->lock, flags); in fast_find_migrateblock()
1935 freelist = &area->free_list[MIGRATE_MOVABLE]; in fast_find_migrateblock()
1960 if (pfn < cc->zone->zone_start_pfn) in fast_find_migrateblock()
1961 pfn = cc->zone->zone_start_pfn; in fast_find_migrateblock()
1962 cc->fast_search_fail = 0; in fast_find_migrateblock()
1967 spin_unlock_irqrestore(&cc->zone->lock, flags); in fast_find_migrateblock()
1970 cc->total_migrate_scanned += nr_scanned; in fast_find_migrateblock()
1977 cc->fast_search_fail++; in fast_find_migrateblock()
1996 (cc->mode != MIGRATE_SYNC ? ISOLATE_ASYNC_MIGRATE : 0); in isolate_migratepages()
2006 if (block_start_pfn < cc->zone->zone_start_pfn) in isolate_migratepages()
2007 block_start_pfn = cc->zone->zone_start_pfn; in isolate_migratepages()
2014 fast_find_block = low_pfn != cc->migrate_pfn && !cc->fast_search_fail; in isolate_migratepages()
2023 for (; block_end_pfn <= cc->free_pfn; in isolate_migratepages()
2025 cc->migrate_pfn = low_pfn = block_end_pfn, in isolate_migratepages()
2038 block_end_pfn, cc->zone); in isolate_migratepages()
2044 block_end_pfn = min(next_pfn, cc->free_pfn); in isolate_migratepages()
2056 low_pfn == cc->zone->zone_start_pfn) && in isolate_migratepages()
2086 return cc->nr_migratepages ? ISOLATE_SUCCESS : ISOLATE_NONE; in isolate_migratepages()
2090 * order == -1 is expected when compacting proactively via
2097 return order == -1; in is_via_compact_memory()
2103 * pgdat_kswapd_lock() pins pgdat->kswapd, so a concurrent kswapd_stop() can't
2111 running = pgdat->kswapd && task_is_running(pgdat->kswapd); in kswapd_is_running()
2140 score = zone->present_pages * fragmentation_score_zone(zone); in fragmentation_score_zone_weighted()
2141 return div64_ul(score, zone->zone_pgdat->node_present_pages + 1); in fragmentation_score_zone_weighted()
2145 * The per-node proactive (background) compaction process is started by its
2148 * the node's score falls below the low threshold, or one of the back-off
2159 zone = &pgdat->node_zones[zoneid]; in fragmentation_score_node()
2177 wmark_low = max(100U - sysctl_compaction_proactiveness, 5U); in fragmentation_score_wmark()
2195 const int migratetype = cc->migratetype; in __compact_finished()
2201 reset_cached_positions(cc->zone); in __compact_finished()
2209 if (cc->direct_compaction) in __compact_finished()
2210 cc->zone->compact_blockskip_flush = true; in __compact_finished()
2212 if (cc->whole_zone) in __compact_finished()
2218 if (cc->proactive_compaction) { in __compact_finished()
2222 pgdat = cc->zone->zone_pgdat; in __compact_finished()
2226 score = fragmentation_score_zone(cc->zone); in __compact_finished()
2237 if (is_via_compact_memory(cc->order)) in __compact_finished()
2246 if (!pageblock_aligned(cc->migrate_pfn)) in __compact_finished()
2251 for (order = cc->order; order < NR_PAGE_ORDERS; order++) { in __compact_finished()
2252 struct free_area *area = &cc->zone->free_area[order]; in __compact_finished()
2270 true, &can_steal) != -1) in __compact_finished()
2273 * stealing for a non-movable allocation, make sure in __compact_finished()
2283 if (cc->contended || fatal_signal_pending(current)) in __compact_finished()
2294 trace_mm_compaction_finished(cc->zone, cc->order, ret); in compact_finished()
2307 * Watermarks for order-0 must be met for compaction to be able to in __compaction_suitable()
2341 * index of -1000 would imply allocations might succeed depending on in compaction_suitable()
2342 * watermarks, but we already failed the high-order watermark check in compaction_suitable()
2347 * ignore fragindex for non-costly orders where the alternative to in compaction_suitable()
2383 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in compaction_zonelist_suitable()
2384 ac->highest_zoneidx, ac->nodemask) { in compaction_zonelist_suitable()
2395 if (__compaction_suitable(zone, order, ac->highest_zoneidx, in compaction_zonelist_suitable()
2431 unsigned long start_pfn = cc->zone->zone_start_pfn; in compact_zone()
2432 unsigned long end_pfn = zone_end_pfn(cc->zone); in compact_zone()
2434 const bool sync = cc->mode != MIGRATE_ASYNC; in compact_zone()
2442 cc->total_migrate_scanned = 0; in compact_zone()
2443 cc->total_free_scanned = 0; in compact_zone()
2444 cc->nr_migratepages = 0; in compact_zone()
2445 cc->nr_freepages = 0; in compact_zone()
2446 INIT_LIST_HEAD(&cc->freepages); in compact_zone()
2447 INIT_LIST_HEAD(&cc->migratepages); in compact_zone()
2449 cc->migratetype = gfp_migratetype(cc->gfp_mask); in compact_zone()
2451 if (!is_via_compact_memory(cc->order)) { in compact_zone()
2452 ret = compaction_suit_allocation_order(cc->zone, cc->order, in compact_zone()
2453 cc->highest_zoneidx, in compact_zone()
2454 cc->alloc_flags); in compact_zone()
2463 if (compaction_restarting(cc->zone, cc->order)) in compact_zone()
2464 __reset_isolation_suitable(cc->zone); in compact_zone()
2472 cc->fast_start_pfn = 0; in compact_zone()
2473 if (cc->whole_zone) { in compact_zone()
2474 cc->migrate_pfn = start_pfn; in compact_zone()
2475 cc->free_pfn = pageblock_start_pfn(end_pfn - 1); in compact_zone()
2477 cc->migrate_pfn = cc->zone->compact_cached_migrate_pfn[sync]; in compact_zone()
2478 cc->free_pfn = cc->zone->compact_cached_free_pfn; in compact_zone()
2479 if (cc->free_pfn < start_pfn || cc->free_pfn >= end_pfn) { in compact_zone()
2480 cc->free_pfn = pageblock_start_pfn(end_pfn - 1); in compact_zone()
2481 cc->zone->compact_cached_free_pfn = cc->free_pfn; in compact_zone()
2483 if (cc->migrate_pfn < start_pfn || cc->migrate_pfn >= end_pfn) { in compact_zone()
2484 cc->migrate_pfn = start_pfn; in compact_zone()
2485 cc->zone->compact_cached_migrate_pfn[0] = cc->migrate_pfn; in compact_zone()
2486 cc->zone->compact_cached_migrate_pfn[1] = cc->migrate_pfn; in compact_zone()
2489 if (cc->migrate_pfn <= cc->zone->compact_init_migrate_pfn) in compact_zone()
2490 cc->whole_zone = true; in compact_zone()
2504 cc->zone->compact_cached_migrate_pfn[0] == cc->zone->compact_cached_migrate_pfn[1]; in compact_zone()
2513 unsigned long iteration_start_pfn = cc->migrate_pfn; in compact_zone()
2523 cc->finish_pageblock = false; in compact_zone()
2526 cc->finish_pageblock = true; in compact_zone()
2533 putback_movable_pages(&cc->migratepages); in compact_zone()
2534 cc->nr_migratepages = 0; in compact_zone()
2538 cc->zone->compact_cached_migrate_pfn[1] = in compact_zone()
2539 cc->zone->compact_cached_migrate_pfn[0]; in compact_zone()
2545 * previous cc->order aligned block. in compact_zone()
2550 last_migrated_pfn = max(cc->zone->zone_start_pfn, in compact_zone()
2551 pageblock_start_pfn(cc->migrate_pfn - 1)); in compact_zone()
2554 err = migrate_pages(&cc->migratepages, compaction_alloc, in compact_zone()
2555 compaction_free, (unsigned long)cc, cc->mode, in compact_zone()
2561 cc->nr_migratepages = 0; in compact_zone()
2563 putback_movable_pages(&cc->migratepages); in compact_zone()
2565 * migrate_pages() may return -ENOMEM when scanners meet in compact_zone()
2568 if (err == -ENOMEM && !compact_scanners_met(cc)) { in compact_zone()
2574 * within the pageblock_order-aligned block and in compact_zone()
2583 if (!pageblock_aligned(cc->migrate_pfn) && in compact_zone()
2584 !cc->ignore_skip_hint && !cc->finish_pageblock && in compact_zone()
2585 (cc->mode < MIGRATE_SYNC)) { in compact_zone()
2586 cc->finish_pageblock = true; in compact_zone()
2593 if (cc->order == COMPACTION_HPAGE_ORDER) in compact_zone()
2601 if (capc && capc->page) { in compact_zone()
2609 * cc->order aligned block where we migrated from? If yes, in compact_zone()
2614 if (cc->order > 0 && last_migrated_pfn) { in compact_zone()
2616 block_start_pfn(cc->migrate_pfn, cc->order); in compact_zone()
2619 lru_add_drain_cpu_zone(cc->zone); in compact_zone()
2631 if (cc->nr_freepages > 0) { in compact_zone()
2632 unsigned long free_pfn = release_freepages(&cc->freepages); in compact_zone()
2634 cc->nr_freepages = 0; in compact_zone()
2642 if (free_pfn > cc->zone->compact_cached_free_pfn) in compact_zone()
2643 cc->zone->compact_cached_free_pfn = free_pfn; in compact_zone()
2646 count_compact_events(COMPACTMIGRATE_SCANNED, cc->total_migrate_scanned); in compact_zone()
2647 count_compact_events(COMPACTFREE_SCANNED, cc->total_free_scanned); in compact_zone()
2651 VM_BUG_ON(!list_empty(&cc->freepages)); in compact_zone()
2652 VM_BUG_ON(!list_empty(&cc->migratepages)); in compact_zone()
2688 WRITE_ONCE(current->capture_control, &capc); in compact_zone_order()
2697 WRITE_ONCE(current->capture_control, NULL); in compact_zone_order()
2712 * try_to_compact_pages - Direct compact to satisfy a high-order allocation
2736 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in try_to_compact_pages()
2737 ac->highest_zoneidx, ac->nodemask) { in try_to_compact_pages()
2747 alloc_flags, ac->highest_zoneidx, capture); in try_to_compact_pages()
2791 * due to various back-off conditions, such as, contention on per-node or
2792 * per-zone locks.
2799 .order = -1, in proactive_compact_node()
2808 zone = &pgdat->node_zones[zoneid]; in proactive_compact_node()
2830 .order = -1, in compact_node()
2840 zone = &pgdat->node_zones[zoneid]; in compact_node()
2875 if (pgdat->proactive_compact_trigger) in compaction_proactiveness_sysctl_handler()
2878 pgdat->proactive_compact_trigger = true; in compaction_proactiveness_sysctl_handler()
2879 trace_mm_compaction_wakeup_kcompactd(pgdat->node_id, -1, in compaction_proactiveness_sysctl_handler()
2880 pgdat->nr_zones - 1); in compaction_proactiveness_sysctl_handler()
2881 wake_up_interruptible(&pgdat->kcompactd_wait); in compaction_proactiveness_sysctl_handler()
2902 return -EINVAL; in sysctl_compaction_handler()
2915 int nid = dev->id; in compact_store()
2930 return device_create_file(&node->dev, &dev_attr_compact); in compaction_register_node()
2935 device_remove_file(&node->dev, &dev_attr_compact); in compaction_unregister_node()
2941 return pgdat->kcompactd_max_order > 0 || kthread_should_stop() || in kcompactd_work_requested()
2942 pgdat->proactive_compact_trigger; in kcompactd_work_requested()
2949 enum zone_type highest_zoneidx = pgdat->kcompactd_highest_zoneidx; in kcompactd_node_suitable()
2953 zone = &pgdat->node_zones[zoneid]; in kcompactd_node_suitable()
2959 pgdat->kcompactd_max_order, in kcompactd_node_suitable()
2977 .order = pgdat->kcompactd_max_order, in kcompactd_do_work()
2978 .search_order = pgdat->kcompactd_max_order, in kcompactd_do_work()
2979 .highest_zoneidx = pgdat->kcompactd_highest_zoneidx, in kcompactd_do_work()
2986 trace_mm_compaction_kcompactd_wake(pgdat->node_id, cc.order, in kcompactd_do_work()
2993 zone = &pgdat->node_zones[zoneid]; in kcompactd_do_work()
3040 if (pgdat->kcompactd_max_order <= cc.order) in kcompactd_do_work()
3041 pgdat->kcompactd_max_order = 0; in kcompactd_do_work()
3042 if (pgdat->kcompactd_highest_zoneidx >= cc.highest_zoneidx) in kcompactd_do_work()
3043 pgdat->kcompactd_highest_zoneidx = pgdat->nr_zones - 1; in kcompactd_do_work()
3051 if (pgdat->kcompactd_max_order < order) in wakeup_kcompactd()
3052 pgdat->kcompactd_max_order = order; in wakeup_kcompactd()
3054 if (pgdat->kcompactd_highest_zoneidx > highest_zoneidx) in wakeup_kcompactd()
3055 pgdat->kcompactd_highest_zoneidx = highest_zoneidx; in wakeup_kcompactd()
3061 if (!wq_has_sleeper(&pgdat->kcompactd_wait)) in wakeup_kcompactd()
3067 trace_mm_compaction_wakeup_kcompactd(pgdat->node_id, order, in wakeup_kcompactd()
3069 wake_up_interruptible(&pgdat->kcompactd_wait); in wakeup_kcompactd()
3083 const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id); in kcompactd()
3090 pgdat->kcompactd_max_order = 0; in kcompactd()
3091 pgdat->kcompactd_highest_zoneidx = pgdat->nr_zones - 1; in kcompactd()
3102 trace_mm_compaction_kcompactd_sleep(pgdat->node_id); in kcompactd()
3103 if (wait_event_freezable_timeout(pgdat->kcompactd_wait, in kcompactd()
3105 !pgdat->proactive_compact_trigger) { in kcompactd()
3140 if (unlikely(pgdat->proactive_compact_trigger)) in kcompactd()
3141 pgdat->proactive_compact_trigger = false; in kcompactd()
3148 * This kcompactd start function will be called by init and node-hot-add.
3149 * On node-hot-add, kcompactd will moved to proper cpus if cpus are hot-added.
3155 if (pgdat->kcompactd) in kcompactd_run()
3158 pgdat->kcompactd = kthread_run(kcompactd, pgdat, "kcompactd%d", nid); in kcompactd_run()
3159 if (IS_ERR(pgdat->kcompactd)) { in kcompactd_run()
3161 pgdat->kcompactd = NULL; in kcompactd_run()
3171 struct task_struct *kcompactd = NODE_DATA(nid)->kcompactd; in kcompactd_stop()
3175 NODE_DATA(nid)->kcompactd = NULL; in kcompactd_stop()
3193 mask = cpumask_of_node(pgdat->node_id); in kcompactd_cpu_online()
3197 if (pgdat->kcompactd) in kcompactd_cpu_online()
3198 set_cpus_allowed_ptr(pgdat->kcompactd, mask); in kcompactd_cpu_online()
3211 old = *(int *)table->data; in proc_dointvec_minmax_warn_RT_change()
3215 if (old != *(int *)table->data) in proc_dointvec_minmax_warn_RT_change()
3217 table->procname, current->comm, in proc_dointvec_minmax_warn_RT_change()