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. */
1256 spin_lock_irqsave(&zone->lock, flags); in free_one_page()
1258 spin_unlock_irqrestore(&zone->lock, flags); in free_one_page()
1298 * unmap it; some archs don't like double-unmappings, so in __free_pages_core()
1310 atomic_long_add(nr_pages, &page_zone(page)->managed_pages); in __free_pages_core()
1342 * Note: the function may return non-NULL struct page even for a page block
1345 * will fall into 2 sub-sections, and the end pfn of the pageblock may be hole
1358 end_pfn--; in __pageblock_pfn_to_page()
1391 * -- nyc
1394 int high, int migratetype) in expand() argument
1396 unsigned int size = 1 << high; in expand()
1399 while (high > low) { in expand()
1400 high--; in expand()
1410 if (set_page_guard(zone, &page[size], high)) in expand()
1413 __add_to_free_list(&page[size], zone, high, migratetype, false); in expand()
1414 set_buddy_order(&page[size], high); in expand()
1423 int high, int migratetype) in page_del_and_expand() argument
1425 int nr_pages = 1 << high; in page_del_and_expand()
1427 __del_page_from_free_list(page, zone, high, migratetype); in page_del_and_expand()
1428 nr_pages -= expand(zone, page, low, high, migratetype); in page_del_and_expand()
1429 account_freepages(zone, -nr_pages, migratetype); in page_del_and_expand()
1434 if (unlikely(page->flags & __PG_HWPOISON)) { in check_new_page_bad()
1479 /* Skip, if hardware tag-based KASAN is not enabled. */ in should_skip_kasan_unpoison()
1484 * With hardware tag-based KASAN enabled, skip if this has been in should_skip_kasan_unpoison()
1492 /* Don't skip, if hardware tag-based KASAN is not enabled. */ in should_skip_init()
1496 /* For hardware tag-based KASAN, skip if requested. */ in should_skip_init()
1595 area = &(zone->free_area[current_order]); in __rmqueue_smallest()
1618 static int fallbacks[MIGRATE_PCPTYPES][MIGRATE_PCPTYPES - 1] = {
1647 VM_WARN_ON(start_pfn & (pageblock_nr_pages - 1)); in __move_freepages_block()
1693 if (!zone_spans_pfn(zone, end - 1)) in prep_move_freepages_block()
1730 return -1; in move_freepages_block()
1761 * move_freepages_block_isolate - move free pages in block for page isolation
1825 int nr_pageblocks = 1 << (start_order - pageblock_order); in change_pageblock_range()
1827 while (nr_pageblocks--) { in change_pageblock_range()
1881 max_boost = mult_frac(zone->_watermark[WMARK_HIGH], in boost_watermark()
1885 * high watermark may be uninitialised if fragmentation occurs in boost_watermark()
1897 zone->watermark_boost = min(zone->watermark_boost + pageblock_nr_pages, in boost_watermark()
1946 set_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); in steal_suitable_fallback()
1967 * to MOVABLE pageblock, consider all non-movable pages as in steal_suitable_fallback()
1970 * exact migratetype of non-movable pages. in steal_suitable_fallback()
1974 - (free_pages + movable_pages); in steal_suitable_fallback()
1982 if (free_pages + alike_pages >= (1 << (pageblock_order-1)) || in steal_suitable_fallback()
2005 if (area->nr_free == 0) in find_suitable_fallback()
2006 return -1; in find_suitable_fallback()
2009 for (i = 0; i < MIGRATE_PCPTYPES - 1 ; i++) { in find_suitable_fallback()
2024 return -1; in find_suitable_fallback()
2029 * exclusive use of high-order atomic allocations if there are no
2042 * Check is race-prone but harmless. in reserve_highatomic_pageblock()
2047 if (zone->nr_reserved_highatomic >= max_managed) in reserve_highatomic_pageblock()
2050 spin_lock_irqsave(&zone->lock, flags); in reserve_highatomic_pageblock()
2053 if (zone->nr_reserved_highatomic >= max_managed) in reserve_highatomic_pageblock()
2063 if (move_freepages_block(zone, page, mt, MIGRATE_HIGHATOMIC) == -1) in reserve_highatomic_pageblock()
2065 zone->nr_reserved_highatomic += pageblock_nr_pages; in reserve_highatomic_pageblock()
2068 zone->nr_reserved_highatomic += 1 << order; in reserve_highatomic_pageblock()
2072 spin_unlock_irqrestore(&zone->lock, flags); in reserve_highatomic_pageblock()
2077 * potentially hurts the reliability of high-order allocations when under
2087 struct zonelist *zonelist = ac->zonelist; in unreserve_highatomic_pageblock()
2089 struct zoneref *z; in unreserve_highatomic_pageblock() local
2095 for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->highest_zoneidx, in unreserve_highatomic_pageblock()
2096 ac->nodemask) { in unreserve_highatomic_pageblock()
2099 * is really high. in unreserve_highatomic_pageblock()
2101 if (!force && zone->nr_reserved_highatomic <= in unreserve_highatomic_pageblock()
2105 spin_lock_irqsave(&zone->lock, flags); in unreserve_highatomic_pageblock()
2107 struct free_area *area = &(zone->free_area[order]); in unreserve_highatomic_pageblock()
2119 * from highatomic to ac->migratetype. So we should in unreserve_highatomic_pageblock()
2126 * locking could inadvertently allow a per-cpu in unreserve_highatomic_pageblock()
2132 size = min(size, zone->nr_reserved_highatomic); in unreserve_highatomic_pageblock()
2133 zone->nr_reserved_highatomic -= size; in unreserve_highatomic_pageblock()
2137 * Convert to ac->migratetype and avoid the normal in unreserve_highatomic_pageblock()
2147 ac->migratetype); in unreserve_highatomic_pageblock()
2150 ac->migratetype); in unreserve_highatomic_pageblock()
2152 ac->migratetype); in unreserve_highatomic_pageblock()
2159 WARN_ON_ONCE(ret == -1); in unreserve_highatomic_pageblock()
2161 spin_unlock_irqrestore(&zone->lock, flags); in unreserve_highatomic_pageblock()
2165 spin_unlock_irqrestore(&zone->lock, flags); in unreserve_highatomic_pageblock()
2206 --current_order) { in __rmqueue_fallback()
2207 area = &(zone->free_area[current_order]); in __rmqueue_fallback()
2210 if (fallback_mt == -1) in __rmqueue_fallback()
2232 area = &(zone->free_area[current_order]); in __rmqueue_fallback()
2235 if (fallback_mt != -1) in __rmqueue_fallback()
2240 * This should not happen - we already found a suitable fallback in __rmqueue_fallback()
2260 * Call me with the zone->lock already held.
2307 spin_lock_irqsave(&zone->lock, flags); in rmqueue_bulk()
2324 list_add_tail(&page->pcp_list, list); in rmqueue_bulk()
2326 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_bulk()
2332 * Called from the vmstat counter updater to decay the PCP high.
2340 high_min = READ_ONCE(pcp->high_min); in decay_pcp_high()
2341 batch = READ_ONCE(pcp->batch); in decay_pcp_high()
2343 * Decrease pcp->high periodically to try to free possible in decay_pcp_high()
2345 * control latency. This caps pcp->high decrement too. in decay_pcp_high()
2347 if (pcp->high > high_min) { in decay_pcp_high()
2348 pcp->high = max3(pcp->count - (batch << CONFIG_PCP_BATCH_SCALE_MAX), in decay_pcp_high()
2349 pcp->high - (pcp->high >> 3), high_min); in decay_pcp_high()
2350 if (pcp->high > high_min) in decay_pcp_high()
2354 to_drain = pcp->count - pcp->high; in decay_pcp_high()
2356 spin_lock(&pcp->lock); in decay_pcp_high()
2358 spin_unlock(&pcp->lock); in decay_pcp_high()
2375 batch = READ_ONCE(pcp->batch); in drain_zone_pages()
2376 to_drain = min(pcp->count, batch); in drain_zone_pages()
2378 spin_lock(&pcp->lock); in drain_zone_pages()
2380 spin_unlock(&pcp->lock); in drain_zone_pages()
2390 struct per_cpu_pages *pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in drain_pages_zone()
2394 spin_lock(&pcp->lock); in drain_pages_zone()
2395 count = pcp->count; in drain_pages_zone()
2398 pcp->batch << CONFIG_PCP_BATCH_SCALE_MAX); in drain_pages_zone()
2401 count -= to_drain; in drain_pages_zone()
2403 spin_unlock(&pcp->lock); in drain_pages_zone()
2420 * Spill all of this CPU's per-cpu pages back into the buddy allocator.
2437 * not empty. The check for non-emptiness can however race with a free to
2438 * pcplist that has not yet increased the pcp->count from 0 to 1. Callers
2471 struct zone *z; in __drain_all_pages() local
2481 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in __drain_all_pages()
2482 if (pcp->count) in __drain_all_pages()
2485 for_each_populated_zone(z) { in __drain_all_pages()
2486 pcp = per_cpu_ptr(z->per_cpu_pageset, cpu); in __drain_all_pages()
2487 if (pcp->count) { in __drain_all_pages()
2511 * Spill all the per-cpu pages from all CPUs back into the buddy allocator.
2513 * When zone parameter is non-NULL, spill just the single zone's pages.
2520 static int nr_pcp_free(struct per_cpu_pages *pcp, int batch, int high, bool free_high) in nr_pcp_free() argument
2524 /* Free as much as possible if batch freeing high-order pages. */ in nr_pcp_free()
2526 return min(pcp->count, batch << CONFIG_PCP_BATCH_SCALE_MAX); in nr_pcp_free()
2529 if (unlikely(high < batch)) in nr_pcp_free()
2532 /* Leave at least pcp->batch pages on the list */ in nr_pcp_free()
2534 max_nr_free = high - batch; in nr_pcp_free()
2540 batch = clamp_t(int, pcp->free_count, min_nr_free, max_nr_free); in nr_pcp_free()
2548 int high, high_min, high_max; in nr_pcp_high() local
2550 high_min = READ_ONCE(pcp->high_min); in nr_pcp_high()
2551 high_max = READ_ONCE(pcp->high_max); in nr_pcp_high()
2552 high = pcp->high = clamp(pcp->high, high_min, high_max); in nr_pcp_high()
2554 if (unlikely(!high)) in nr_pcp_high()
2558 pcp->high = max(high - (batch << CONFIG_PCP_BATCH_SCALE_MAX), in nr_pcp_high()
2567 if (test_bit(ZONE_RECLAIM_ACTIVE, &zone->flags)) { in nr_pcp_high()
2568 int free_count = max_t(int, pcp->free_count, batch); in nr_pcp_high()
2570 pcp->high = max(high - free_count, high_min); in nr_pcp_high()
2571 return min(batch << 2, pcp->high); in nr_pcp_high()
2575 return high; in nr_pcp_high()
2577 if (test_bit(ZONE_BELOW_HIGH, &zone->flags)) { in nr_pcp_high()
2578 int free_count = max_t(int, pcp->free_count, batch); in nr_pcp_high()
2580 pcp->high = max(high - free_count, high_min); in nr_pcp_high()
2581 high = max(pcp->count, high_min); in nr_pcp_high()
2582 } else if (pcp->count >= high) { in nr_pcp_high()
2583 int need_high = pcp->free_count + batch; in nr_pcp_high()
2585 /* pcp->high should be large enough to hold batch freed pages */ in nr_pcp_high()
2586 if (pcp->high < need_high) in nr_pcp_high()
2587 pcp->high = clamp(need_high, high_min, high_max); in nr_pcp_high()
2590 return high; in nr_pcp_high()
2597 int high, batch; in free_unref_page_commit() local
2606 pcp->alloc_factor >>= 1; in free_unref_page_commit()
2609 list_add(&page->pcp_list, &pcp->lists[pindex]); in free_unref_page_commit()
2610 pcp->count += 1 << order; in free_unref_page_commit()
2612 batch = READ_ONCE(pcp->batch); in free_unref_page_commit()
2614 * As high-order pages other than THP's stored on PCP can contribute in free_unref_page_commit()
2620 free_high = (pcp->free_count >= batch && in free_unref_page_commit()
2621 (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) && in free_unref_page_commit()
2622 (!(pcp->flags & PCPF_FREE_HIGH_BATCH) || in free_unref_page_commit()
2623 pcp->count >= READ_ONCE(batch))); in free_unref_page_commit()
2624 pcp->flags |= PCPF_PREV_FREE_HIGH_ORDER; in free_unref_page_commit()
2625 } else if (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) { in free_unref_page_commit()
2626 pcp->flags &= ~PCPF_PREV_FREE_HIGH_ORDER; in free_unref_page_commit()
2628 if (pcp->free_count < (batch << CONFIG_PCP_BATCH_SCALE_MAX)) in free_unref_page_commit()
2629 pcp->free_count += (1 << order); in free_unref_page_commit()
2630 high = nr_pcp_high(pcp, zone, batch, free_high); in free_unref_page_commit()
2631 if (pcp->count >= high) { in free_unref_page_commit()
2632 free_pcppages_bulk(zone, nr_pcp_free(pcp, batch, high, free_high), in free_unref_page_commit()
2634 if (test_bit(ZONE_BELOW_HIGH, &zone->flags) && in free_unref_page_commit()
2637 clear_bit(ZONE_BELOW_HIGH, &zone->flags); in free_unref_page_commit()
2678 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in free_unref_page()
2699 for (i = 0, j = 0; i < folios->nr; i++) { in free_unref_folios()
2700 struct folio *folio = folios->folios[i]; in free_unref_folios()
2704 if (!free_pages_prepare(&folio->page, order)) in free_unref_folios()
2711 free_one_page(folio_zone(folio), &folio->page, in free_unref_folios()
2715 folio->private = (void *)(unsigned long)order; in free_unref_folios()
2717 folios->folios[j] = folio; in free_unref_folios()
2720 folios->nr = j; in free_unref_folios()
2722 for (i = 0; i < folios->nr; i++) { in free_unref_folios()
2723 struct folio *folio = folios->folios[i]; in free_unref_folios()
2726 unsigned int order = (unsigned long)folio->private; in free_unref_folios()
2729 folio->private = NULL; in free_unref_folios()
2730 migratetype = get_pfnblock_migratetype(&folio->page, pfn); in free_unref_folios()
2747 free_one_page(zone, &folio->page, pfn, in free_unref_folios()
2757 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in free_unref_folios()
2760 free_one_page(zone, &folio->page, pfn, in free_unref_folios()
2768 * Non-isolated types over MIGRATE_PCPTYPES get added in free_unref_folios()
2774 trace_mm_page_free_batched(&folio->page); in free_unref_folios()
2775 free_unref_page_commit(zone, pcp, &folio->page, migratetype, in free_unref_folios()
2787 * split_page takes a non-compound higher-order page, and splits it into
2788 * n (1<<order) sub-pages: page[0..n]
2789 * Each sub-page must be freed individually.
2818 * emulate a high-order watermark check with a raised order-0 in __isolate_free_page()
2819 * watermark, because we already know our high-order page in __isolate_free_page()
2822 watermark = zone->_watermark[WMARK_MIN] + (1UL << order); in __isolate_free_page()
2833 if (order >= pageblock_order - 1) { in __isolate_free_page()
2834 struct page *endpage = page + (1 << order) - 1; in __isolate_free_page()
2851 * __putback_isolated_page - Return a now-isolated page back where we got it
2864 lockdep_assert_held(&zone->lock); in __putback_isolated_page()
2874 static inline void zone_statistics(struct zone *preferred_zone, struct zone *z, in zone_statistics() argument
2884 if (zone_to_nid(z) != numa_node_id()) in zone_statistics()
2887 if (zone_to_nid(z) == zone_to_nid(preferred_zone)) in zone_statistics()
2888 __count_numa_events(z, NUMA_HIT, nr_account); in zone_statistics()
2890 __count_numa_events(z, NUMA_MISS, nr_account); in zone_statistics()
2893 __count_numa_events(z, local_stat, nr_account); in zone_statistics()
2907 spin_lock_irqsave(&zone->lock, flags); in rmqueue_buddy()
2915 * order-0 (atomic) allocs access to HIGHATOMIC in rmqueue_buddy()
2917 * high-order atomic allocation in the future. in rmqueue_buddy()
2923 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_buddy()
2927 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_buddy()
2938 int high, base_batch, batch, max_nr_alloc; in nr_pcp_alloc() local
2941 base_batch = READ_ONCE(pcp->batch); in nr_pcp_alloc()
2942 high_min = READ_ONCE(pcp->high_min); in nr_pcp_alloc()
2943 high_max = READ_ONCE(pcp->high_max); in nr_pcp_alloc()
2944 high = pcp->high = clamp(pcp->high, high_min, high_max); in nr_pcp_alloc()
2947 if (unlikely(high < base_batch)) in nr_pcp_alloc()
2953 batch = (base_batch << pcp->alloc_factor); in nr_pcp_alloc()
2956 * If we had larger pcp->high, we could avoid to allocate from in nr_pcp_alloc()
2959 if (high_min != high_max && !test_bit(ZONE_BELOW_HIGH, &zone->flags)) in nr_pcp_alloc()
2960 high = pcp->high = min(high + batch, high_max); in nr_pcp_alloc()
2963 max_nr_alloc = max(high - pcp->count - base_batch, base_batch); in nr_pcp_alloc()
2966 * subsequent allocation of order-0 pages without any freeing. in nr_pcp_alloc()
2969 pcp->alloc_factor < CONFIG_PCP_BATCH_SCALE_MAX) in nr_pcp_alloc()
2970 pcp->alloc_factor++; in nr_pcp_alloc()
2986 /* Remove page from the per-cpu list, caller must protect the list */
3005 pcp->count += alloced << order; in __rmqueue_pcplist()
3011 list_del(&page->pcp_list); in __rmqueue_pcplist()
3012 pcp->count -= 1 << order; in __rmqueue_pcplist()
3018 /* Lock and remove page from the per-cpu list */
3030 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in rmqueue_pcplist()
3041 pcp->free_count >>= 1; in rmqueue_pcplist()
3042 list = &pcp->lists[order_to_pindex(migratetype, order)]; in rmqueue_pcplist()
3055 * Use pcplists for THP or "cheap" high-order allocations.
3086 unlikely(test_bit(ZONE_BOOSTED_WATERMARK, &zone->flags))) { in rmqueue()
3087 clear_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); in rmqueue()
3095 static inline long __zone_watermark_unusable_free(struct zone *z, in __zone_watermark_unusable_free() argument
3098 long unusable_free = (1 << order) - 1; in __zone_watermark_unusable_free()
3105 unusable_free += READ_ONCE(z->nr_free_highatomic); in __zone_watermark_unusable_free()
3110 unusable_free += zone_page_state(z, NR_FREE_CMA_PAGES); in __zone_watermark_unusable_free()
3117 * Return true if free base pages are above 'mark'. For high-order checks it
3118 * will return true of the order-0 watermark is reached and there is at least
3122 bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, in __zone_watermark_ok() argument
3129 /* free_pages may go negative - that's OK */ in __zone_watermark_ok()
3130 free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); in __zone_watermark_ok()
3138 min -= min / 2; in __zone_watermark_ok()
3141 * Non-blocking allocations (e.g. GFP_ATOMIC) can in __zone_watermark_ok()
3143 * non-blocking allocations requests such as GFP_NOWAIT in __zone_watermark_ok()
3148 min -= min / 4; in __zone_watermark_ok()
3155 * makes during the free path will be small and short-lived. in __zone_watermark_ok()
3158 min -= min / 2; in __zone_watermark_ok()
3162 * Check watermarks for an order-0 allocation request. If these in __zone_watermark_ok()
3163 * are not met, then a high-order request also cannot go ahead in __zone_watermark_ok()
3166 if (free_pages <= min + z->lowmem_reserve[highest_zoneidx]) in __zone_watermark_ok()
3169 /* If this is an order-0 request then the watermark is fine */ in __zone_watermark_ok()
3173 /* For a high-order request, check at least one suitable page is free */ in __zone_watermark_ok()
3175 struct free_area *area = &z->free_area[o]; in __zone_watermark_ok()
3178 if (!area->nr_free) in __zone_watermark_ok()
3200 bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, in zone_watermark_ok() argument
3203 return __zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags, in zone_watermark_ok()
3204 zone_page_state(z, NR_FREE_PAGES)); in zone_watermark_ok()
3207 static inline bool zone_watermark_fast(struct zone *z, unsigned int order, in zone_watermark_fast() argument
3213 free_pages = zone_page_state(z, NR_FREE_PAGES); in zone_watermark_fast()
3216 * Fast check for order-0 only. If this fails then the reserves in zone_watermark_fast()
3224 reserved = __zone_watermark_unusable_free(z, 0, alloc_flags); in zone_watermark_fast()
3226 /* reserved may over estimate high-atomic reserves. */ in zone_watermark_fast()
3227 usable_free -= min(usable_free, reserved); in zone_watermark_fast()
3228 if (usable_free > mark + z->lowmem_reserve[highest_zoneidx]) in zone_watermark_fast()
3232 if (__zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags, in zone_watermark_fast()
3237 * Ignore watermark boosting for __GFP_HIGH order-0 allocations in zone_watermark_fast()
3242 if (unlikely(!order && (alloc_flags & ALLOC_MIN_RESERVE) && z->watermark_boost in zone_watermark_fast()
3244 mark = z->_watermark[WMARK_MIN]; in zone_watermark_fast()
3245 return __zone_watermark_ok(z, order, mark, highest_zoneidx, in zone_watermark_fast()
3252 bool zone_watermark_ok_safe(struct zone *z, unsigned int order, in zone_watermark_ok_safe() argument
3255 long free_pages = zone_page_state(z, NR_FREE_PAGES); in zone_watermark_ok_safe()
3257 if (z->percpu_drift_mark && free_pages < z->percpu_drift_mark) in zone_watermark_ok_safe()
3258 free_pages = zone_page_state_snapshot(z, NR_FREE_PAGES); in zone_watermark_ok_safe()
3260 return __zone_watermark_ok(z, order, mark, highest_zoneidx, 0, in zone_watermark_ok_safe()
3307 * the pointer is within zone->zone_pgdat->node_zones[]. Also assume in alloc_flags_nofragment()
3310 BUILD_BUG_ON(ZONE_NORMAL - ZONE_DMA32 != 1); in alloc_flags_nofragment()
3311 if (nr_online_nodes > 1 && !populated_zone(--zone)) in alloc_flags_nofragment()
3338 struct zoneref *z; in get_page_from_freelist() local
3350 z = ac->preferred_zoneref; in get_page_from_freelist()
3351 for_next_zone_zonelist_nodemask(zone, z, ac->highest_zoneidx, in get_page_from_freelist()
3352 ac->nodemask) { in get_page_from_freelist()
3366 * lowmem reserves and high watermark so that kswapd in get_page_from_freelist()
3371 * exceed the per-node dirty limit in the slowpath in get_page_from_freelist()
3377 * dirty-throttling and the flusher threads. in get_page_from_freelist()
3379 if (ac->spread_dirty_pages) { in get_page_from_freelist()
3380 if (last_pgdat != zone->zone_pgdat) { in get_page_from_freelist()
3381 last_pgdat = zone->zone_pgdat; in get_page_from_freelist()
3382 last_pgdat_dirty_ok = node_dirty_ok(zone->zone_pgdat); in get_page_from_freelist()
3390 zone != zonelist_zone(ac->preferred_zoneref)) { in get_page_from_freelist()
3398 local_nid = zonelist_node_idx(ac->preferred_zoneref); in get_page_from_freelist()
3408 * Detect whether the number of free pages is below high in get_page_from_freelist()
3409 * watermark. If so, we will decrease pcp->high and free in get_page_from_freelist()
3414 if (test_bit(ZONE_BELOW_HIGH, &zone->flags)) in get_page_from_freelist()
3419 ac->highest_zoneidx, alloc_flags, in get_page_from_freelist()
3423 set_bit(ZONE_BELOW_HIGH, &zone->flags); in get_page_from_freelist()
3428 ac->highest_zoneidx, alloc_flags, in get_page_from_freelist()
3449 !zone_allows_reclaim(zonelist_zone(ac->preferred_zoneref), zone)) in get_page_from_freelist()
3452 ret = node_reclaim(zone->zone_pgdat, gfp_mask, order); in get_page_from_freelist()
3463 ac->highest_zoneidx, alloc_flags)) in get_page_from_freelist()
3471 page = rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, in get_page_from_freelist()
3472 gfp_mask, alloc_flags, ac->migratetype); in get_page_from_freelist()
3477 * If this is a high-order atomic allocation then check in get_page_from_freelist()
3519 (current->flags & (PF_MEMALLOC | PF_EXITING))) in warn_alloc_show_mem()
3542 current->comm, &vaf, gfp_mask, &gfp_mask, in warn_alloc()
3577 .zonelist = ac->zonelist, in __alloc_pages_may_oom()
3578 .nodemask = ac->nodemask, in __alloc_pages_may_oom()
3598 * Go through the zonelist yet one more time, keep very high watermark in __alloc_pages_may_oom()
3611 if (current->flags & PF_DUMPCORE) in __alloc_pages_may_oom()
3627 if (ac->highest_zoneidx < ZONE_NORMAL) in __alloc_pages_may_oom()
3647 * Help non-failing allocations by giving them access to memory in __alloc_pages_may_oom()
3666 /* Try memory compaction for high-order allocations before reclaim */
3709 zone->compact_blockskip_flush = false; in __alloc_pages_direct_compact()
3745 * Compaction was skipped due to a lack of free order-0 in should_compact_retry()
3783 (*compact_priority)--; in should_compact_retry()
3808 struct zoneref *z; in should_compact_retry() local
3816 * Let's give them a good hope and keep retrying while the order-0 in should_compact_retry()
3819 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in should_compact_retry()
3820 ac->highest_zoneidx, ac->nodemask) { in should_compact_retry()
3822 ac->highest_zoneidx, alloc_flags)) in should_compact_retry()
3840 if (current->flags & PF_MEMALLOC) in __need_reclaim()
3927 progress = try_to_free_pages(ac->zonelist, order, gfp_mask, in __perform_reclaim()
3928 ac->nodemask); in __perform_reclaim()
3958 * pages are pinned on the per-cpu lists or in high alloc reserves. in __alloc_pages_direct_reclaim()
3976 struct zoneref *z; in wake_all_kswapds() local
3979 enum zone_type highest_zoneidx = ac->highest_zoneidx; in wake_all_kswapds()
3981 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, highest_zoneidx, in wake_all_kswapds()
3982 ac->nodemask) { in wake_all_kswapds()
3985 if (last_pgdat != zone->zone_pgdat) { in wake_all_kswapds()
3987 last_pgdat = zone->zone_pgdat; in wake_all_kswapds()
4027 * Ignore cpuset mems for non-blocking __GFP_HIGH (probably in gfp_to_alloc_flags()
4066 if (in_serving_softirq() && (current->flags & PF_MEMALLOC)) in __gfp_pfmemalloc_flags()
4069 if (current->flags & PF_MEMALLOC) in __gfp_pfmemalloc_flags()
4099 struct zoneref *z; in should_reclaim_retry() local
4104 * their order will become available due to high fragmentation so in should_reclaim_retry()
4122 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in should_reclaim_retry()
4123 ac->highest_zoneidx, ac->nodemask) { in should_reclaim_retry()
4142 ac->highest_zoneidx, alloc_flags, available); in should_reclaim_retry()
4143 trace_reclaim_retry_zone(z, order, reclaimable, in should_reclaim_retry()
4158 if (current->flags & PF_WQ_WORKER) in should_reclaim_retry()
4179 * This assumes that for all allocations, ac->nodemask can come only in check_retry_cpuset()
4184 if (cpusets_enabled() && ac->nodemask && in check_retry_cpuset()
4185 !cpuset_nodemask_valid_mems_allowed(ac->nodemask)) { in check_retry_cpuset()
4186 ac->nodemask = NULL; in check_retry_cpuset()
4225 * allocate greater than order-1 page units with __GFP_NOFAIL. in __alloc_pages_slowpath()
4238 WARN_ON_ONCE(current->flags & PF_MEMALLOC); in __alloc_pages_slowpath()
4258 * there was a cpuset modification and we are retrying - otherwise we in __alloc_pages_slowpath()
4259 * could end up iterating over non-eligible zones endlessly. in __alloc_pages_slowpath()
4261 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath()
4262 ac->highest_zoneidx, ac->nodemask); in __alloc_pages_slowpath()
4263 if (!zonelist_zone(ac->preferred_zoneref)) in __alloc_pages_slowpath()
4268 * any suitable zone to satisfy the request - e.g. non-movable in __alloc_pages_slowpath()
4272 struct zoneref *z = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath() local
4273 ac->highest_zoneidx, in __alloc_pages_slowpath()
4275 if (!zonelist_zone(z)) in __alloc_pages_slowpath()
4292 * that we have enough base pages and don't need to reclaim. For non- in __alloc_pages_slowpath()
4293 * movable high-order allocations, do that as well, as compaction will in __alloc_pages_slowpath()
4301 (order > 0 && ac->migratetype != MIGRATE_MOVABLE)) in __alloc_pages_slowpath()
4323 * - potentially very expensive because zones are far in __alloc_pages_slowpath()
4325 * bursty high order allocations, in __alloc_pages_slowpath()
4326 * - not guaranteed to help because isolate_freepages() in __alloc_pages_slowpath()
4329 * - unlikely to make entire pageblocks free on its in __alloc_pages_slowpath()
4357 * ignored. These allocations are high priority and system rather than in __alloc_pages_slowpath()
4361 ac->nodemask = NULL; in __alloc_pages_slowpath()
4362 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath()
4363 ac->highest_zoneidx, ac->nodemask); in __alloc_pages_slowpath()
4376 if (current->flags & PF_MEMALLOC) in __alloc_pages_slowpath()
4396 * Do not retry costly high order allocations unless they are in __alloc_pages_slowpath()
4408 * It doesn't make any sense to retry for the compaction if the order-0 in __alloc_pages_slowpath()
4468 * Help non-failing allocations by giving some access to memory in __alloc_pages_slowpath()
4469 * reserves normally used for high priority non-blocking in __alloc_pages_slowpath()
4482 warn_alloc(gfp_mask, ac->nodemask, in __alloc_pages_slowpath()
4493 ac->highest_zoneidx = gfp_zone(gfp_mask); in prepare_alloc_pages()
4494 ac->zonelist = node_zonelist(preferred_nid, gfp_mask); in prepare_alloc_pages()
4495 ac->nodemask = nodemask; in prepare_alloc_pages()
4496 ac->migratetype = gfp_migratetype(gfp_mask); in prepare_alloc_pages()
4504 if (in_task() && !ac->nodemask) in prepare_alloc_pages()
4505 ac->nodemask = &cpuset_current_mems_allowed; in prepare_alloc_pages()
4518 ac->spread_dirty_pages = (gfp_mask & __GFP_WRITE); in prepare_alloc_pages()
4525 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in prepare_alloc_pages()
4526 ac->highest_zoneidx, ac->nodemask); in prepare_alloc_pages()
4532 * __alloc_pages_bulk - Allocate a number of order-0 pages to a list or array
4559 struct zoneref *z; in alloc_pages_bulk_noprof() local
4579 if (unlikely(page_array && nr_pages - nr_populated == 0)) in alloc_pages_bulk_noprof()
4587 if (nr_pages - nr_populated == 1) in alloc_pages_bulk_noprof()
4610 z = ac.preferred_zoneref; in alloc_pages_bulk_noprof()
4611 for_next_zone_zonelist_nodemask(zone, z, ac.highest_zoneidx, ac.nodemask) { in alloc_pages_bulk_noprof()
4652 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in alloc_pages_bulk_noprof()
4657 pcp_list = &pcp->lists[order_to_pindex(ac.migratetype, 0)]; in alloc_pages_bulk_noprof()
4680 list_add(&page->lru, page_list); in alloc_pages_bulk_noprof()
4702 list_add(&page->lru, page_list); in alloc_pages_bulk_noprof()
4760 * &cpuset_current_mems_allowed to optimize the fast-path attempt. in __alloc_pages_noprof()
4792 * you need to access high mem.
4812 * __free_pages - Free pages allocated with alloc_pages().
4816 * This function can free multi-page allocations that are not compound
4822 * by put_page() which only frees the first page of a non-compound
4840 pgalloc_tag_sub_pages(tag, (1 << order) - 1); in __free_pages()
4841 while (order-- > 0) in __free_pages()
4859 * An arbitrary-length arbitrary-offset area of memory which resides
4866 * sk_buff->head, or to be used in the "frags" portion of skb_shared_info.
4879 nc->size = page ? PAGE_FRAG_CACHE_MAX_SIZE : PAGE_SIZE; in __page_frag_cache_refill()
4884 nc->va = page ? page_address(page) : NULL; in __page_frag_cache_refill()
4891 if (!nc->va) in page_frag_cache_drain()
4894 __page_frag_cache_drain(virt_to_head_page(nc->va), nc->pagecnt_bias); in page_frag_cache_drain()
4895 nc->va = NULL; in page_frag_cache_drain()
4916 if (unlikely(!nc->va)) { in __page_frag_alloc_align()
4924 size = nc->size; in __page_frag_alloc_align()
4932 nc->pfmemalloc = page_is_pfmemalloc(page); in __page_frag_alloc_align()
4933 nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; in __page_frag_alloc_align()
4934 nc->offset = size; in __page_frag_alloc_align()
4937 offset = nc->offset - fragsz; in __page_frag_alloc_align()
4939 page = virt_to_page(nc->va); in __page_frag_alloc_align()
4941 if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) in __page_frag_alloc_align()
4944 if (unlikely(nc->pfmemalloc)) { in __page_frag_alloc_align()
4951 size = nc->size; in __page_frag_alloc_align()
4957 nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; in __page_frag_alloc_align()
4958 offset = size - fragsz; in __page_frag_alloc_align()
4973 nc->pagecnt_bias--; in __page_frag_alloc_align()
4975 nc->offset = offset; in __page_frag_alloc_align()
4977 return nc->va + offset; in __page_frag_alloc_align()
5004 while (page < --last) in make_alloc_exact()
5015 * alloc_pages_exact - allocate an exact number physically-contiguous pages.
5021 * allocate memory in power-of-two pages.
5043 * alloc_pages_exact_nid - allocate an exact number of physically-contiguous
5069 * free_pages_exact - release memory allocated via alloc_pages_exact()
5088 * nr_free_zone_pages - count number of pages beyond high watermark
5092 * high watermark within all zones at or below a given zone index. For each
5095 * nr_free_zone_pages = managed_pages - high_pages
5097 * Return: number of pages beyond high watermark.
5101 struct zoneref *z; in nr_free_zone_pages() local
5109 for_each_zone_zonelist(zone, z, zonelist, offset) { in nr_free_zone_pages()
5111 unsigned long high = high_wmark_pages(zone); in nr_free_zone_pages() local
5112 if (size > high) in nr_free_zone_pages()
5113 sum += size - high; in nr_free_zone_pages()
5120 * nr_free_buffer_pages - count number of pages beyond high watermark
5122 * nr_free_buffer_pages() counts the number of pages which are beyond the high
5125 * Return: number of pages beyond high watermark within ZONE_DMA and
5136 zoneref->zone = zone; in zoneref_set_zone()
5137 zoneref->zone_idx = zone_idx(zone); in zoneref_set_zone()
5152 zone_type--; in build_zonerefs_node()
5153 zone = pgdat->node_zones + zone_type; in build_zonerefs_node()
5175 return -EINVAL; in __parse_numa_zonelist_order()
5196 * find_next_best_node - find the next node that should appear in a given node's fallback list
5260 * This results in maximum locality--normal zone overflows into local
5261 * DMA zone, if any--but risks exhausting DMA zone.
5269 zonerefs = pgdat->node_zonelists[ZONELIST_FALLBACK]._zonerefs; in build_zonelists_in_node_order()
5279 zonerefs->zone = NULL; in build_zonelists_in_node_order()
5280 zonerefs->zone_idx = 0; in build_zonelists_in_node_order()
5291 zonerefs = pgdat->node_zonelists[ZONELIST_NOFALLBACK]._zonerefs; in build_thisnode_zonelists()
5294 zonerefs->zone = NULL; in build_thisnode_zonelists()
5295 zonerefs->zone_idx = 0; in build_thisnode_zonelists()
5312 /* NUMA-aware ordering of nodes */ in build_zonelists()
5313 local_node = pgdat->node_id; in build_zonelists()
5321 * distance group to make it round-robin. in build_zonelists()
5348 struct zoneref *z; in local_memory_node() local
5350 z = first_zones_zonelist(node_zonelist(node, GFP_KERNEL), in local_memory_node()
5353 return zonelist_node_idx(z); in local_memory_node()
5366 zonerefs = pgdat->node_zonelists[ZONELIST_FALLBACK]._zonerefs; in build_zonelists()
5370 zonerefs->zone = NULL; in build_zonelists()
5371 zonerefs->zone_idx = 0; in build_zonelists()
5412 * trying to hold port->lock, for in __build_all_zonelists()
5414 * calling kmalloc(GFP_ATOMIC | __GFP_NOWARN) with port->lock held. in __build_all_zonelists()
5424 * building zonelists is fine - no need to touch other nodes. in __build_all_zonelists()
5426 if (self && !node_online(self->node_id)) { in __build_all_zonelists()
5441 * We now know the "local memory node" for each node-- in __build_all_zonelists()
5443 * Set up numa_mem percpu variable for on-line cpus. During in __build_all_zonelists()
5444 * boot, only the boot cpu should be on-line; we'll init the in __build_all_zonelists()
5445 * secondary cpus' numa_mem as they come on-line. During in __build_all_zonelists()
5446 * node/memory hotplug, we'll fixup all on-line cpus. in __build_all_zonelists()
5475 * (a chicken-egg dilemma). in build_all_zonelists_init()
5500 /* Get the number of free pages beyond high watermark in all zones. */ in build_all_zonelists()
5505 * more accurate, but expensive to check per-zone. This check is in build_all_zonelists()
5506 * made on memory-hotadd so a system can start with mobility in build_all_zonelists()
5540 * Clamp the batch to a 2^n - 1 value. Having a power in zone_batchsize()
5549 batch = rounddown_pow_of_two(batch + batch/2) - 1; in zone_batchsize()
5565 * fragmented and becoming unavailable for high-order allocations. in zone_batchsize()
5576 int high; in zone_highsize() local
5582 * By default, the high value of the pcp is based on the zone in zone_highsize()
5589 * If percpu_pagelist_high_fraction is configured, the high in zone_highsize()
5597 * Split the high value across all online CPUs local to the zone. Note in zone_highsize()
5600 * onlined. For memory nodes that have no CPUs, split the high value in zone_highsize()
5607 high = total_pages / nr_split_cpus; in zone_highsize()
5610 * Ensure high is at least batch*4. The multiple is based on the in zone_highsize()
5611 * historical relationship between high and batch. in zone_highsize()
5613 high = max(high, batch << 2); in zone_highsize()
5615 return high; in zone_highsize()
5622 * pcp->high and pcp->batch values are related and generally batch is lower
5623 * than high. They are also related to pcp->count such that count is lower
5624 * than high, and as soon as it reaches high, the pcplist is flushed.
5629 * store tearing. Any new users of pcp->batch, pcp->high_min and pcp->high_max
5631 * fully trust only the pcp->count field on the local CPU with interrupts
5641 WRITE_ONCE(pcp->batch, batch); in pageset_update()
5642 WRITE_ONCE(pcp->high_min, high_min); in pageset_update()
5643 WRITE_ONCE(pcp->high_max, high_max); in pageset_update()
5653 spin_lock_init(&pcp->lock); in per_cpu_pages_init()
5655 INIT_LIST_HEAD(&pcp->lists[pindex]); in per_cpu_pages_init()
5658 * Set batch and high values safe for a boot pageset. A true percpu in per_cpu_pages_init()
5663 pcp->high_min = BOOT_PAGESET_HIGH; in per_cpu_pages_init()
5664 pcp->high_max = BOOT_PAGESET_HIGH; in per_cpu_pages_init()
5665 pcp->batch = BOOT_PAGESET_BATCH; in per_cpu_pages_init()
5666 pcp->free_count = 0; in per_cpu_pages_init()
5676 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in __zone_set_pageset_high_and_batch()
5682 * Calculate and set new high and batch values for all per-cpu pagesets of a
5694 * PCP high is tuned manually, disable auto-tuning via in zone_set_pageset_high_and_batch()
5704 if (zone->pageset_high_min == new_high_min && in zone_set_pageset_high_and_batch()
5705 zone->pageset_high_max == new_high_max && in zone_set_pageset_high_and_batch()
5706 zone->pageset_batch == new_batch) in zone_set_pageset_high_and_batch()
5709 zone->pageset_high_min = new_high_min; in zone_set_pageset_high_and_batch()
5710 zone->pageset_high_max = new_high_max; in zone_set_pageset_high_and_batch()
5711 zone->pageset_batch = new_batch; in zone_set_pageset_high_and_batch()
5723 zone->per_cpu_zonestats = alloc_percpu(struct per_cpu_zonestat); in setup_zone_pageset()
5725 zone->per_cpu_pageset = alloc_percpu(struct per_cpu_pages); in setup_zone_pageset()
5730 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in setup_zone_pageset()
5731 pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); in setup_zone_pageset()
5740 * page high values need to be recalculated.
5754 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in zone_pcp_update_cacheinfo()
5757 * If data cache slice of CPU is large enough, "pcp->batch" in zone_pcp_update_cacheinfo()
5759 * consecutive high-order pages freeing without allocation. in zone_pcp_update_cacheinfo()
5761 * cache-hot pages sharing. in zone_pcp_update_cacheinfo()
5763 spin_lock(&pcp->lock); in zone_pcp_update_cacheinfo()
5764 if ((cci->per_cpu_data_slice_size >> PAGE_SHIFT) > 3 * pcp->batch) in zone_pcp_update_cacheinfo()
5765 pcp->flags |= PCPF_FREE_HIGH_BATCH; in zone_pcp_update_cacheinfo()
5767 pcp->flags &= ~PCPF_FREE_HIGH_BATCH; in zone_pcp_update_cacheinfo()
5768 spin_unlock(&pcp->lock); in zone_pcp_update_cacheinfo()
5801 memset(pzstats->vm_numa_event, 0, in setup_per_cpu_pageset()
5802 sizeof(pzstats->vm_numa_event)); in setup_per_cpu_pageset()
5807 pgdat->per_cpu_nodestats = in setup_per_cpu_pageset()
5818 zone->per_cpu_pageset = &boot_pageset; in zone_pcp_init()
5819 zone->per_cpu_zonestats = &boot_zonestats; in zone_pcp_init()
5820 zone->pageset_high_min = BOOT_PAGESET_HIGH; in zone_pcp_init()
5821 zone->pageset_high_max = BOOT_PAGESET_HIGH; in zone_pcp_init()
5822 zone->pageset_batch = BOOT_PAGESET_BATCH; in zone_pcp_init()
5825 pr_debug(" %s zone: %lu pages, LIFO batch:%u\n", zone->name, in zone_pcp_init()
5826 zone->present_pages, zone_batchsize(zone)); in zone_pcp_init()
5831 atomic_long_add(count, &page_zone(page)->managed_pages); in adjust_managed_page_count()
5856 * Perform a kasan-unchecked memset() since this memory in free_reserved_area()
5934 * calculate_totalreserve_pages - called when sysctl_lowmem_reserve_ratio
5945 pgdat->totalreserve_pages = 0; in calculate_totalreserve_pages()
5948 struct zone *zone = pgdat->node_zones + i; in calculate_totalreserve_pages()
5954 if (zone->lowmem_reserve[j] > max) in calculate_totalreserve_pages()
5955 max = zone->lowmem_reserve[j]; in calculate_totalreserve_pages()
5958 /* we treat the high watermark as reserved pages. */ in calculate_totalreserve_pages()
5964 pgdat->totalreserve_pages += max; in calculate_totalreserve_pages()
5973 * setup_per_zone_lowmem_reserve - called whenever
5984 for (i = 0; i < MAX_NR_ZONES - 1; i++) { in setup_per_zone_lowmem_reserve()
5985 struct zone *zone = &pgdat->node_zones[i]; in setup_per_zone_lowmem_reserve()
5991 struct zone *upper_zone = &pgdat->node_zones[j]; in setup_per_zone_lowmem_reserve()
5997 zone->lowmem_reserve[j] = 0; in setup_per_zone_lowmem_reserve()
5999 zone->lowmem_reserve[j] = managed_pages / ratio; in setup_per_zone_lowmem_reserve()
6010 unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10); in __setup_per_zone_wmarks()
6024 spin_lock_irqsave(&zone->lock, flags); in __setup_per_zone_wmarks()
6033 * The WMARK_HIGH-WMARK_LOW and (WMARK_LOW-WMARK_MIN) in __setup_per_zone_wmarks()
6041 zone->_watermark[WMARK_MIN] = min_pages; in __setup_per_zone_wmarks()
6047 zone->_watermark[WMARK_MIN] = tmp; in __setup_per_zone_wmarks()
6059 zone->watermark_boost = 0; in __setup_per_zone_wmarks()
6060 zone->_watermark[WMARK_LOW] = min_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
6061 zone->_watermark[WMARK_HIGH] = low_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
6062 zone->_watermark[WMARK_PROMO] = high_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
6064 spin_unlock_irqrestore(&zone->lock, flags); in __setup_per_zone_wmarks()
6072 * setup_per_zone_wmarks - called when min_free_kbytes changes
6073 * or when memory is hot-{added|removed}
6075 * Ensures that the watermark[min,low,high] values for each zone are set
6089 * and high limits or the limits may be inappropriate. in setup_per_zone_wmarks()
6154 * min_free_kbytes_sysctl_handler - just a wrapper around proc_dointvec() so in postcore_initcall()
6196 pgdat->min_unmapped_pages = 0; in setup_min_unmapped_ratio()
6199 zone->zone_pgdat->min_unmapped_pages += (zone_managed_pages(zone) * in setup_min_unmapped_ratio()
6224 pgdat->min_slab_pages = 0; in setup_min_slab_ratio()
6227 zone->zone_pgdat->min_slab_pages += (zone_managed_pages(zone) * in setup_min_slab_ratio()
6247 * lowmem_reserve_ratio_sysctl_handler - just a wrapper around
6272 * percpu_pagelist_high_fraction - changes the pcp->high for each zone on each
6294 ret = -EINVAL; in percpu_pagelist_high_fraction_sysctl_handler()
6385 /* Usage: See admin-guide/dynamic-debug-howto.rst */
6414 .nid = zone_to_nid(cc->zone), in __alloc_contig_migrate_range()
6425 while (pfn < end || !list_empty(&cc->migratepages)) { in __alloc_contig_migrate_range()
6427 ret = -EINTR; in __alloc_contig_migrate_range()
6431 if (list_empty(&cc->migratepages)) { in __alloc_contig_migrate_range()
6432 cc->nr_migratepages = 0; in __alloc_contig_migrate_range()
6434 if (ret && ret != -EAGAIN) in __alloc_contig_migrate_range()
6436 pfn = cc->migrate_pfn; in __alloc_contig_migrate_range()
6439 ret = -EBUSY; in __alloc_contig_migrate_range()
6443 nr_reclaimed = reclaim_clean_pages_from_list(cc->zone, in __alloc_contig_migrate_range()
6444 &cc->migratepages); in __alloc_contig_migrate_range()
6445 cc->nr_migratepages -= nr_reclaimed; in __alloc_contig_migrate_range()
6449 list_for_each_entry(page, &cc->migratepages, lru) { in __alloc_contig_migrate_range()
6457 ret = migrate_pages(&cc->migratepages, alloc_migration_target, in __alloc_contig_migrate_range()
6458 NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE, NULL); in __alloc_contig_migrate_range()
6461 total_migrated += cc->nr_migratepages; in __alloc_contig_migrate_range()
6464 * On -ENOMEM, migrate_pages() bails out right away. It is pointless in __alloc_contig_migrate_range()
6467 if (ret == -ENOMEM) in __alloc_contig_migrate_range()
6473 if (!(cc->gfp_mask & __GFP_NOWARN) && ret == -EBUSY) in __alloc_contig_migrate_range()
6474 alloc_contig_dump_pages(&cc->migratepages); in __alloc_contig_migrate_range()
6475 putback_movable_pages(&cc->migratepages); in __alloc_contig_migrate_range()
6502 /* Add all subpages to the order-0 head, in sequence. */ in split_free_pages()
6503 list_del(&page->lru); in split_free_pages()
6511 * alloc_contig_range() -- tries to allocate given range of pages
6513 * @end: one-past-the-last PFN to allocate
6539 .order = -1, in alloc_contig_range_noprof()
6577 * In case of -EBUSY, we'd like to know which page causes problem. in alloc_contig_range_noprof()
6584 * -EBUSY is not accidentally used or returned to caller. in alloc_contig_range_noprof()
6587 if (ret && ret != -EBUSY) in alloc_contig_range_noprof()
6604 * We don't have to hold zone->lock here because the pages are in alloc_contig_range_noprof()
6611 ret = -EBUSY; in alloc_contig_range_noprof()
6618 ret = -EBUSY; in alloc_contig_range_noprof()
6627 free_contig_range(outer_start, start - outer_start); in alloc_contig_range_noprof()
6629 free_contig_range(end, outer_end - end); in alloc_contig_range_noprof()
6630 } else if (start == outer_start && end == outer_end && is_power_of_2(end - start)) { in alloc_contig_range_noprof()
6632 int order = ilog2(end - start); in alloc_contig_range_noprof()
6637 ret = -EINVAL; in alloc_contig_range_noprof()
6656 static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn, in pfn_range_valid_contig() argument
6667 if (page_zone(page) != z) in pfn_range_valid_contig()
6682 unsigned long last_pfn = start_pfn + nr_pages - 1; in zone_spans_last_pfn()
6688 * alloc_contig_pages() -- tries to find and allocate contiguous range of pages
6714 struct zoneref *z; in alloc_contig_pages_noprof() local
6717 for_each_zone_zonelist_nodemask(zone, z, zonelist, in alloc_contig_pages_noprof()
6719 spin_lock_irqsave(&zone->lock, flags); in alloc_contig_pages_noprof()
6721 pfn = ALIGN(zone->zone_start_pfn, nr_pages); in alloc_contig_pages_noprof()
6731 spin_unlock_irqrestore(&zone->lock, flags); in alloc_contig_pages_noprof()
6736 spin_lock_irqsave(&zone->lock, flags); in alloc_contig_pages_noprof()
6740 spin_unlock_irqrestore(&zone->lock, flags); in alloc_contig_pages_noprof()
6762 for (; nr_pages--; pfn++) { in free_contig_range()
6773 * Effectively disable pcplists for the zone by setting the high limit to 0
6776 * will be drained, or observe the new high limit and skip the pcplist.
6789 __zone_set_pageset_high_and_batch(zone, zone->pageset_high_min, in zone_pcp_enable()
6790 zone->pageset_high_max, zone->pageset_batch); in zone_pcp_enable()
6799 if (zone->per_cpu_pageset != &boot_pageset) { in zone_pcp_reset()
6801 pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); in zone_pcp_reset()
6804 free_percpu(zone->per_cpu_pageset); in zone_pcp_reset()
6805 zone->per_cpu_pageset = &boot_pageset; in zone_pcp_reset()
6806 if (zone->per_cpu_zonestats != &boot_zonestats) { in zone_pcp_reset()
6807 free_percpu(zone->per_cpu_zonestats); in zone_pcp_reset()
6808 zone->per_cpu_zonestats = &boot_zonestats; in zone_pcp_reset()
6818 * Returns the number of managed (non-PageOffline()) pages in the range: the
6833 spin_lock_irqsave(&zone->lock, flags); in __offline_isolated_pages()
6863 spin_unlock_irqrestore(&zone->lock, flags); in __offline_isolated_pages()
6865 return end_pfn - start_pfn - already_offline; in __offline_isolated_pages()
6878 const struct page *head = page - (pfn & ((1 << order) - 1)); in is_free_buddy_page()
6899 * Break down a higher-order page in sub-pages, and keep our target out of
6903 struct page *target, int low, int high, in break_down_buddy_pages() argument
6906 unsigned long size = 1 << high; in break_down_buddy_pages()
6909 while (high > low) { in break_down_buddy_pages()
6910 high--; in break_down_buddy_pages()
6920 if (set_page_guard(zone, current_buddy, high)) in break_down_buddy_pages()
6923 add_to_free_list(current_buddy, zone, high, migratetype, false); in break_down_buddy_pages()
6924 set_buddy_order(current_buddy, high); in break_down_buddy_pages()
6939 spin_lock_irqsave(&zone->lock, flags); in take_page_off_buddy()
6941 struct page *page_head = page - (pfn & ((1 << order) - 1)); in take_page_off_buddy()
6960 spin_unlock_irqrestore(&zone->lock, flags); in take_page_off_buddy()
6973 spin_lock_irqsave(&zone->lock, flags); in put_page_back_buddy()
6984 spin_unlock_irqrestore(&zone->lock, flags); in put_page_back_buddy()
6996 struct zone *zone = &pgdat->node_zones[ZONE_DMA]; in has_managed_dma()
7021 return -EINVAL; in accept_memory_parse()
7038 list_del(&page->lru); in __accept_page()
7039 last = list_empty(&zone->unaccepted_pages); in __accept_page()
7041 account_freepages(zone, -MAX_ORDER_NR_PAGES, MIGRATE_MOVABLE); in __accept_page()
7042 __mod_zone_page_state(zone, NR_UNACCEPTED, -MAX_ORDER_NR_PAGES); in __accept_page()
7044 spin_unlock_irqrestore(&zone->lock, *flags); in __accept_page()
7059 spin_lock_irqsave(&zone->lock, flags); in accept_page()
7061 spin_unlock_irqrestore(&zone->lock, flags); in accept_page()
7065 /* Unlocks zone->lock */ in accept_page()
7074 spin_lock_irqsave(&zone->lock, flags); in try_to_accept_memory_one()
7075 page = list_first_entry_or_null(&zone->unaccepted_pages, in try_to_accept_memory_one()
7078 spin_unlock_irqrestore(&zone->lock, flags); in try_to_accept_memory_one()
7082 /* Unlocks zone->lock */ in try_to_accept_memory_one()
7101 if (list_empty(&zone->unaccepted_pages)) in cond_accept_memory()
7105 to_accept = promo_wmark_pages(zone) - in cond_accept_memory()
7106 (zone_page_state(zone, NR_FREE_PAGES) - in cond_accept_memory()
7107 __zone_watermark_unusable_free(zone, order, 0) - in cond_accept_memory()
7114 to_accept -= MAX_ORDER_NR_PAGES; in cond_accept_memory()
7129 spin_lock_irqsave(&zone->lock, flags); in __free_unaccepted()
7130 first = list_empty(&zone->unaccepted_pages); in __free_unaccepted()
7131 list_add_tail(&page->lru, &zone->unaccepted_pages); in __free_unaccepted()
7135 spin_unlock_irqrestore(&zone->lock, flags); in __free_unaccepted()