Lines Matching +full:high +full:- +full:z

1 // SPDX-License-Identifier: GPL-2.0-only
39 #include <linux/fault-inject.h>
63 /* Free Page Internal flags: for internal, non-pcp variants of free_pages(). */
72 * reporting it and marking it "reported" - it only skips notifying
81 * page shuffling (relevant code - e.g., memory onlining - is expected to
84 * Note: No code should rely on this flag for correctness - it's purely
91 /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */
104 /* UP spin_trylock always succeeds so disable IRQs to prevent re-entrancy. */
115 * interfered with and a high priority task cannot preempt the allocator.
126 * Generic helper to lookup and a per-cpu variable with an embedded spinlock.
134 spin_lock(&_ret->member); \
143 if (!spin_trylock(&_ret->member)) { \
152 spin_unlock(&ptr->member); \
219 * 1G machine -> (16M dma, 800M-16M normal, 1G-800M high)
220 * 1G machine -> (16M dma, 784M normal, 224M high)
225 * TBD: should special case ZONE_DMA32 machines here - in those we normally
273 int user_min_free_kbytes = -1;
296 * During boot we initialize deferred pages on-demand, as needed, but once
337 return page_zone(page)->pageblock_flags; in get_pageblock_bitmap()
344 pfn &= (PAGES_PER_SECTION-1); in pfn_to_bitidx()
346 pfn = pfn - pageblock_start_pfn(page_zone(page)->zone_start_pfn); in pfn_to_bitidx()
352 …* get_pfnblock_flags_mask - Return the requested group of flags for the pageblock_nr_pages block o…
369 bitidx &= (BITS_PER_LONG-1); in get_pfnblock_flags_mask()
386 …* set_pfnblock_flags_mask - Set the requested group of flags for a pageblock_nr_pages block of pag…
406 bitidx &= (BITS_PER_LONG-1); in set_pfnblock_flags_mask()
438 start_pfn = zone->zone_start_pfn; in page_outside_zone_boundaries()
439 sp = zone->spanned_pages; in page_outside_zone_boundaries()
444 pr_err("page 0x%lx outside node %d zone %s [ 0x%lx - 0x%lx ]\n", in page_outside_zone_boundaries()
445 pfn, zone_to_nid(zone), zone->name, in page_outside_zone_boundaries()
497 current->comm, page_to_pfn(page)); in bad_page()
554 * Higher-order pages are called "compound pages". They are structured thusly:
559 * in bit 0 of page->compound_head. The rest of bits is pointer to head page.
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.
586 struct capture_control *capc = current->capture_control; in task_capc()
589 !(current->flags & PF_KTHREAD) && in task_capc()
590 !capc->page && in task_capc()
591 capc->cc->zone == zone ? capc : NULL; in task_capc()
598 if (!capc || order != capc->cc->order) in compaction_capture()
610 * and vice-versa but no more than normal fallback logic which can in compaction_capture()
611 * have trouble finding a high-order free page. in compaction_capture()
614 capc->cc->migratetype != MIGRATE_MOVABLE) in compaction_capture()
617 capc->page = page; in compaction_capture()
638 lockdep_assert_held(&zone->lock); in account_freepages()
648 WRITE_ONCE(zone->nr_free_highatomic, in account_freepages()
649 zone->nr_free_highatomic + nr_pages); in account_freepages()
657 struct free_area *area = &zone->free_area[order]; in __add_to_free_list()
664 list_add_tail(&page->buddy_list, &area->free_list[migratetype]); in __add_to_free_list()
666 list_add(&page->buddy_list, &area->free_list[migratetype]); in __add_to_free_list()
667 area->nr_free++; in __add_to_free_list()
672 * of the list - so the moved pages won't immediately be considered for
678 struct free_area *area = &zone->free_area[order]; in move_to_free_list()
685 list_move_tail(&page->buddy_list, &area->free_list[new_mt]); in move_to_free_list()
687 account_freepages(zone, -(1 << order), old_mt); in move_to_free_list()
702 list_del(&page->buddy_list); in __del_page_from_free_list()
705 zone->free_area[order].nr_free--; in __del_page_from_free_list()
712 account_freepages(zone, -(1 << order), migratetype); in del_page_from_free_list()
718 return list_first_entry_or_null(&area->free_list[migratetype], in get_page_from_free_area()
724 * of the next-higher order is free. If it is, it's possible
728 * as a 2-level higher order page
737 if (order >= MAX_PAGE_ORDER - 1) in buddy_merge_likely()
741 higher_page = page + (higher_page_pfn - pfn); in buddy_merge_likely()
750 * The concept of a buddy system is to maintain direct-mapped table
755 * At a high level, all that happens here is marking the table entry
768 * -- nyc
783 VM_BUG_ON_PAGE(page->flags & PAGE_FLAGS_CHECK_AT_PREP, page); in __free_one_page()
785 VM_BUG_ON(migratetype == -1); in __free_one_page()
786 VM_BUG_ON_PAGE(pfn & ((1 << order) - 1), page); in __free_one_page()
795 account_freepages(zone, -(1 << order), migratetype); in __free_one_page()
830 * expand() down the line puts the sub-blocks in __free_one_page()
837 page = page + (combined_pfn - pfn); in __free_one_page()
867 if (unlikely(atomic_read(&page->_mapcount) != -1)) in page_expected_state()
870 if (unlikely((unsigned long)page->mapping | in page_expected_state()
873 page->memcg_data | in page_expected_state()
876 ((page->pp_magic & ~0x3UL) == PP_SIGNATURE) | in page_expected_state()
878 (page->flags & check_flags))) in page_expected_state()
888 if (unlikely(atomic_read(&page->_mapcount) != -1)) in page_bad_reason()
890 if (unlikely(page->mapping != NULL)) in page_bad_reason()
891 bad_reason = "non-NULL mapping"; in page_bad_reason()
894 if (unlikely(page->flags & flags)) { in page_bad_reason()
901 if (unlikely(page->memcg_data)) in page_bad_reason()
905 if (unlikely((page->pp_magic & ~0x3UL) == PP_SIGNATURE)) in page_bad_reason()
938 * We rely page->lru.next never has bit 0 set, unless the page in free_tail_page_prepare()
939 * is PageTail(). Let's make sure that's true even for poisoned ->lru. in free_tail_page_prepare()
947 switch (page - head_page) { in free_tail_page_prepare()
949 /* the first tail page: these may be in place of ->mapping */ in free_tail_page_prepare()
958 if (unlikely(atomic_read(&folio->_nr_pages_mapped))) { in free_tail_page_prepare()
962 if (unlikely(atomic_read(&folio->_pincount))) { in free_tail_page_prepare()
968 /* the second tail page: deferred_list overlaps ->mapping */ in free_tail_page_prepare()
969 if (unlikely(!list_empty(&folio->_deferred_list))) { in free_tail_page_prepare()
975 if (page->mapping != TAIL_MAPPING) { in free_tail_page_prepare()
991 page->mapping = NULL; in free_tail_page_prepare()
1000 * Tag-based KASAN modes skip pages freed via deferred memory initialization
1002 * 2. For tag-based KASAN modes: the page has a match-all KASAN tag, indicating
1005 * Pages will have match-all tags in the following circumstances:
1022 * on-demand allocation and then freed again before the deferred pages
1071 zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages); in free_pages_prepare()
1094 * avoid checking PageCompound for order-0 pages. in free_pages_prepare()
1110 (page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; in free_pages_prepare()
1115 mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); in free_pages_prepare()
1116 page->mapping = NULL; in free_pages_prepare()
1126 page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; in free_pages_prepare()
1145 * With hardware tag-based KASAN, memory tags must be set before the in free_pages_prepare()
1187 count = min(pcp->count, count); in free_pcppages_bulk()
1190 pindex = pindex - 1; in free_pcppages_bulk()
1192 spin_lock_irqsave(&zone->lock, flags); in free_pcppages_bulk()
1198 /* Remove pages from lists in a round-robin fashion. */ in free_pcppages_bulk()
1200 if (++pindex > NR_PCP_LISTS - 1) in free_pcppages_bulk()
1202 list = &pcp->lists[pindex]; in free_pcppages_bulk()
1216 list_del(&page->pcp_list); in free_pcppages_bulk()
1217 count -= nr_pages; in free_pcppages_bulk()
1218 pcp->count -= nr_pages; in free_pcppages_bulk()
1225 spin_unlock_irqrestore(&zone->lock, flags); in free_pcppages_bulk()
1228 /* Split a multi-block free page into its individual pageblocks. */
1258 spin_lock_irqsave(&zone->lock, flags); in free_one_page()
1260 spin_unlock_irqrestore(&zone->lock, flags); in free_one_page()
1306 atomic_long_add(nr_pages, &page_zone(page)->managed_pages); in __free_pages_core()
1338 * Note: the function may return non-NULL struct page even for a page block
1341 * will fall into 2 sub-sections, and the end pfn of the pageblock may be hole
1354 end_pfn--; in __pageblock_pfn_to_page()
1387 * -- nyc
1390 int high, int migratetype) in expand() argument
1392 unsigned int size = 1 << high; in expand()
1395 while (high > low) { in expand()
1396 high--; in expand()
1406 if (set_page_guard(zone, &page[size], high)) in expand()
1409 __add_to_free_list(&page[size], zone, high, migratetype, false); in expand()
1410 set_buddy_order(&page[size], high); in expand()
1419 int high, int migratetype) in page_del_and_expand() argument
1421 int nr_pages = 1 << high; in page_del_and_expand()
1423 __del_page_from_free_list(page, zone, high, migratetype); in page_del_and_expand()
1424 nr_pages -= expand(zone, page, low, high, migratetype); in page_del_and_expand()
1425 account_freepages(zone, -nr_pages, migratetype); in page_del_and_expand()
1430 if (unlikely(page->flags & __PG_HWPOISON)) { in check_new_page_bad()
1475 /* Skip, if hardware tag-based KASAN is not enabled. */ in should_skip_kasan_unpoison()
1480 * With hardware tag-based KASAN enabled, skip if this has been in should_skip_kasan_unpoison()
1488 /* Don't skip, if hardware tag-based KASAN is not enabled. */ in should_skip_init()
1492 /* For hardware tag-based KASAN, skip if requested. */ in should_skip_init()
1590 area = &(zone->free_area[current_order]); in __rmqueue_smallest()
1613 static int fallbacks[MIGRATE_PCPTYPES][MIGRATE_PCPTYPES - 1] = {
1642 VM_WARN_ON(start_pfn & (pageblock_nr_pages - 1)); in __move_freepages_block()
1688 if (!zone_spans_pfn(zone, end - 1)) in prep_move_freepages_block()
1725 return -1; in move_freepages_block()
1756 * move_freepages_block_isolate - move free pages in block for page isolation
1820 int nr_pageblocks = 1 << (start_order - pageblock_order); in change_pageblock_range()
1822 while (nr_pageblocks--) { in change_pageblock_range()
1884 max_boost = mult_frac(zone->_watermark[WMARK_HIGH], in boost_watermark()
1888 * high watermark may be uninitialised if fragmentation occurs in boost_watermark()
1900 zone->watermark_boost = min(zone->watermark_boost + pageblock_nr_pages, in boost_watermark()
1949 set_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); in steal_suitable_fallback()
1970 * to MOVABLE pageblock, consider all non-movable pages as in steal_suitable_fallback()
1973 * exact migratetype of non-movable pages. in steal_suitable_fallback()
1977 - (free_pages + movable_pages); in steal_suitable_fallback()
1985 if (free_pages + alike_pages >= (1 << (pageblock_order-1)) || in steal_suitable_fallback()
2008 if (area->nr_free == 0) in find_suitable_fallback()
2009 return -1; in find_suitable_fallback()
2012 for (i = 0; i < MIGRATE_PCPTYPES - 1 ; i++) { in find_suitable_fallback()
2027 return -1; in find_suitable_fallback()
2032 * exclusive use of high-order atomic allocations if there are no
2045 * Check is race-prone but harmless. in reserve_highatomic_pageblock()
2050 if (zone->nr_reserved_highatomic >= max_managed) in reserve_highatomic_pageblock()
2053 spin_lock_irqsave(&zone->lock, flags); in reserve_highatomic_pageblock()
2056 if (zone->nr_reserved_highatomic >= max_managed) in reserve_highatomic_pageblock()
2066 if (move_freepages_block(zone, page, mt, MIGRATE_HIGHATOMIC) == -1) in reserve_highatomic_pageblock()
2068 zone->nr_reserved_highatomic += pageblock_nr_pages; in reserve_highatomic_pageblock()
2071 zone->nr_reserved_highatomic += 1 << order; in reserve_highatomic_pageblock()
2075 spin_unlock_irqrestore(&zone->lock, flags); in reserve_highatomic_pageblock()
2080 * potentially hurts the reliability of high-order allocations when under
2090 struct zonelist *zonelist = ac->zonelist; in unreserve_highatomic_pageblock()
2092 struct zoneref *z; in unreserve_highatomic_pageblock() local
2098 for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->highest_zoneidx, in unreserve_highatomic_pageblock()
2099 ac->nodemask) { in unreserve_highatomic_pageblock()
2102 * is really high. in unreserve_highatomic_pageblock()
2104 if (!force && zone->nr_reserved_highatomic <= in unreserve_highatomic_pageblock()
2108 spin_lock_irqsave(&zone->lock, flags); in unreserve_highatomic_pageblock()
2110 struct free_area *area = &(zone->free_area[order]); in unreserve_highatomic_pageblock()
2122 * from highatomic to ac->migratetype. So we should in unreserve_highatomic_pageblock()
2129 * locking could inadvertently allow a per-cpu in unreserve_highatomic_pageblock()
2135 size = min(size, zone->nr_reserved_highatomic); in unreserve_highatomic_pageblock()
2136 zone->nr_reserved_highatomic -= size; in unreserve_highatomic_pageblock()
2140 * Convert to ac->migratetype and avoid the normal in unreserve_highatomic_pageblock()
2150 ac->migratetype); in unreserve_highatomic_pageblock()
2153 ac->migratetype); in unreserve_highatomic_pageblock()
2155 ac->migratetype); in unreserve_highatomic_pageblock()
2162 WARN_ON_ONCE(ret == -1); in unreserve_highatomic_pageblock()
2164 spin_unlock_irqrestore(&zone->lock, flags); in unreserve_highatomic_pageblock()
2168 spin_unlock_irqrestore(&zone->lock, flags); in unreserve_highatomic_pageblock()
2209 --current_order) { in __rmqueue_fallback()
2210 area = &(zone->free_area[current_order]); in __rmqueue_fallback()
2213 if (fallback_mt == -1) in __rmqueue_fallback()
2235 area = &(zone->free_area[current_order]); in __rmqueue_fallback()
2238 if (fallback_mt != -1) in __rmqueue_fallback()
2243 * This should not happen - we already found a suitable fallback in __rmqueue_fallback()
2263 * Call me with the zone->lock already held.
2310 spin_lock_irqsave(&zone->lock, flags); in rmqueue_bulk()
2327 list_add_tail(&page->pcp_list, list); in rmqueue_bulk()
2329 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_bulk()
2335 * Called from the vmstat counter updater to decay the PCP high.
2343 high_min = READ_ONCE(pcp->high_min); in decay_pcp_high()
2344 batch = READ_ONCE(pcp->batch); in decay_pcp_high()
2346 * Decrease pcp->high periodically to try to free possible in decay_pcp_high()
2348 * control latency. This caps pcp->high decrement too. in decay_pcp_high()
2350 if (pcp->high > high_min) { in decay_pcp_high()
2351 pcp->high = max3(pcp->count - (batch << CONFIG_PCP_BATCH_SCALE_MAX), in decay_pcp_high()
2352 pcp->high - (pcp->high >> 3), high_min); in decay_pcp_high()
2353 if (pcp->high > high_min) in decay_pcp_high()
2357 to_drain = pcp->count - pcp->high; in decay_pcp_high()
2359 spin_lock(&pcp->lock); in decay_pcp_high()
2361 spin_unlock(&pcp->lock); in decay_pcp_high()
2378 batch = READ_ONCE(pcp->batch); in drain_zone_pages()
2379 to_drain = min(pcp->count, batch); in drain_zone_pages()
2381 spin_lock(&pcp->lock); in drain_zone_pages()
2383 spin_unlock(&pcp->lock); in drain_zone_pages()
2393 struct per_cpu_pages *pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in drain_pages_zone()
2397 spin_lock(&pcp->lock); in drain_pages_zone()
2398 count = pcp->count; in drain_pages_zone()
2401 pcp->batch << CONFIG_PCP_BATCH_SCALE_MAX); in drain_pages_zone()
2404 count -= to_drain; in drain_pages_zone()
2406 spin_unlock(&pcp->lock); in drain_pages_zone()
2423 * Spill all of this CPU's per-cpu pages back into the buddy allocator.
2440 * not empty. The check for non-emptiness can however race with a free to
2441 * pcplist that has not yet increased the pcp->count from 0 to 1. Callers
2474 struct zone *z; in __drain_all_pages() local
2484 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in __drain_all_pages()
2485 if (pcp->count) in __drain_all_pages()
2488 for_each_populated_zone(z) { in __drain_all_pages()
2489 pcp = per_cpu_ptr(z->per_cpu_pageset, cpu); in __drain_all_pages()
2490 if (pcp->count) { in __drain_all_pages()
2514 * Spill all the per-cpu pages from all CPUs back into the buddy allocator.
2516 * When zone parameter is non-NULL, spill just the single zone's pages.
2523 static int nr_pcp_free(struct per_cpu_pages *pcp, int batch, int high, bool free_high) in nr_pcp_free() argument
2527 /* Free as much as possible if batch freeing high-order pages. */ in nr_pcp_free()
2529 return min(pcp->count, batch << CONFIG_PCP_BATCH_SCALE_MAX); in nr_pcp_free()
2532 if (unlikely(high < batch)) in nr_pcp_free()
2535 /* Leave at least pcp->batch pages on the list */ in nr_pcp_free()
2537 max_nr_free = high - batch; in nr_pcp_free()
2543 batch = clamp_t(int, pcp->free_count, min_nr_free, max_nr_free); in nr_pcp_free()
2551 int high, high_min, high_max; in nr_pcp_high() local
2553 high_min = READ_ONCE(pcp->high_min); in nr_pcp_high()
2554 high_max = READ_ONCE(pcp->high_max); in nr_pcp_high()
2555 high = pcp->high = clamp(pcp->high, high_min, high_max); in nr_pcp_high()
2557 if (unlikely(!high)) in nr_pcp_high()
2561 pcp->high = max(high - (batch << CONFIG_PCP_BATCH_SCALE_MAX), in nr_pcp_high()
2570 if (test_bit(ZONE_RECLAIM_ACTIVE, &zone->flags)) { in nr_pcp_high()
2571 int free_count = max_t(int, pcp->free_count, batch); in nr_pcp_high()
2573 pcp->high = max(high - free_count, high_min); in nr_pcp_high()
2574 return min(batch << 2, pcp->high); in nr_pcp_high()
2578 return high; in nr_pcp_high()
2580 if (test_bit(ZONE_BELOW_HIGH, &zone->flags)) { in nr_pcp_high()
2581 int free_count = max_t(int, pcp->free_count, batch); in nr_pcp_high()
2583 pcp->high = max(high - free_count, high_min); in nr_pcp_high()
2584 high = max(pcp->count, high_min); in nr_pcp_high()
2585 } else if (pcp->count >= high) { in nr_pcp_high()
2586 int need_high = pcp->free_count + batch; in nr_pcp_high()
2588 /* pcp->high should be large enough to hold batch freed pages */ in nr_pcp_high()
2589 if (pcp->high < need_high) in nr_pcp_high()
2590 pcp->high = clamp(need_high, high_min, high_max); in nr_pcp_high()
2593 return high; in nr_pcp_high()
2600 int high, batch; in free_frozen_page_commit() local
2609 pcp->alloc_factor >>= 1; in free_frozen_page_commit()
2612 list_add(&page->pcp_list, &pcp->lists[pindex]); in free_frozen_page_commit()
2613 pcp->count += 1 << order; in free_frozen_page_commit()
2615 batch = READ_ONCE(pcp->batch); in free_frozen_page_commit()
2617 * As high-order pages other than THP's stored on PCP can contribute in free_frozen_page_commit()
2623 free_high = (pcp->free_count >= batch && in free_frozen_page_commit()
2624 (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) && in free_frozen_page_commit()
2625 (!(pcp->flags & PCPF_FREE_HIGH_BATCH) || in free_frozen_page_commit()
2626 pcp->count >= READ_ONCE(batch))); in free_frozen_page_commit()
2627 pcp->flags |= PCPF_PREV_FREE_HIGH_ORDER; in free_frozen_page_commit()
2628 } else if (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) { in free_frozen_page_commit()
2629 pcp->flags &= ~PCPF_PREV_FREE_HIGH_ORDER; in free_frozen_page_commit()
2631 if (pcp->free_count < (batch << CONFIG_PCP_BATCH_SCALE_MAX)) in free_frozen_page_commit()
2632 pcp->free_count += (1 << order); in free_frozen_page_commit()
2633 high = nr_pcp_high(pcp, zone, batch, free_high); in free_frozen_page_commit()
2634 if (pcp->count >= high) { in free_frozen_page_commit()
2635 free_pcppages_bulk(zone, nr_pcp_free(pcp, batch, high, free_high), in free_frozen_page_commit()
2637 if (test_bit(ZONE_BELOW_HIGH, &zone->flags) && in free_frozen_page_commit()
2640 clear_bit(ZONE_BELOW_HIGH, &zone->flags); in free_frozen_page_commit()
2681 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in free_frozen_pages()
2702 for (i = 0, j = 0; i < folios->nr; i++) { in free_unref_folios()
2703 struct folio *folio = folios->folios[i]; in free_unref_folios()
2707 if (!free_pages_prepare(&folio->page, order)) in free_unref_folios()
2714 free_one_page(folio_zone(folio), &folio->page, in free_unref_folios()
2718 folio->private = (void *)(unsigned long)order; in free_unref_folios()
2720 folios->folios[j] = folio; in free_unref_folios()
2723 folios->nr = j; in free_unref_folios()
2725 for (i = 0; i < folios->nr; i++) { in free_unref_folios()
2726 struct folio *folio = folios->folios[i]; in free_unref_folios()
2729 unsigned int order = (unsigned long)folio->private; in free_unref_folios()
2732 folio->private = NULL; in free_unref_folios()
2733 migratetype = get_pfnblock_migratetype(&folio->page, pfn); in free_unref_folios()
2750 free_one_page(zone, &folio->page, pfn, in free_unref_folios()
2760 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in free_unref_folios()
2763 free_one_page(zone, &folio->page, pfn, in free_unref_folios()
2771 * Non-isolated types over MIGRATE_PCPTYPES get added in free_unref_folios()
2777 trace_mm_page_free_batched(&folio->page); in free_unref_folios()
2778 free_frozen_page_commit(zone, pcp, &folio->page, migratetype, in free_unref_folios()
2790 * split_page takes a non-compound higher-order page, and splits it into
2791 * n (1<<order) sub-pages: page[0..n]
2792 * Each sub-page must be freed individually.
2821 * emulate a high-order watermark check with a raised order-0 in __isolate_free_page()
2822 * watermark, because we already know our high-order page in __isolate_free_page()
2825 watermark = zone->_watermark[WMARK_MIN] + (1UL << order); in __isolate_free_page()
2836 if (order >= pageblock_order - 1) { in __isolate_free_page()
2837 struct page *endpage = page + (1 << order) - 1; in __isolate_free_page()
2854 * __putback_isolated_page - Return a now-isolated page back where we got it
2867 lockdep_assert_held(&zone->lock); in __putback_isolated_page()
2877 static inline void zone_statistics(struct zone *preferred_zone, struct zone *z, in zone_statistics() argument
2887 if (zone_to_nid(z) != numa_node_id()) in zone_statistics()
2890 if (zone_to_nid(z) == zone_to_nid(preferred_zone)) in zone_statistics()
2891 __count_numa_events(z, NUMA_HIT, nr_account); in zone_statistics()
2893 __count_numa_events(z, NUMA_MISS, nr_account); in zone_statistics()
2896 __count_numa_events(z, local_stat, nr_account); in zone_statistics()
2910 spin_lock_irqsave(&zone->lock, flags); in rmqueue_buddy()
2918 * order-0 (atomic) allocs access to HIGHATOMIC in rmqueue_buddy()
2920 * high-order atomic allocation in the future. in rmqueue_buddy()
2926 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_buddy()
2930 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_buddy()
2941 int high, base_batch, batch, max_nr_alloc; in nr_pcp_alloc() local
2944 base_batch = READ_ONCE(pcp->batch); in nr_pcp_alloc()
2945 high_min = READ_ONCE(pcp->high_min); in nr_pcp_alloc()
2946 high_max = READ_ONCE(pcp->high_max); in nr_pcp_alloc()
2947 high = pcp->high = clamp(pcp->high, high_min, high_max); in nr_pcp_alloc()
2950 if (unlikely(high < base_batch)) in nr_pcp_alloc()
2956 batch = (base_batch << pcp->alloc_factor); in nr_pcp_alloc()
2959 * If we had larger pcp->high, we could avoid to allocate from in nr_pcp_alloc()
2962 if (high_min != high_max && !test_bit(ZONE_BELOW_HIGH, &zone->flags)) in nr_pcp_alloc()
2963 high = pcp->high = min(high + batch, high_max); in nr_pcp_alloc()
2966 max_nr_alloc = max(high - pcp->count - base_batch, base_batch); in nr_pcp_alloc()
2969 * subsequent allocation of order-0 pages without any freeing. in nr_pcp_alloc()
2972 pcp->alloc_factor < CONFIG_PCP_BATCH_SCALE_MAX) in nr_pcp_alloc()
2973 pcp->alloc_factor++; in nr_pcp_alloc()
2989 /* Remove page from the per-cpu list, caller must protect the list */
3008 pcp->count += alloced << order; in __rmqueue_pcplist()
3014 list_del(&page->pcp_list); in __rmqueue_pcplist()
3015 pcp->count -= 1 << order; in __rmqueue_pcplist()
3021 /* Lock and remove page from the per-cpu list */
3033 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in rmqueue_pcplist()
3044 pcp->free_count >>= 1; in rmqueue_pcplist()
3045 list = &pcp->lists[order_to_pindex(migratetype, order)]; in rmqueue_pcplist()
3058 * Use pcplists for THP or "cheap" high-order allocations.
3089 unlikely(test_bit(ZONE_BOOSTED_WATERMARK, &zone->flags))) { in rmqueue()
3090 clear_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); in rmqueue()
3098 static inline long __zone_watermark_unusable_free(struct zone *z, in __zone_watermark_unusable_free() argument
3101 long unusable_free = (1 << order) - 1; in __zone_watermark_unusable_free()
3108 unusable_free += READ_ONCE(z->nr_free_highatomic); in __zone_watermark_unusable_free()
3113 unusable_free += zone_page_state(z, NR_FREE_CMA_PAGES); in __zone_watermark_unusable_free()
3120 * Return true if free base pages are above 'mark'. For high-order checks it
3121 * will return true of the order-0 watermark is reached and there is at least
3125 bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, in __zone_watermark_ok() argument
3132 /* free_pages may go negative - that's OK */ in __zone_watermark_ok()
3133 free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); in __zone_watermark_ok()
3141 min -= min / 2; in __zone_watermark_ok()
3144 * Non-blocking allocations (e.g. GFP_ATOMIC) can in __zone_watermark_ok()
3146 * non-blocking allocations requests such as GFP_NOWAIT in __zone_watermark_ok()
3151 min -= min / 4; in __zone_watermark_ok()
3158 * makes during the free path will be small and short-lived. in __zone_watermark_ok()
3161 min -= min / 2; in __zone_watermark_ok()
3165 * Check watermarks for an order-0 allocation request. If these in __zone_watermark_ok()
3166 * are not met, then a high-order request also cannot go ahead in __zone_watermark_ok()
3169 if (free_pages <= min + z->lowmem_reserve[highest_zoneidx]) in __zone_watermark_ok()
3172 /* If this is an order-0 request then the watermark is fine */ in __zone_watermark_ok()
3176 /* For a high-order request, check at least one suitable page is free */ in __zone_watermark_ok()
3178 struct free_area *area = &z->free_area[o]; in __zone_watermark_ok()
3181 if (!area->nr_free) in __zone_watermark_ok()
3203 bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, in zone_watermark_ok() argument
3206 return __zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags, in zone_watermark_ok()
3207 zone_page_state(z, NR_FREE_PAGES)); in zone_watermark_ok()
3210 static inline bool zone_watermark_fast(struct zone *z, unsigned int order, in zone_watermark_fast() argument
3216 free_pages = zone_page_state(z, NR_FREE_PAGES); in zone_watermark_fast()
3219 * Fast check for order-0 only. If this fails then the reserves in zone_watermark_fast()
3227 reserved = __zone_watermark_unusable_free(z, 0, alloc_flags); in zone_watermark_fast()
3229 /* reserved may over estimate high-atomic reserves. */ in zone_watermark_fast()
3230 usable_free -= min(usable_free, reserved); in zone_watermark_fast()
3231 if (usable_free > mark + z->lowmem_reserve[highest_zoneidx]) in zone_watermark_fast()
3235 if (__zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags, in zone_watermark_fast()
3240 * Ignore watermark boosting for __GFP_HIGH order-0 allocations in zone_watermark_fast()
3245 if (unlikely(!order && (alloc_flags & ALLOC_MIN_RESERVE) && z->watermark_boost in zone_watermark_fast()
3247 mark = z->_watermark[WMARK_MIN]; in zone_watermark_fast()
3248 return __zone_watermark_ok(z, order, mark, highest_zoneidx, in zone_watermark_fast()
3255 bool zone_watermark_ok_safe(struct zone *z, unsigned int order, in zone_watermark_ok_safe() argument
3258 long free_pages = zone_page_state(z, NR_FREE_PAGES); in zone_watermark_ok_safe()
3260 if (z->percpu_drift_mark && free_pages < z->percpu_drift_mark) in zone_watermark_ok_safe()
3261 free_pages = zone_page_state_snapshot(z, NR_FREE_PAGES); in zone_watermark_ok_safe()
3263 return __zone_watermark_ok(z, order, mark, highest_zoneidx, 0, in zone_watermark_ok_safe()
3310 * the pointer is within zone->zone_pgdat->node_zones[]. Also assume in alloc_flags_nofragment()
3313 BUILD_BUG_ON(ZONE_NORMAL - ZONE_DMA32 != 1); in alloc_flags_nofragment()
3314 if (nr_online_nodes > 1 && !populated_zone(--zone)) in alloc_flags_nofragment()
3341 struct zoneref *z; in get_page_from_freelist() local
3353 z = ac->preferred_zoneref; in get_page_from_freelist()
3354 for_next_zone_zonelist_nodemask(zone, z, ac->highest_zoneidx, in get_page_from_freelist()
3355 ac->nodemask) { in get_page_from_freelist()
3369 * lowmem reserves and high watermark so that kswapd in get_page_from_freelist()
3374 * exceed the per-node dirty limit in the slowpath in get_page_from_freelist()
3380 * dirty-throttling and the flusher threads. in get_page_from_freelist()
3382 if (ac->spread_dirty_pages) { in get_page_from_freelist()
3383 if (last_pgdat != zone->zone_pgdat) { in get_page_from_freelist()
3384 last_pgdat = zone->zone_pgdat; in get_page_from_freelist()
3385 last_pgdat_dirty_ok = node_dirty_ok(zone->zone_pgdat); in get_page_from_freelist()
3393 zone != zonelist_zone(ac->preferred_zoneref)) { in get_page_from_freelist()
3401 local_nid = zonelist_node_idx(ac->preferred_zoneref); in get_page_from_freelist()
3411 * Detect whether the number of free pages is below high in get_page_from_freelist()
3412 * watermark. If so, we will decrease pcp->high and free in get_page_from_freelist()
3417 if (test_bit(ZONE_BELOW_HIGH, &zone->flags)) in get_page_from_freelist()
3422 ac->highest_zoneidx, alloc_flags, in get_page_from_freelist()
3426 set_bit(ZONE_BELOW_HIGH, &zone->flags); in get_page_from_freelist()
3431 ac->highest_zoneidx, alloc_flags, in get_page_from_freelist()
3452 !zone_allows_reclaim(zonelist_zone(ac->preferred_zoneref), zone)) in get_page_from_freelist()
3455 ret = node_reclaim(zone->zone_pgdat, gfp_mask, order); in get_page_from_freelist()
3466 ac->highest_zoneidx, alloc_flags)) in get_page_from_freelist()
3474 page = rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, in get_page_from_freelist()
3475 gfp_mask, alloc_flags, ac->migratetype); in get_page_from_freelist()
3480 * If this is a high-order atomic allocation then check in get_page_from_freelist()
3522 (current->flags & (PF_MEMALLOC | PF_EXITING))) in warn_alloc_show_mem()
3545 current->comm, &vaf, gfp_mask, &gfp_mask, in warn_alloc()
3579 .zonelist = ac->zonelist, in __alloc_pages_may_oom()
3580 .nodemask = ac->nodemask, in __alloc_pages_may_oom()
3600 * Go through the zonelist yet one more time, keep very high watermark in __alloc_pages_may_oom()
3613 if (current->flags & PF_DUMPCORE) in __alloc_pages_may_oom()
3629 if (ac->highest_zoneidx < ZONE_NORMAL) in __alloc_pages_may_oom()
3649 * Help non-failing allocations by giving them access to memory in __alloc_pages_may_oom()
3668 /* Try memory compaction for high-order allocations before reclaim */
3711 zone->compact_blockskip_flush = false; in __alloc_pages_direct_compact()
3747 * Compaction was skipped due to a lack of free order-0 in should_compact_retry()
3785 (*compact_priority)--; in should_compact_retry()
3810 struct zoneref *z; in should_compact_retry() local
3818 * Let's give them a good hope and keep retrying while the order-0 in should_compact_retry()
3821 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in should_compact_retry()
3822 ac->highest_zoneidx, ac->nodemask) { in should_compact_retry()
3824 ac->highest_zoneidx, alloc_flags)) in should_compact_retry()
3842 if (current->flags & PF_MEMALLOC) in __need_reclaim()
3929 progress = try_to_free_pages(ac->zonelist, order, gfp_mask, in __perform_reclaim()
3930 ac->nodemask); in __perform_reclaim()
3960 * pages are pinned on the per-cpu lists or in high alloc reserves. in __alloc_pages_direct_reclaim()
3978 struct zoneref *z; in wake_all_kswapds() local
3981 enum zone_type highest_zoneidx = ac->highest_zoneidx; in wake_all_kswapds()
3983 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, highest_zoneidx, in wake_all_kswapds()
3984 ac->nodemask) { in wake_all_kswapds()
3987 if (last_pgdat != zone->zone_pgdat) { in wake_all_kswapds()
3989 last_pgdat = zone->zone_pgdat; in wake_all_kswapds()
4029 * Ignore cpuset mems for non-blocking __GFP_HIGH (probably in gfp_to_alloc_flags()
4068 if (in_serving_softirq() && (current->flags & PF_MEMALLOC)) in __gfp_pfmemalloc_flags()
4071 if (current->flags & PF_MEMALLOC) in __gfp_pfmemalloc_flags()
4101 struct zoneref *z; in should_reclaim_retry() local
4106 * their order will become available due to high fragmentation so in should_reclaim_retry()
4124 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in should_reclaim_retry()
4125 ac->highest_zoneidx, ac->nodemask) { in should_reclaim_retry()
4144 ac->highest_zoneidx, alloc_flags, available); in should_reclaim_retry()
4145 trace_reclaim_retry_zone(z, order, reclaimable, in should_reclaim_retry()
4160 if (current->flags & PF_WQ_WORKER) in should_reclaim_retry()
4181 * This assumes that for all allocations, ac->nodemask can come only in check_retry_cpuset()
4186 if (cpusets_enabled() && ac->nodemask && in check_retry_cpuset()
4187 !cpuset_nodemask_valid_mems_allowed(ac->nodemask)) { in check_retry_cpuset()
4188 ac->nodemask = NULL; in check_retry_cpuset()
4227 * allocate greater than order-1 page units with __GFP_NOFAIL. in __alloc_pages_slowpath()
4240 WARN_ON_ONCE(current->flags & PF_MEMALLOC); in __alloc_pages_slowpath()
4261 * there was a cpuset modification and we are retrying - otherwise we in __alloc_pages_slowpath()
4262 * could end up iterating over non-eligible zones endlessly. in __alloc_pages_slowpath()
4264 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath()
4265 ac->highest_zoneidx, ac->nodemask); in __alloc_pages_slowpath()
4266 if (!zonelist_zone(ac->preferred_zoneref)) in __alloc_pages_slowpath()
4271 * any suitable zone to satisfy the request - e.g. non-movable in __alloc_pages_slowpath()
4275 struct zoneref *z = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath() local
4276 ac->highest_zoneidx, in __alloc_pages_slowpath()
4278 if (!zonelist_zone(z)) in __alloc_pages_slowpath()
4295 * that we have enough base pages and don't need to reclaim. For non- in __alloc_pages_slowpath()
4296 * movable high-order allocations, do that as well, as compaction will in __alloc_pages_slowpath()
4304 (order > 0 && ac->migratetype != MIGRATE_MOVABLE)) in __alloc_pages_slowpath()
4326 * - potentially very expensive because zones are far in __alloc_pages_slowpath()
4328 * bursty high order allocations, in __alloc_pages_slowpath()
4329 * - not guaranteed to help because isolate_freepages() in __alloc_pages_slowpath()
4332 * - unlikely to make entire pageblocks free on its in __alloc_pages_slowpath()
4360 * ignored. These allocations are high priority and system rather than in __alloc_pages_slowpath()
4364 ac->nodemask = NULL; in __alloc_pages_slowpath()
4365 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath()
4366 ac->highest_zoneidx, ac->nodemask); in __alloc_pages_slowpath()
4379 if (current->flags & PF_MEMALLOC) in __alloc_pages_slowpath()
4399 * Do not retry costly high order allocations unless they are in __alloc_pages_slowpath()
4411 * It doesn't make any sense to retry for the compaction if the order-0 in __alloc_pages_slowpath()
4471 * Help non-failing allocations by giving some access to memory in __alloc_pages_slowpath()
4472 * reserves normally used for high priority non-blocking in __alloc_pages_slowpath()
4485 warn_alloc(gfp_mask, ac->nodemask, in __alloc_pages_slowpath()
4496 ac->highest_zoneidx = gfp_zone(gfp_mask); in prepare_alloc_pages()
4497 ac->zonelist = node_zonelist(preferred_nid, gfp_mask); in prepare_alloc_pages()
4498 ac->nodemask = nodemask; in prepare_alloc_pages()
4499 ac->migratetype = gfp_migratetype(gfp_mask); in prepare_alloc_pages()
4507 if (in_task() && !ac->nodemask) in prepare_alloc_pages()
4508 ac->nodemask = &cpuset_current_mems_allowed; in prepare_alloc_pages()
4521 ac->spread_dirty_pages = (gfp_mask & __GFP_WRITE); in prepare_alloc_pages()
4528 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in prepare_alloc_pages()
4529 ac->highest_zoneidx, ac->nodemask); in prepare_alloc_pages()
4535 * __alloc_pages_bulk - Allocate a number of order-0 pages to an array
4557 struct zoneref *z; in alloc_pages_bulk_noprof() local
4577 if (unlikely(nr_pages - nr_populated == 0)) in alloc_pages_bulk_noprof()
4585 if (nr_pages - nr_populated == 1) in alloc_pages_bulk_noprof()
4608 z = ac.preferred_zoneref; in alloc_pages_bulk_noprof()
4609 for_next_zone_zonelist_nodemask(zone, z, ac.highest_zoneidx, ac.nodemask) { in alloc_pages_bulk_noprof()
4650 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in alloc_pages_bulk_noprof()
4655 pcp_list = &pcp->lists[order_to_pindex(ac.migratetype, 0)]; in alloc_pages_bulk_noprof()
4749 * &cpuset_current_mems_allowed to optimize the fast-path attempt. in __alloc_frozen_pages_noprof()
4793 * you need to access high mem.
4813 * __free_pages - Free pages allocated with alloc_pages().
4817 * This function can free multi-page allocations that are not compound
4823 * by put_page() which only frees the first page of a non-compound
4841 pgalloc_tag_sub_pages(tag, (1 << order) - 1); in __free_pages()
4842 while (order-- > 0) in __free_pages()
4869 while (page < --last) in make_alloc_exact()
4880 * alloc_pages_exact - allocate an exact number physically-contiguous pages.
4886 * allocate memory in power-of-two pages.
4908 * alloc_pages_exact_nid - allocate an exact number of physically-contiguous
4934 * free_pages_exact - release memory allocated via alloc_pages_exact()
4953 * nr_free_zone_pages - count number of pages beyond high watermark
4957 * high watermark within all zones at or below a given zone index. For each
4960 * nr_free_zone_pages = managed_pages - high_pages
4962 * Return: number of pages beyond high watermark.
4966 struct zoneref *z; in nr_free_zone_pages() local
4974 for_each_zone_zonelist(zone, z, zonelist, offset) { in nr_free_zone_pages()
4976 unsigned long high = high_wmark_pages(zone); in nr_free_zone_pages() local
4977 if (size > high) in nr_free_zone_pages()
4978 sum += size - high; in nr_free_zone_pages()
4985 * nr_free_buffer_pages - count number of pages beyond high watermark
4987 * nr_free_buffer_pages() counts the number of pages which are beyond the high
4990 * Return: number of pages beyond high watermark within ZONE_DMA and
5001 zoneref->zone = zone; in zoneref_set_zone()
5002 zoneref->zone_idx = zone_idx(zone); in zoneref_set_zone()
5017 zone_type--; in build_zonerefs_node()
5018 zone = pgdat->node_zones + zone_type; in build_zonerefs_node()
5040 return -EINVAL; in __parse_numa_zonelist_order()
5061 * find_next_best_node - find the next node that should appear in a given node's fallback list
5125 * This results in maximum locality--normal zone overflows into local
5126 * DMA zone, if any--but risks exhausting DMA zone.
5134 zonerefs = pgdat->node_zonelists[ZONELIST_FALLBACK]._zonerefs; in build_zonelists_in_node_order()
5144 zonerefs->zone = NULL; in build_zonelists_in_node_order()
5145 zonerefs->zone_idx = 0; in build_zonelists_in_node_order()
5156 zonerefs = pgdat->node_zonelists[ZONELIST_NOFALLBACK]._zonerefs; in build_thisnode_zonelists()
5159 zonerefs->zone = NULL; in build_thisnode_zonelists()
5160 zonerefs->zone_idx = 0; in build_thisnode_zonelists()
5170 /* NUMA-aware ordering of nodes */ in build_zonelists()
5171 local_node = pgdat->node_id; in build_zonelists()
5179 * distance group to make it round-robin. in build_zonelists()
5206 struct zoneref *z; in local_memory_node() local
5208 z = first_zones_zonelist(node_zonelist(node, GFP_KERNEL), in local_memory_node()
5211 return zonelist_node_idx(z); in local_memory_node()
5224 zonerefs = pgdat->node_zonelists[ZONELIST_FALLBACK]._zonerefs; in build_zonelists()
5228 zonerefs->zone = NULL; in build_zonelists()
5229 zonerefs->zone_idx = 0; in build_zonelists()
5270 * trying to hold port->lock, for in __build_all_zonelists()
5272 * calling kmalloc(GFP_ATOMIC | __GFP_NOWARN) with port->lock held. in __build_all_zonelists()
5282 * building zonelists is fine - no need to touch other nodes. in __build_all_zonelists()
5284 if (self && !node_online(self->node_id)) { in __build_all_zonelists()
5299 * We now know the "local memory node" for each node-- in __build_all_zonelists()
5301 * Set up numa_mem percpu variable for on-line cpus. During in __build_all_zonelists()
5302 * boot, only the boot cpu should be on-line; we'll init the in __build_all_zonelists()
5303 * secondary cpus' numa_mem as they come on-line. During in __build_all_zonelists()
5304 * node/memory hotplug, we'll fixup all on-line cpus. in __build_all_zonelists()
5333 * (a chicken-egg dilemma). in build_all_zonelists_init()
5358 /* Get the number of free pages beyond high watermark in all zones. */ in build_all_zonelists()
5363 * more accurate, but expensive to check per-zone. This check is in build_all_zonelists()
5364 * made on memory-hotadd so a system can start with mobility in build_all_zonelists()
5398 * Clamp the batch to a 2^n - 1 value. Having a power in zone_batchsize()
5407 batch = rounddown_pow_of_two(batch + batch/2) - 1; in zone_batchsize()
5423 * fragmented and becoming unavailable for high-order allocations. in zone_batchsize()
5434 int high; in zone_highsize() local
5440 * By default, the high value of the pcp is based on the zone in zone_highsize()
5447 * If percpu_pagelist_high_fraction is configured, the high in zone_highsize()
5455 * Split the high value across all online CPUs local to the zone. Note in zone_highsize()
5458 * onlined. For memory nodes that have no CPUs, split the high value in zone_highsize()
5465 high = total_pages / nr_split_cpus; in zone_highsize()
5468 * Ensure high is at least batch*4. The multiple is based on the in zone_highsize()
5469 * historical relationship between high and batch. in zone_highsize()
5471 high = max(high, batch << 2); in zone_highsize()
5473 return high; in zone_highsize()
5480 * pcp->high and pcp->batch values are related and generally batch is lower
5481 * than high. They are also related to pcp->count such that count is lower
5482 * than high, and as soon as it reaches high, the pcplist is flushed.
5487 * store tearing. Any new users of pcp->batch, pcp->high_min and pcp->high_max
5489 * fully trust only the pcp->count field on the local CPU with interrupts
5499 WRITE_ONCE(pcp->batch, batch); in pageset_update()
5500 WRITE_ONCE(pcp->high_min, high_min); in pageset_update()
5501 WRITE_ONCE(pcp->high_max, high_max); in pageset_update()
5511 spin_lock_init(&pcp->lock); in per_cpu_pages_init()
5513 INIT_LIST_HEAD(&pcp->lists[pindex]); in per_cpu_pages_init()
5516 * Set batch and high values safe for a boot pageset. A true percpu in per_cpu_pages_init()
5521 pcp->high_min = BOOT_PAGESET_HIGH; in per_cpu_pages_init()
5522 pcp->high_max = BOOT_PAGESET_HIGH; in per_cpu_pages_init()
5523 pcp->batch = BOOT_PAGESET_BATCH; in per_cpu_pages_init()
5524 pcp->free_count = 0; in per_cpu_pages_init()
5534 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in __zone_set_pageset_high_and_batch()
5540 * Calculate and set new high and batch values for all per-cpu pagesets of a
5552 * PCP high is tuned manually, disable auto-tuning via in zone_set_pageset_high_and_batch()
5562 if (zone->pageset_high_min == new_high_min && in zone_set_pageset_high_and_batch()
5563 zone->pageset_high_max == new_high_max && in zone_set_pageset_high_and_batch()
5564 zone->pageset_batch == new_batch) in zone_set_pageset_high_and_batch()
5567 zone->pageset_high_min = new_high_min; in zone_set_pageset_high_and_batch()
5568 zone->pageset_high_max = new_high_max; in zone_set_pageset_high_and_batch()
5569 zone->pageset_batch = new_batch; in zone_set_pageset_high_and_batch()
5581 zone->per_cpu_zonestats = alloc_percpu(struct per_cpu_zonestat); in setup_zone_pageset()
5583 zone->per_cpu_pageset = alloc_percpu(struct per_cpu_pages); in setup_zone_pageset()
5588 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in setup_zone_pageset()
5589 pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); in setup_zone_pageset()
5598 * page high values need to be recalculated.
5612 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in zone_pcp_update_cacheinfo()
5615 * If data cache slice of CPU is large enough, "pcp->batch" in zone_pcp_update_cacheinfo()
5617 * consecutive high-order pages freeing without allocation. in zone_pcp_update_cacheinfo()
5619 * cache-hot pages sharing. in zone_pcp_update_cacheinfo()
5621 spin_lock(&pcp->lock); in zone_pcp_update_cacheinfo()
5622 if ((cci->per_cpu_data_slice_size >> PAGE_SHIFT) > 3 * pcp->batch) in zone_pcp_update_cacheinfo()
5623 pcp->flags |= PCPF_FREE_HIGH_BATCH; in zone_pcp_update_cacheinfo()
5625 pcp->flags &= ~PCPF_FREE_HIGH_BATCH; in zone_pcp_update_cacheinfo()
5626 spin_unlock(&pcp->lock); in zone_pcp_update_cacheinfo()
5659 memset(pzstats->vm_numa_event, 0, in setup_per_cpu_pageset()
5660 sizeof(pzstats->vm_numa_event)); in setup_per_cpu_pageset()
5665 pgdat->per_cpu_nodestats = in setup_per_cpu_pageset()
5676 zone->per_cpu_pageset = &boot_pageset; in zone_pcp_init()
5677 zone->per_cpu_zonestats = &boot_zonestats; in zone_pcp_init()
5678 zone->pageset_high_min = BOOT_PAGESET_HIGH; in zone_pcp_init()
5679 zone->pageset_high_max = BOOT_PAGESET_HIGH; in zone_pcp_init()
5680 zone->pageset_batch = BOOT_PAGESET_BATCH; in zone_pcp_init()
5683 pr_debug(" %s zone: %lu pages, LIFO batch:%u\n", zone->name, in zone_pcp_init()
5684 zone->present_pages, zone_batchsize(zone)); in zone_pcp_init()
5691 atomic_long_add(count, &page_zone(page)->managed_pages); in adjust_managed_page_count()
5717 * Perform a kasan-unchecked memset() since this memory in free_reserved_area()
5795 * calculate_totalreserve_pages - called when sysctl_lowmem_reserve_ratio
5806 pgdat->totalreserve_pages = 0; in calculate_totalreserve_pages()
5809 struct zone *zone = pgdat->node_zones + i; in calculate_totalreserve_pages()
5815 if (zone->lowmem_reserve[j] > max) in calculate_totalreserve_pages()
5816 max = zone->lowmem_reserve[j]; in calculate_totalreserve_pages()
5819 /* we treat the high watermark as reserved pages. */ in calculate_totalreserve_pages()
5825 pgdat->totalreserve_pages += max; in calculate_totalreserve_pages()
5834 * setup_per_zone_lowmem_reserve - called whenever
5845 for (i = 0; i < MAX_NR_ZONES - 1; i++) { in setup_per_zone_lowmem_reserve()
5846 struct zone *zone = &pgdat->node_zones[i]; in setup_per_zone_lowmem_reserve()
5852 struct zone *upper_zone = &pgdat->node_zones[j]; in setup_per_zone_lowmem_reserve()
5857 zone->lowmem_reserve[j] = 0; in setup_per_zone_lowmem_reserve()
5859 zone->lowmem_reserve[j] = managed_pages / ratio; in setup_per_zone_lowmem_reserve()
5870 unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10); in __setup_per_zone_wmarks()
5884 spin_lock_irqsave(&zone->lock, flags); in __setup_per_zone_wmarks()
5893 * The WMARK_HIGH-WMARK_LOW and (WMARK_LOW-WMARK_MIN) in __setup_per_zone_wmarks()
5901 zone->_watermark[WMARK_MIN] = min_pages; in __setup_per_zone_wmarks()
5907 zone->_watermark[WMARK_MIN] = tmp; in __setup_per_zone_wmarks()
5919 zone->watermark_boost = 0; in __setup_per_zone_wmarks()
5920 zone->_watermark[WMARK_LOW] = min_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
5921 zone->_watermark[WMARK_HIGH] = low_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
5922 zone->_watermark[WMARK_PROMO] = high_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
5924 spin_unlock_irqrestore(&zone->lock, flags); in __setup_per_zone_wmarks()
5932 * setup_per_zone_wmarks - called when min_free_kbytes changes
5933 * or when memory is hot-{added|removed}
5935 * Ensures that the watermark[min,low,high] values for each zone are set
5949 * and high limits or the limits may be inappropriate. in setup_per_zone_wmarks()
6014 * min_free_kbytes_sysctl_handler - just a wrapper around proc_dointvec() so in postcore_initcall()
6056 pgdat->min_unmapped_pages = 0; in setup_min_unmapped_ratio()
6059 zone->zone_pgdat->min_unmapped_pages += (zone_managed_pages(zone) * in setup_min_unmapped_ratio()
6084 pgdat->min_slab_pages = 0; in setup_min_slab_ratio()
6087 zone->zone_pgdat->min_slab_pages += (zone_managed_pages(zone) * in setup_min_slab_ratio()
6107 * lowmem_reserve_ratio_sysctl_handler - just a wrapper around
6132 * percpu_pagelist_high_fraction - changes the pcp->high for each zone on each
6154 ret = -EINVAL; in percpu_pagelist_high_fraction_sysctl_handler()
6245 /* Usage: See admin-guide/dynamic-debug-howto.rst */
6273 .nid = zone_to_nid(cc->zone), in __alloc_contig_migrate_range()
6274 .gfp_mask = cc->gfp_mask, in __alloc_contig_migrate_range()
6284 while (pfn < end || !list_empty(&cc->migratepages)) { in __alloc_contig_migrate_range()
6286 ret = -EINTR; in __alloc_contig_migrate_range()
6290 if (list_empty(&cc->migratepages)) { in __alloc_contig_migrate_range()
6291 cc->nr_migratepages = 0; in __alloc_contig_migrate_range()
6293 if (ret && ret != -EAGAIN) in __alloc_contig_migrate_range()
6295 pfn = cc->migrate_pfn; in __alloc_contig_migrate_range()
6298 ret = -EBUSY; in __alloc_contig_migrate_range()
6302 nr_reclaimed = reclaim_clean_pages_from_list(cc->zone, in __alloc_contig_migrate_range()
6303 &cc->migratepages); in __alloc_contig_migrate_range()
6304 cc->nr_migratepages -= nr_reclaimed; in __alloc_contig_migrate_range()
6308 list_for_each_entry(page, &cc->migratepages, lru) { in __alloc_contig_migrate_range()
6316 ret = migrate_pages(&cc->migratepages, alloc_migration_target, in __alloc_contig_migrate_range()
6317 NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE, NULL); in __alloc_contig_migrate_range()
6320 total_migrated += cc->nr_migratepages; in __alloc_contig_migrate_range()
6323 * On -ENOMEM, migrate_pages() bails out right away. It is pointless in __alloc_contig_migrate_range()
6326 if (ret == -ENOMEM) in __alloc_contig_migrate_range()
6332 if (!(cc->gfp_mask & __GFP_NOWARN) && ret == -EBUSY) in __alloc_contig_migrate_range()
6333 alloc_contig_dump_pages(&cc->migratepages); in __alloc_contig_migrate_range()
6334 putback_movable_pages(&cc->migratepages); in __alloc_contig_migrate_range()
6362 /* Add all subpages to the order-0 head, in sequence. */ in split_free_pages()
6363 list_del(&page->lru); in split_free_pages()
6389 return -EINVAL; in __alloc_contig_verify_gfp_mask()
6405 * alloc_contig_range() -- tries to allocate given range of pages
6407 * @end: one-past-the-last PFN to allocate
6435 .order = -1, in alloc_contig_range_noprof()
6446 return -EINVAL; in alloc_contig_range_noprof()
6476 * In case of -EBUSY, we'd like to know which page causes problem. in alloc_contig_range_noprof()
6483 * -EBUSY is not accidentally used or returned to caller. in alloc_contig_range_noprof()
6486 if (ret && ret != -EBUSY) in alloc_contig_range_noprof()
6490 * When in-use hugetlb pages are migrated, they may simply be released in alloc_contig_range_noprof()
6492 * buddy system. After the migration of in-use huge pages is completed, in alloc_contig_range_noprof()
6513 * We don't have to hold zone->lock here because the pages are in alloc_contig_range_noprof()
6520 ret = -EBUSY; in alloc_contig_range_noprof()
6527 ret = -EBUSY; in alloc_contig_range_noprof()
6536 free_contig_range(outer_start, start - outer_start); in alloc_contig_range_noprof()
6538 free_contig_range(end, outer_end - end); in alloc_contig_range_noprof()
6539 } else if (start == outer_start && end == outer_end && is_power_of_2(end - start)) { in alloc_contig_range_noprof()
6541 int order = ilog2(end - start); in alloc_contig_range_noprof()
6547 ret = -EINVAL; in alloc_contig_range_noprof()
6566 static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn, in pfn_range_valid_contig() argument
6577 if (page_zone(page) != z) in pfn_range_valid_contig()
6592 unsigned long last_pfn = start_pfn + nr_pages - 1; in zone_spans_last_pfn()
6598 * alloc_contig_pages() -- tries to find and allocate contiguous range of pages
6626 struct zoneref *z; in alloc_contig_pages_noprof() local
6629 for_each_zone_zonelist_nodemask(zone, z, zonelist, in alloc_contig_pages_noprof()
6631 spin_lock_irqsave(&zone->lock, flags); in alloc_contig_pages_noprof()
6633 pfn = ALIGN(zone->zone_start_pfn, nr_pages); in alloc_contig_pages_noprof()
6643 spin_unlock_irqrestore(&zone->lock, flags); in alloc_contig_pages_noprof()
6648 spin_lock_irqsave(&zone->lock, flags); in alloc_contig_pages_noprof()
6652 spin_unlock_irqrestore(&zone->lock, flags); in alloc_contig_pages_noprof()
6674 for (; nr_pages--; pfn++) { in free_contig_range()
6685 * Effectively disable pcplists for the zone by setting the high limit to 0
6688 * will be drained, or observe the new high limit and skip the pcplist.
6701 __zone_set_pageset_high_and_batch(zone, zone->pageset_high_min, in zone_pcp_enable()
6702 zone->pageset_high_max, zone->pageset_batch); in zone_pcp_enable()
6711 if (zone->per_cpu_pageset != &boot_pageset) { in zone_pcp_reset()
6713 pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); in zone_pcp_reset()
6716 free_percpu(zone->per_cpu_pageset); in zone_pcp_reset()
6717 zone->per_cpu_pageset = &boot_pageset; in zone_pcp_reset()
6718 if (zone->per_cpu_zonestats != &boot_zonestats) { in zone_pcp_reset()
6719 free_percpu(zone->per_cpu_zonestats); in zone_pcp_reset()
6720 zone->per_cpu_zonestats = &boot_zonestats; in zone_pcp_reset()
6730 * Returns the number of managed (non-PageOffline()) pages in the range: the
6745 spin_lock_irqsave(&zone->lock, flags); in __offline_isolated_pages()
6775 spin_unlock_irqrestore(&zone->lock, flags); in __offline_isolated_pages()
6777 return end_pfn - start_pfn - already_offline; in __offline_isolated_pages()
6790 const struct page *head = page - (pfn & ((1 << order) - 1)); in is_free_buddy_page()
6811 * Break down a higher-order page in sub-pages, and keep our target out of
6815 struct page *target, int low, int high, in break_down_buddy_pages() argument
6818 unsigned long size = 1 << high; in break_down_buddy_pages()
6821 while (high > low) { in break_down_buddy_pages()
6822 high--; in break_down_buddy_pages()
6832 if (set_page_guard(zone, current_buddy, high)) in break_down_buddy_pages()
6835 add_to_free_list(current_buddy, zone, high, migratetype, false); in break_down_buddy_pages()
6836 set_buddy_order(current_buddy, high); in break_down_buddy_pages()
6851 spin_lock_irqsave(&zone->lock, flags); in take_page_off_buddy()
6853 struct page *page_head = page - (pfn & ((1 << order) - 1)); in take_page_off_buddy()
6872 spin_unlock_irqrestore(&zone->lock, flags); in take_page_off_buddy()
6885 spin_lock_irqsave(&zone->lock, flags); in put_page_back_buddy()
6896 spin_unlock_irqrestore(&zone->lock, flags); in put_page_back_buddy()
6908 struct zone *zone = &pgdat->node_zones[ZONE_DMA]; in has_managed_dma()
6933 return -EINVAL; in accept_memory_parse()
6950 list_del(&page->lru); in __accept_page()
6951 last = list_empty(&zone->unaccepted_pages); in __accept_page()
6953 account_freepages(zone, -MAX_ORDER_NR_PAGES, MIGRATE_MOVABLE); in __accept_page()
6954 __mod_zone_page_state(zone, NR_UNACCEPTED, -MAX_ORDER_NR_PAGES); in __accept_page()
6956 spin_unlock_irqrestore(&zone->lock, *flags); in __accept_page()
6971 spin_lock_irqsave(&zone->lock, flags); in accept_page()
6973 spin_unlock_irqrestore(&zone->lock, flags); in accept_page()
6977 /* Unlocks zone->lock */ in accept_page()
6986 spin_lock_irqsave(&zone->lock, flags); in try_to_accept_memory_one()
6987 page = list_first_entry_or_null(&zone->unaccepted_pages, in try_to_accept_memory_one()
6990 spin_unlock_irqrestore(&zone->lock, flags); in try_to_accept_memory_one()
6994 /* Unlocks zone->lock */ in try_to_accept_memory_one()
7013 if (list_empty(&zone->unaccepted_pages)) in cond_accept_memory()
7027 to_accept = wmark - in cond_accept_memory()
7028 (zone_page_state(zone, NR_FREE_PAGES) - in cond_accept_memory()
7029 __zone_watermark_unusable_free(zone, order, 0) - in cond_accept_memory()
7036 to_accept -= MAX_ORDER_NR_PAGES; in cond_accept_memory()
7051 spin_lock_irqsave(&zone->lock, flags); in __free_unaccepted()
7052 first = list_empty(&zone->unaccepted_pages); in __free_unaccepted()
7053 list_add_tail(&page->lru, &zone->unaccepted_pages); in __free_unaccepted()
7057 spin_unlock_irqrestore(&zone->lock, flags); in __free_unaccepted()