Lines Matching full:order

214 static void __free_pages_ok(struct page *page, unsigned int order,
288 static bool page_contains_unaccepted(struct page *page, unsigned int order);
289 static bool cond_accept_memory(struct zone *zone, unsigned int order);
314 _deferred_grow_zone(struct zone *zone, unsigned int order) in _deferred_grow_zone() argument
316 return deferred_grow_zone(zone, order); in _deferred_grow_zone()
324 static inline bool _deferred_grow_zone(struct zone *zone, unsigned int order) in _deferred_grow_zone() argument
509 static inline unsigned int order_to_pindex(int migratetype, int order) in order_to_pindex() argument
514 if (order > PAGE_ALLOC_COSTLY_ORDER) { in order_to_pindex()
515 VM_BUG_ON(order != HPAGE_PMD_ORDER); in order_to_pindex()
522 VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); in order_to_pindex()
525 return (MIGRATE_PCPTYPES * order) + migratetype; in order_to_pindex()
530 int order = pindex / MIGRATE_PCPTYPES; in pindex_to_order() local
534 order = HPAGE_PMD_ORDER; in pindex_to_order()
536 VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); in pindex_to_order()
539 return order; in pindex_to_order()
542 static inline bool pcp_allowed_order(unsigned int order) in pcp_allowed_order() argument
544 if (order <= PAGE_ALLOC_COSTLY_ORDER) in pcp_allowed_order()
547 if (order == HPAGE_PMD_ORDER) in pcp_allowed_order()
554 * Higher-order pages are called "compound pages". They are structured thusly:
561 * The first tail page's ->compound_order holds the order of allocation.
562 * This usage means that zero-order pages may not be compound.
565 void prep_compound_page(struct page *page, unsigned int order) in prep_compound_page() argument
568 int nr_pages = 1 << order; in prep_compound_page()
574 prep_compound_head(page, order); in prep_compound_page()
577 static inline void set_buddy_order(struct page *page, unsigned int order) in set_buddy_order() argument
579 set_page_private(page, order); in set_buddy_order()
596 int order, int migratetype) in compaction_capture() argument
598 if (!capc || order != capc->cc->order) in compaction_capture()
607 * Do not let lower order allocations pollute a movable pageblock in compaction_capture()
611 * have trouble finding a high-order free page. in compaction_capture()
613 if (order < pageblock_order && migratetype == MIGRATE_MOVABLE && in compaction_capture()
629 int order, int migratetype) in compaction_capture() argument
654 unsigned int order, int migratetype, in __add_to_free_list() argument
657 struct free_area *area = &zone->free_area[order]; in __add_to_free_list()
661 get_pageblock_migratetype(page), migratetype, 1 << order); in __add_to_free_list()
676 unsigned int order, int old_mt, int new_mt) in move_to_free_list() argument
678 struct free_area *area = &zone->free_area[order]; in move_to_free_list()
683 get_pageblock_migratetype(page), old_mt, 1 << order); in move_to_free_list()
687 account_freepages(zone, -(1 << order), old_mt); in move_to_free_list()
688 account_freepages(zone, 1 << order, new_mt); in move_to_free_list()
692 unsigned int order, int migratetype) in __del_page_from_free_list() argument
696 get_pageblock_migratetype(page), migratetype, 1 << order); in __del_page_from_free_list()
705 zone->free_area[order].nr_free--; in __del_page_from_free_list()
709 unsigned int order, int migratetype) in del_page_from_free_list() argument
711 __del_page_from_free_list(page, zone, order, migratetype); in del_page_from_free_list()
712 account_freepages(zone, -(1 << order), migratetype); in del_page_from_free_list()
724 * of the next-higher order is free. If it is, it's possible
728 * as a 2-level higher order page
732 struct page *page, unsigned int order) in buddy_merge_likely() argument
737 if (order >= MAX_PAGE_ORDER - 1) in buddy_merge_likely()
743 return find_buddy_page_pfn(higher_page, higher_page_pfn, order + 1, in buddy_merge_likely()
760 * free pages of length of (1 << order) and marked with PageBuddy.
761 * Page's order is recorded in page_private(page) field.
773 struct zone *zone, unsigned int order, in __free_one_page() argument
786 VM_BUG_ON_PAGE(pfn & ((1 << order) - 1), page); in __free_one_page()
789 account_freepages(zone, 1 << order, migratetype); in __free_one_page()
791 while (order < MAX_PAGE_ORDER) { in __free_one_page()
794 if (compaction_capture(capc, page, order, migratetype)) { in __free_one_page()
795 account_freepages(zone, -(1 << order), migratetype); in __free_one_page()
799 buddy = find_buddy_page_pfn(page, pfn, order, &buddy_pfn); in __free_one_page()
803 if (unlikely(order >= pageblock_order)) { in __free_one_page()
820 * merge with it and move up one order. in __free_one_page()
823 clear_page_guard(zone, buddy, order); in __free_one_page()
825 __del_page_from_free_list(buddy, zone, order, buddy_mt); in __free_one_page()
839 order++; in __free_one_page()
843 set_buddy_order(page, order); in __free_one_page()
847 else if (is_shuffle_order(order)) in __free_one_page()
850 to_tail = buddy_merge_likely(pfn, buddy_pfn, page, order); in __free_one_page()
852 __add_to_free_list(page, zone, order, migratetype, to_tail); in __free_one_page()
856 page_reporting_notify_free(order); in __free_one_page()
1045 unsigned int order) in free_pages_prepare() argument
1055 trace_mm_page_free(page, order); in free_pages_prepare()
1056 kmsan_free_page(page, order); in free_pages_prepare()
1059 __memcg_kmem_uncharge_page(page, order); in free_pages_prepare()
1075 if (unlikely(PageHWPoison(page)) && !order) { in free_pages_prepare()
1077 reset_page_owner(page, order); in free_pages_prepare()
1078 page_table_check_free(page, order); in free_pages_prepare()
1079 pgalloc_tag_sub(page, 1 << order); in free_pages_prepare()
1090 VM_BUG_ON_PAGE(compound && compound_order(page) != order, page); in free_pages_prepare()
1094 * avoid checking PageCompound for order-0 pages. in free_pages_prepare()
1096 if (unlikely(order)) { in free_pages_prepare()
1101 for (i = 1; i < (1 << order); i++) { in free_pages_prepare()
1115 mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); in free_pages_prepare()
1127 reset_page_owner(page, order); in free_pages_prepare()
1128 page_table_check_free(page, order); in free_pages_prepare()
1129 pgalloc_tag_sub(page, 1 << order); in free_pages_prepare()
1133 PAGE_SIZE << order); in free_pages_prepare()
1135 PAGE_SIZE << order); in free_pages_prepare()
1138 kernel_poison_pages(page, 1 << order); in free_pages_prepare()
1149 kasan_poison_pages(page, order, init); in free_pages_prepare()
1156 kernel_init_pages(page, 1 << order); in free_pages_prepare()
1163 arch_free_page(page, order); in free_pages_prepare()
1165 debug_pagealloc_unmap_pages(page, 1 << order); in free_pages_prepare()
1180 unsigned int order; in free_pcppages_bulk() local
1205 order = pindex_to_order(pindex); in free_pcppages_bulk()
1206 nr_pages = 1 << order; in free_pcppages_bulk()
1220 __free_one_page(page, pfn, zone, order, mt, FPI_NONE); in free_pcppages_bulk()
1221 trace_mm_page_pcpu_drain(page, order, mt); in free_pcppages_bulk()
1230 unsigned long pfn, int order, fpi_t fpi) in split_large_buddy() argument
1232 unsigned long end = pfn + (1 << order); in split_large_buddy()
1234 VM_WARN_ON_ONCE(!IS_ALIGNED(pfn, 1 << order)); in split_large_buddy()
1238 if (order > pageblock_order) in split_large_buddy()
1239 order = pageblock_order; in split_large_buddy()
1244 __free_one_page(page, pfn, zone, order, mt, fpi); in split_large_buddy()
1245 pfn += 1 << order; in split_large_buddy()
1253 unsigned long pfn, unsigned int order, in free_one_page() argument
1259 split_large_buddy(zone, page, pfn, order, fpi_flags); in free_one_page()
1262 __count_vm_events(PGFREE, 1 << order); in free_one_page()
1265 static void __free_pages_ok(struct page *page, unsigned int order, in __free_pages_ok() argument
1271 if (free_pages_prepare(page, order)) in __free_pages_ok()
1272 free_one_page(zone, page, pfn, order, fpi_flags); in __free_pages_ok()
1275 void __meminit __free_pages_core(struct page *page, unsigned int order, in __free_pages_core() argument
1278 unsigned int nr_pages = 1 << order; in __free_pages_core()
1315 if (page_contains_unaccepted(page, order)) { in __free_pages_core()
1316 if (order == MAX_PAGE_ORDER && __free_unaccepted(page)) in __free_pages_core()
1319 accept_memory(page_to_phys(page), PAGE_SIZE << order); in __free_pages_core()
1326 __free_pages_ok(page, order, FPI_TO_TAIL); in __free_pages_core()
1346 * of the pfn range). For example, if the pageblock order is MAX_PAGE_ORDER, which
1382 * The order of subdivision here is critical for the IO subsystem.
1383 * Please do not alter this order without good reasons and regression
1385 * the order in which smaller blocks are delivered depends on the order
1387 * influencing the order in which pages are delivered to the IO
1460 static inline bool check_new_pages(struct page *page, unsigned int order) in check_new_pages() argument
1463 for (int i = 0; i < (1 << order); i++) { in check_new_pages()
1502 inline void post_alloc_hook(struct page *page, unsigned int order, in post_alloc_hook() argument
1513 arch_alloc_page(page, order); in post_alloc_hook()
1514 debug_pagealloc_map_pages(page, 1 << order); in post_alloc_hook()
1521 kernel_unpoison_pages(page, 1 << order); in post_alloc_hook()
1535 for (i = 0; i != 1 << order; ++i) in post_alloc_hook()
1542 kasan_unpoison_pages(page, order, init)) { in post_alloc_hook()
1551 for (i = 0; i != 1 << order; ++i) in post_alloc_hook()
1556 kernel_init_pages(page, 1 << order); in post_alloc_hook()
1558 set_page_owner(page, order, gfp_flags); in post_alloc_hook()
1559 page_table_check_alloc(page, order); in post_alloc_hook()
1560 pgalloc_tag_add(page, current, 1 << order); in post_alloc_hook()
1563 static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags, in prep_new_page() argument
1566 post_alloc_hook(page, order, gfp_flags); in prep_new_page()
1568 if (order && (gfp_flags & __GFP_COMP)) in prep_new_page()
1569 prep_compound_page(page, order); in prep_new_page()
1588 struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, in __rmqueue_smallest() argument
1596 for (current_order = order; current_order < NR_PAGE_ORDERS; ++current_order) { in __rmqueue_smallest()
1602 page_del_and_expand(zone, page, order, current_order, in __rmqueue_smallest()
1604 trace_mm_page_alloc_zone_locked(page, order, migratetype, in __rmqueue_smallest()
1605 pcp_allowed_order(order) && in __rmqueue_smallest()
1615 * This array describes the order lists are fallen back to when
1628 unsigned int order) in __rmqueue_cma_fallback() argument
1630 return __rmqueue_smallest(zone, order, MIGRATE_CMA); in __rmqueue_cma_fallback()
1634 unsigned int order) { return NULL; } in __rmqueue_cma_fallback() argument
1646 unsigned int order; in __move_freepages_block() local
1663 order = buddy_order(page); in __move_freepages_block()
1665 move_to_free_list(page, zone, order, old_mt, new_mt); in __move_freepages_block()
1667 pfn += 1 << order; in __move_freepages_block()
1668 pages_moved += 1 << order; in __move_freepages_block()
1741 int order = 0; in find_large_buddy() local
1747 if (++order > MAX_PAGE_ORDER) in find_large_buddy()
1749 pfn &= ~0UL << order; in find_large_buddy()
1797 int order = buddy_order(buddy); in move_freepages_block_isolate() local
1799 del_page_from_free_list(buddy, zone, order, in move_freepages_block_isolate()
1802 split_large_buddy(zone, buddy, pfn, order, FPI_NONE); in move_freepages_block_isolate()
1808 int order = buddy_order(page); in move_freepages_block_isolate() local
1810 del_page_from_free_list(page, zone, order, in move_freepages_block_isolate()
1813 split_large_buddy(zone, page, pfn, order, FPI_NONE); in move_freepages_block_isolate()
1847 static bool can_steal_fallback(unsigned int order, int start_mt) in can_steal_fallback() argument
1850 * Leaving this order check is intended, although there is in can_steal_fallback()
1851 * relaxed order check in next check. The reason is that in can_steal_fallback()
1856 if (order >= pageblock_order) in can_steal_fallback()
1859 if (order >= pageblock_order / 2 || in can_steal_fallback()
1906 * This function implements actual steal behaviour. If order is large enough, we
1911 * the order we need from the fallback block and leave its migratetype alone.
1915 int current_order, int order, int start_type, in steal_suitable_fallback() argument
1937 nr_added = expand(zone, page, order, current_order, start_type); in steal_suitable_fallback()
1987 return __rmqueue_smallest(zone, order, start_type); in steal_suitable_fallback()
1991 page_del_and_expand(zone, page, order, current_order, block_type); in steal_suitable_fallback()
1996 * Check whether there is a suitable fallback freepage with requested order.
2001 int find_suitable_fallback(struct free_area *area, unsigned int order, in find_suitable_fallback() argument
2016 if (can_steal_fallback(order, migratetype)) in find_suitable_fallback()
2031 * exclusive use of high-order atomic allocations if there are no
2032 * empty page blocks that contain a page with a suitable order
2034 static void reserve_highatomic_pageblock(struct page *page, int order, in reserve_highatomic_pageblock() argument
2064 if (order < pageblock_order) { in reserve_highatomic_pageblock()
2069 change_pageblock_range(page, order, MIGRATE_HIGHATOMIC); in reserve_highatomic_pageblock()
2070 zone->nr_reserved_highatomic += 1 << order; in reserve_highatomic_pageblock()
2079 * potentially hurts the reliability of high-order allocations when under
2094 int order; in unreserve_highatomic_pageblock() local
2108 for (order = 0; order < NR_PAGE_ORDERS; order++) { in unreserve_highatomic_pageblock()
2109 struct free_area *area = &(zone->free_area[order]); in unreserve_highatomic_pageblock()
2133 size = max(pageblock_nr_pages, 1UL << order); in unreserve_highatomic_pageblock()
2147 if (order < pageblock_order) in unreserve_highatomic_pageblock()
2151 move_to_free_list(page, zone, order, mt, in unreserve_highatomic_pageblock()
2153 change_pageblock_range(page, order, in unreserve_highatomic_pageblock()
2179 * The use of signed ints for order and current_order is a deliberate
2184 __rmqueue_fallback(struct zone *zone, int order, int start_migratetype, in __rmqueue_fallback() argument
2189 int min_order = order; in __rmqueue_fallback()
2199 if (order < pageblock_order && alloc_flags & ALLOC_NOFRAGMENT) in __rmqueue_fallback()
2224 && current_order > order) in __rmqueue_fallback()
2233 for (current_order = order; current_order < NR_PAGE_ORDERS; current_order++) { in __rmqueue_fallback()
2251 page = steal_suitable_fallback(zone, page, current_order, order, in __rmqueue_fallback()
2254 trace_mm_page_alloc_extfrag(page, order, current_order, in __rmqueue_fallback()
2265 __rmqueue(struct zone *zone, unsigned int order, int migratetype, in __rmqueue() argument
2279 page = __rmqueue_cma_fallback(zone, order); in __rmqueue()
2285 page = __rmqueue_smallest(zone, order, migratetype); in __rmqueue()
2288 page = __rmqueue_cma_fallback(zone, order); in __rmqueue()
2291 page = __rmqueue_fallback(zone, order, migratetype, in __rmqueue()
2302 static int rmqueue_bulk(struct zone *zone, unsigned int order, in rmqueue_bulk() argument
2311 struct page *page = __rmqueue(zone, order, migratetype, in rmqueue_bulk()
2318 * physical page order. The page is added to the tail of in rmqueue_bulk()
2322 * head, thus also in the physical page order. This is useful in rmqueue_bulk()
2526 /* Free as much as possible if batch freeing high-order pages. */ in nr_pcp_free()
2597 unsigned int order) in free_unref_page_commit() argument
2609 __count_vm_events(PGFREE, 1 << order); in free_unref_page_commit()
2610 pindex = order_to_pindex(migratetype, order); in free_unref_page_commit()
2612 pcp->count += 1 << order; in free_unref_page_commit()
2616 * As high-order pages other than THP's stored on PCP can contribute in free_unref_page_commit()
2621 if (order && order <= PAGE_ALLOC_COSTLY_ORDER) { in free_unref_page_commit()
2631 pcp->free_count += (1 << order); in free_unref_page_commit()
2646 void free_unref_page(struct page *page, unsigned int order) in free_unref_page() argument
2654 if (!pcp_allowed_order(order)) { in free_unref_page()
2655 __free_pages_ok(page, order, FPI_NONE); in free_unref_page()
2659 if (!free_pages_prepare(page, order)) in free_unref_page()
2672 free_one_page(page_zone(page), page, pfn, order, FPI_NONE); in free_unref_page()
2682 free_unref_page_commit(zone, pcp, page, migratetype, order); in free_unref_page()
2685 free_one_page(zone, page, pfn, order, FPI_NONE); in free_unref_page()
2704 unsigned int order = folio_order(folio); in free_unref_folios() local
2706 if (!free_pages_prepare(&folio->page, order)) in free_unref_folios()
2712 if (!pcp_allowed_order(order)) { in free_unref_folios()
2714 pfn, order, FPI_NONE); in free_unref_folios()
2717 folio->private = (void *)(unsigned long)order; in free_unref_folios()
2728 unsigned int order = (unsigned long)folio->private; in free_unref_folios() local
2750 order, FPI_NONE); in free_unref_folios()
2763 order, FPI_NONE); in free_unref_folios()
2778 order); in free_unref_folios()
2789 * split_page takes a non-compound higher-order page, and splits it into
2790 * n (1<<order) sub-pages: page[0..n]
2796 void split_page(struct page *page, unsigned int order) in split_page() argument
2803 for (i = 1; i < (1 << order); i++) in split_page()
2805 split_page_owner(page, order, 0); in split_page()
2806 pgalloc_tag_split(page_folio(page), order, 0); in split_page()
2807 split_page_memcg(page, order, 0); in split_page()
2811 int __isolate_free_page(struct page *page, unsigned int order) in __isolate_free_page() argument
2820 * emulate a high-order watermark check with a raised order-0 in __isolate_free_page()
2821 * watermark, because we already know our high-order page in __isolate_free_page()
2824 watermark = zone->_watermark[WMARK_MIN] + (1UL << order); in __isolate_free_page()
2829 del_page_from_free_list(page, zone, order, mt); in __isolate_free_page()
2835 if (order >= pageblock_order - 1) { in __isolate_free_page()
2836 struct page *endpage = page + (1 << order) - 1; in __isolate_free_page()
2849 return 1UL << order; in __isolate_free_page()
2855 * @order: Order of the isolated page
2861 void __putback_isolated_page(struct page *page, unsigned int order, int mt) in __putback_isolated_page() argument
2869 __free_one_page(page, page_to_pfn(page), zone, order, mt, in __putback_isolated_page()
2901 unsigned int order, unsigned int alloc_flags, in rmqueue_buddy() argument
2911 page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC); in rmqueue_buddy()
2913 page = __rmqueue(zone, order, migratetype, alloc_flags); in rmqueue_buddy()
2917 * order-0 (atomic) allocs access to HIGHATOMIC in rmqueue_buddy()
2919 * high-order atomic allocation in the future. in rmqueue_buddy()
2922 page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC); in rmqueue_buddy()
2930 } while (check_new_pages(page, order)); in rmqueue_buddy()
2932 __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order); in rmqueue_buddy()
2938 static int nr_pcp_alloc(struct per_cpu_pages *pcp, struct zone *zone, int order) in nr_pcp_alloc() argument
2952 if (order) in nr_pcp_alloc()
2964 if (!order) { in nr_pcp_alloc()
2968 * subsequent allocation of order-0 pages without any freeing. in nr_pcp_alloc()
2977 * Scale batch relative to order if batch implies free pages in nr_pcp_alloc()
2983 batch = max(batch >> order, 2); in nr_pcp_alloc()
2990 struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, in __rmqueue_pcplist() argument
3000 int batch = nr_pcp_alloc(pcp, zone, order); in __rmqueue_pcplist()
3003 alloced = rmqueue_bulk(zone, order, in __rmqueue_pcplist()
3007 pcp->count += alloced << order; in __rmqueue_pcplist()
3014 pcp->count -= 1 << order; in __rmqueue_pcplist()
3015 } while (check_new_pages(page, order)); in __rmqueue_pcplist()
3022 struct zone *zone, unsigned int order, in rmqueue_pcplist() argument
3044 list = &pcp->lists[order_to_pindex(migratetype, order)]; in rmqueue_pcplist()
3045 page = __rmqueue_pcplist(zone, order, migratetype, alloc_flags, pcp, list); in rmqueue_pcplist()
3049 __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order); in rmqueue_pcplist()
3057 * Use pcplists for THP or "cheap" high-order allocations.
3069 struct zone *zone, unsigned int order, in rmqueue() argument
3075 if (likely(pcp_allowed_order(order))) { in rmqueue()
3076 page = rmqueue_pcplist(preferred_zone, zone, order, in rmqueue()
3082 page = rmqueue_buddy(preferred_zone, zone, order, alloc_flags, in rmqueue()
3098 unsigned int order, unsigned int alloc_flags) in __zone_watermark_unusable_free() argument
3100 long unusable_free = (1 << order) - 1; in __zone_watermark_unusable_free()
3119 * Return true if free base pages are above 'mark'. For high-order checks it
3120 * will return true of the order-0 watermark is reached and there is at least
3124 bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, in __zone_watermark_ok() argument
3132 free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); in __zone_watermark_ok()
3164 * Check watermarks for an order-0 allocation request. If these in __zone_watermark_ok()
3165 * are not met, then a high-order request also cannot go ahead in __zone_watermark_ok()
3171 /* If this is an order-0 request then the watermark is fine */ in __zone_watermark_ok()
3172 if (!order) in __zone_watermark_ok()
3175 /* For a high-order request, check at least one suitable page is free */ in __zone_watermark_ok()
3176 for (o = order; o < NR_PAGE_ORDERS; o++) { in __zone_watermark_ok()
3202 bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, in zone_watermark_ok() argument
3205 return __zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags, in zone_watermark_ok()
3209 static inline bool zone_watermark_fast(struct zone *z, unsigned int order, in zone_watermark_fast() argument
3218 * Fast check for order-0 only. If this fails then the reserves in zone_watermark_fast()
3221 if (!order) { in zone_watermark_fast()
3234 if (__zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags, in zone_watermark_fast()
3239 * Ignore watermark boosting for __GFP_HIGH order-0 allocations in zone_watermark_fast()
3244 if (unlikely(!order && (alloc_flags & ALLOC_MIN_RESERVE) && z->watermark_boost in zone_watermark_fast()
3247 return __zone_watermark_ok(z, order, mark, highest_zoneidx, in zone_watermark_fast()
3254 bool zone_watermark_ok_safe(struct zone *z, unsigned int order, in zone_watermark_ok_safe() argument
3262 return __zone_watermark_ok(z, order, mark, highest_zoneidx, 0, in zone_watermark_ok_safe()
3337 get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, in get_page_from_freelist() argument
3407 cond_accept_memory(zone, order); in get_page_from_freelist()
3420 if (zone_watermark_fast(zone, order, mark, in get_page_from_freelist()
3429 if (!zone_watermark_fast(zone, order, mark, in get_page_from_freelist()
3434 if (cond_accept_memory(zone, order)) in get_page_from_freelist()
3442 if (_deferred_grow_zone(zone, order)) in get_page_from_freelist()
3454 ret = node_reclaim(zone->zone_pgdat, gfp_mask, order); in get_page_from_freelist()
3464 if (zone_watermark_ok(zone, order, mark, in get_page_from_freelist()
3473 page = rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, in get_page_from_freelist()
3476 prep_new_page(page, order, gfp_mask, alloc_flags); in get_page_from_freelist()
3479 * If this is a high-order atomic allocation then check in get_page_from_freelist()
3483 reserve_highatomic_pageblock(page, order, zone); in get_page_from_freelist()
3487 if (cond_accept_memory(zone, order)) in get_page_from_freelist()
3492 if (_deferred_grow_zone(zone, order)) in get_page_from_freelist()
3555 __alloc_pages_cpuset_fallback(gfp_t gfp_mask, unsigned int order, in __alloc_pages_cpuset_fallback() argument
3561 page = get_page_from_freelist(gfp_mask, order, in __alloc_pages_cpuset_fallback()
3568 page = get_page_from_freelist(gfp_mask, order, in __alloc_pages_cpuset_fallback()
3575 __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, in __alloc_pages_may_oom() argument
3583 .order = order, in __alloc_pages_may_oom()
3607 ~__GFP_DIRECT_RECLAIM, order, in __alloc_pages_may_oom()
3615 /* The OOM killer will not help higher order allocs */ in __alloc_pages_may_oom()
3616 if (order > PAGE_ALLOC_COSTLY_ORDER) in __alloc_pages_may_oom()
3653 page = __alloc_pages_cpuset_fallback(gfp_mask, order, in __alloc_pages_may_oom()
3668 /* Try memory compaction for high-order allocations before reclaim */
3670 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, in __alloc_pages_direct_compact() argument
3678 if (!order) in __alloc_pages_direct_compact()
3685 *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, in __alloc_pages_direct_compact()
3702 prep_new_page(page, order, gfp_mask, alloc_flags); in __alloc_pages_direct_compact()
3706 page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); in __alloc_pages_direct_compact()
3712 compaction_defer_reset(zone, order, true); in __alloc_pages_direct_compact()
3729 should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, in should_compact_retry() argument
3740 if (!order) in should_compact_retry()
3747 * Compaction was skipped due to a lack of free order-0 in should_compact_retry()
3751 ret = compaction_zonelist_suitable(ac, order, alloc_flags); in should_compact_retry()
3769 if (order > PAGE_ALLOC_COSTLY_ORDER) in should_compact_retry()
3781 min_priority = (order > PAGE_ALLOC_COSTLY_ORDER) ? in should_compact_retry()
3790 trace_compact_retry(order, priority, compact_result, retries, max_retries, ret); in should_compact_retry()
3795 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, in __alloc_pages_direct_compact() argument
3804 should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags, in should_compact_retry() argument
3812 if (!order || order > PAGE_ALLOC_COSTLY_ORDER) in should_compact_retry()
3818 * Let's give them a good hope and keep retrying while the order-0 in should_compact_retry()
3916 __perform_reclaim(gfp_t gfp_mask, unsigned int order, in __perform_reclaim() argument
3929 progress = try_to_free_pages(ac->zonelist, order, gfp_mask, in __perform_reclaim()
3942 __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, in __alloc_pages_direct_reclaim() argument
3951 *did_some_progress = __perform_reclaim(gfp_mask, order, ac); in __alloc_pages_direct_reclaim()
3956 page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); in __alloc_pages_direct_reclaim()
3975 static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask, in wake_all_kswapds() argument
3988 wakeup_kswapd(zone, gfp_mask, order, highest_zoneidx); in wake_all_kswapds()
3995 gfp_to_alloc_flags(gfp_t gfp_mask, unsigned int order) in gfp_to_alloc_flags() argument
4024 if (order > 0) in gfp_to_alloc_flags()
4096 should_reclaim_retry(gfp_t gfp_mask, unsigned order, in should_reclaim_retry() argument
4106 * their order will become available due to high fragmentation so in should_reclaim_retry()
4109 if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER) in should_reclaim_retry()
4143 wmark = __zone_watermark_ok(zone, order, min_wmark, in should_reclaim_retry()
4145 trace_reclaim_retry_zone(z, order, reclaimable, in should_reclaim_retry()
4206 __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, in __alloc_pages_slowpath() argument
4212 const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER; in __alloc_pages_slowpath()
4227 * allocate greater than order-1 page units with __GFP_NOFAIL. in __alloc_pages_slowpath()
4229 WARN_ON_ONCE(order > 1); in __alloc_pages_slowpath()
4255 alloc_flags = gfp_to_alloc_flags(gfp_mask, order); in __alloc_pages_slowpath()
4282 wake_all_kswapds(order, gfp_mask, ac); in __alloc_pages_slowpath()
4288 page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); in __alloc_pages_slowpath()
4295 * movable high-order allocations, do that as well, as compaction will in __alloc_pages_slowpath()
4303 (order > 0 && ac->migratetype != MIGRATE_MOVABLE)) in __alloc_pages_slowpath()
4305 page = __alloc_pages_direct_compact(gfp_mask, order, in __alloc_pages_slowpath()
4321 * order, fail immediately unless the allocator has in __alloc_pages_slowpath()
4327 * bursty high order allocations, in __alloc_pages_slowpath()
4350 wake_all_kswapds(order, gfp_mask, ac); in __alloc_pages_slowpath()
4369 page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); in __alloc_pages_slowpath()
4382 page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags, ac, in __alloc_pages_slowpath()
4388 page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags, ac, in __alloc_pages_slowpath()
4398 * Do not retry costly high order allocations unless they are in __alloc_pages_slowpath()
4405 if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags, in __alloc_pages_slowpath()
4410 * It doesn't make any sense to retry for the compaction if the order-0 in __alloc_pages_slowpath()
4416 should_compact_retry(ac, order, alloc_flags, in __alloc_pages_slowpath()
4431 page = __alloc_pages_may_oom(gfp_mask, order, ac, &did_some_progress); in __alloc_pages_slowpath()
4476 page = __alloc_pages_cpuset_fallback(gfp_mask, order, ALLOC_MIN_RESERVE, ac); in __alloc_pages_slowpath()
4485 "page allocation failure: order:%u", order); in __alloc_pages_slowpath()
4490 static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, in prepare_alloc_pages() argument
4514 if (should_fail_alloc_page(gfp_mask, order)) in prepare_alloc_pages()
4534 * __alloc_pages_bulk - Allocate a number of order-0 pages to a list or array
4717 struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, in __alloc_pages_noprof() argument
4726 * There are several places where we assume that the order value is sane in __alloc_pages_noprof()
4729 if (WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)) in __alloc_pages_noprof()
4742 if (!prepare_alloc_pages(gfp, order, preferred_nid, nodemask, &ac, in __alloc_pages_noprof()
4753 page = get_page_from_freelist(alloc_gfp, order, alloc_flags, &ac); in __alloc_pages_noprof()
4766 page = __alloc_pages_slowpath(alloc_gfp, order, &ac); in __alloc_pages_noprof()
4770 unlikely(__memcg_kmem_charge_page(page, gfp, order) != 0)) { in __alloc_pages_noprof()
4771 __free_pages(page, order); in __alloc_pages_noprof()
4775 trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype); in __alloc_pages_noprof()
4776 kmsan_alloc_page(page, order, alloc_gfp); in __alloc_pages_noprof()
4782 struct folio *__folio_alloc_noprof(gfp_t gfp, unsigned int order, int preferred_nid, in __folio_alloc_noprof() argument
4785 struct page *page = __alloc_pages_noprof(gfp | __GFP_COMP, order, in __folio_alloc_noprof()
4796 unsigned long get_free_pages_noprof(gfp_t gfp_mask, unsigned int order) in get_free_pages_noprof() argument
4800 page = alloc_pages_noprof(gfp_mask & ~__GFP_HIGHMEM, order); in get_free_pages_noprof()
4816 * @order: The order of the allocation.
4819 * pages. It does not check that the @order passed in matches that of
4833 void __free_pages(struct page *page, unsigned int order) in __free_pages() argument
4840 free_unref_page(page, order); in __free_pages()
4842 pgalloc_tag_sub_pages(tag, (1 << order) - 1); in __free_pages()
4843 while (order-- > 0) in __free_pages()
4844 free_unref_page(page + (1 << order), order); in __free_pages()
4849 void free_pages(unsigned long addr, unsigned int order) in free_pages() argument
4853 __free_pages(virt_to_page((void *)addr), order); in free_pages()
4859 static void *make_alloc_exact(unsigned long addr, unsigned int order, in make_alloc_exact() argument
4867 split_page_owner(page, order, 0); in make_alloc_exact()
4868 pgalloc_tag_split(page_folio(page), order, 0); in make_alloc_exact()
4869 split_page_memcg(page, order, 0); in make_alloc_exact()
4873 last = page + (1UL << order); in make_alloc_exact()
4897 unsigned int order = get_order(size); in alloc_pages_exact_noprof() local
4903 addr = get_free_pages_noprof(gfp_mask, order); in alloc_pages_exact_noprof()
4904 return make_alloc_exact(addr, order, size); in alloc_pages_exact_noprof()
4922 unsigned int order = get_order(size); in alloc_pages_exact_nid_noprof() local
4928 p = alloc_pages_node_noprof(nid, gfp_mask, order); in alloc_pages_exact_nid_noprof()
4931 return make_alloc_exact((unsigned long)page_address(p), order, size); in alloc_pages_exact_nid_noprof()
5199 pr_info("Fallback order for Node %d: ", local_node); in build_zonelists()
5340 * needs the percpu allocator in order to allocate its pagesets in build_all_zonelists_init()
5431 * fragmented and becoming unavailable for high-order allocations. in zone_batchsize()
5625 * consecutive high-order pages freeing without allocation. in zone_pcp_update_cacheinfo()
6353 int order; in split_free_pages() local
6355 for (order = 0; order < NR_PAGE_ORDERS; order++) { in split_free_pages()
6357 int nr_pages = 1 << order; in split_free_pages()
6359 list_for_each_entry_safe(page, next, &list[order], lru) { in split_free_pages()
6362 post_alloc_hook(page, order, __GFP_MOVABLE); in split_free_pages()
6363 if (!order) in split_free_pages()
6366 split_page(page, order); in split_free_pages()
6368 /* Add all subpages to the order-0 head, in sequence. */ in split_free_pages()
6405 .order = -1, in alloc_contig_range_noprof()
6417 * MIGRATE_ISOLATE. Because pageblock and max order pages may in alloc_contig_range_noprof()
6466 * page allocator holds, ie. they can be part of higher order in alloc_contig_range_noprof()
6498 int order = ilog2(end - start); in alloc_contig_range_noprof() local
6500 check_new_pages(head, order); in alloc_contig_range_noprof()
6501 prep_new_page(head, order, gfp_mask, 0); in alloc_contig_range_noprof()
6695 unsigned int order; in __offline_isolated_pages() local
6725 order = buddy_order(page); in __offline_isolated_pages()
6726 del_page_from_free_list(page, zone, order, MIGRATE_ISOLATE); in __offline_isolated_pages()
6727 pfn += (1 << order); in __offline_isolated_pages()
6741 unsigned int order; in is_free_buddy_page() local
6743 for (order = 0; order < NR_PAGE_ORDERS; order++) { in is_free_buddy_page()
6744 const struct page *head = page - (pfn & ((1 << order) - 1)); in is_free_buddy_page()
6747 buddy_order_unsafe(head) >= order) in is_free_buddy_page()
6751 return order <= MAX_PAGE_ORDER; in is_free_buddy_page()
6757 unsigned int order, int migratetype, in add_to_free_list() argument
6760 __add_to_free_list(page, zone, order, migratetype, tail); in add_to_free_list()
6761 account_freepages(zone, 1 << order, migratetype); in add_to_free_list()
6765 * Break down a higher-order page in sub-pages, and keep our target out of
6802 unsigned int order; in take_page_off_buddy() local
6806 for (order = 0; order < NR_PAGE_ORDERS; order++) { in take_page_off_buddy()
6807 struct page *page_head = page - (pfn & ((1 << order) - 1)); in take_page_off_buddy()
6810 if (PageBuddy(page_head) && page_order >= order) { in take_page_off_buddy()
6892 static bool page_contains_unaccepted(struct page *page, unsigned int order) in page_contains_unaccepted() argument
6896 return range_contains_unaccepted_memory(start, PAGE_SIZE << order); in page_contains_unaccepted()
6959 static bool cond_accept_memory(struct zone *zone, unsigned int order) in cond_accept_memory() argument
6973 __zone_watermark_unusable_free(zone, order, 0) - in cond_accept_memory()
7011 static bool page_contains_unaccepted(struct page *page, unsigned int order) in page_contains_unaccepted() argument
7016 static bool cond_accept_memory(struct zone *zone, unsigned int order) in cond_accept_memory() argument