Lines Matching +full:oc +full:- +full:delay +full:- +full:us
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
94 /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */
107 /* UP spin_trylock always succeeds so disable IRQs to prevent re-entrancy. */
129 * Generic helper to lookup and a per-cpu variable with an embedded spinlock.
137 spin_lock(&_ret->member); \
146 if (!spin_trylock(&_ret->member)) { \
155 spin_unlock(&ptr->member); \
222 * 1G machine -> (16M dma, 800M-16M normal, 1G-800M high)
223 * 1G machine -> (16M dma, 784M normal, 224M high)
228 * TBD: should special case ZONE_DMA32 machines here - in those we normally
276 int user_min_free_kbytes = -1;
301 * During boot we initialize deferred pages on-demand, as needed, but once
342 return page_zone(page)->pageblock_flags; in get_pageblock_bitmap()
349 pfn &= (PAGES_PER_SECTION-1); in pfn_to_bitidx()
351 pfn = pfn - pageblock_start_pfn(page_zone(page)->zone_start_pfn); in pfn_to_bitidx()
357 …* get_pfnblock_flags_mask - Return the requested group of flags for the pageblock_nr_pages block o…
374 bitidx &= (BITS_PER_LONG-1); in get_pfnblock_flags_mask()
391 …* set_pfnblock_flags_mask - Set the requested group of flags for a pageblock_nr_pages block of pag…
411 bitidx &= (BITS_PER_LONG-1); in set_pfnblock_flags_mask()
443 start_pfn = zone->zone_start_pfn; in page_outside_zone_boundaries()
444 sp = zone->spanned_pages; in page_outside_zone_boundaries()
449 pr_err("page 0x%lx outside node %d zone %s [ 0x%lx - 0x%lx ]\n", in page_outside_zone_boundaries()
450 pfn, zone_to_nid(zone), zone->name, in page_outside_zone_boundaries()
502 current->comm, page_to_pfn(page)); in bad_page()
559 * Higher-order pages are called "compound pages". They are structured thusly:
564 * in bit 0 of page->compound_head. The rest of bits is pointer to head page.
566 * The first tail page's ->compound_order holds the order of allocation.
567 * This usage means that zero-order pages may not be compound.
591 struct capture_control *capc = current->capture_control; in task_capc()
594 !(current->flags & PF_KTHREAD) && in task_capc()
595 !capc->page && in task_capc()
596 capc->cc->zone == zone ? capc : NULL; in task_capc()
603 if (!capc || order != capc->cc->order) in compaction_capture()
615 * and vice-versa but no more than normal fallback logic which can in compaction_capture()
616 * have trouble finding a high-order free page. in compaction_capture()
619 capc->cc->migratetype != MIGRATE_MOVABLE) in compaction_capture()
622 if (migratetype != capc->cc->migratetype) in compaction_capture()
623 trace_mm_page_alloc_extfrag(page, capc->cc->order, order, in compaction_capture()
624 capc->cc->migratetype, migratetype); in compaction_capture()
626 capc->page = page; in compaction_capture()
647 lockdep_assert_held(&zone->lock); in account_freepages()
657 WRITE_ONCE(zone->nr_free_highatomic, in account_freepages()
658 zone->nr_free_highatomic + nr_pages); in account_freepages()
666 struct free_area *area = &zone->free_area[order]; in __add_to_free_list()
674 list_add_tail(&page->buddy_list, &area->free_list[migratetype]); in __add_to_free_list()
676 list_add(&page->buddy_list, &area->free_list[migratetype]); in __add_to_free_list()
677 area->nr_free++; in __add_to_free_list()
685 * of the list - so the moved pages won't immediately be considered for
691 struct free_area *area = &zone->free_area[order]; in move_to_free_list()
699 list_move_tail(&page->buddy_list, &area->free_list[new_mt]); in move_to_free_list()
701 account_freepages(zone, -nr_pages, old_mt); in move_to_free_list()
707 nr_pages = -nr_pages; in move_to_free_list()
725 list_del(&page->buddy_list); in __del_page_from_free_list()
728 zone->free_area[order].nr_free--; in __del_page_from_free_list()
731 __mod_zone_page_state(zone, NR_FREE_PAGES_BLOCKS, -nr_pages); in __del_page_from_free_list()
738 account_freepages(zone, -(1 << order), migratetype); in del_page_from_free_list()
744 return list_first_entry_or_null(&area->free_list[migratetype], in get_page_from_free_area()
750 * of the next-higher order is free. If it is, it's possible
754 * as a 2-level higher order page
763 if (order >= MAX_PAGE_ORDER - 1) in buddy_merge_likely()
767 higher_page = page + (higher_page_pfn - pfn); in buddy_merge_likely()
776 * The concept of a buddy system is to maintain direct-mapped table
794 * -- nyc
809 VM_BUG_ON_PAGE(page->flags & PAGE_FLAGS_CHECK_AT_PREP, page); in __free_one_page()
811 VM_BUG_ON(migratetype == -1); in __free_one_page()
812 VM_BUG_ON_PAGE(pfn & ((1 << order) - 1), page); in __free_one_page()
821 account_freepages(zone, -(1 << order), migratetype); in __free_one_page()
856 * expand() down the line puts the sub-blocks in __free_one_page()
863 page = page + (combined_pfn - pfn); in __free_one_page()
893 if (unlikely(atomic_read(&page->_mapcount) != -1)) in page_expected_state()
896 if (unlikely((unsigned long)page->mapping | in page_expected_state()
899 page->memcg_data | in page_expected_state()
902 ((page->pp_magic & ~0x3UL) == PP_SIGNATURE) | in page_expected_state()
904 (page->flags & check_flags))) in page_expected_state()
914 if (unlikely(atomic_read(&page->_mapcount) != -1)) in page_bad_reason()
916 if (unlikely(page->mapping != NULL)) in page_bad_reason()
917 bad_reason = "non-NULL mapping"; in page_bad_reason()
920 if (unlikely(page->flags & flags)) { in page_bad_reason()
927 if (unlikely(page->memcg_data)) in page_bad_reason()
931 if (unlikely((page->pp_magic & ~0x3UL) == PP_SIGNATURE)) in page_bad_reason()
964 * We rely page->lru.next never has bit 0 set, unless the page in free_tail_page_prepare()
965 * is PageTail(). Let's make sure that's true even for poisoned ->lru. in free_tail_page_prepare()
973 switch (page - head_page) { in free_tail_page_prepare()
975 /* the first tail page: these may be in place of ->mapping */ in free_tail_page_prepare()
981 unlikely(atomic_read(&folio->_nr_pages_mapped))) { in free_tail_page_prepare()
986 if (unlikely(folio->_mm_id_mapcount[0] != -1)) { in free_tail_page_prepare()
990 if (unlikely(folio->_mm_id_mapcount[1] != -1)) { in free_tail_page_prepare()
996 if (unlikely(atomic_read(&folio->_entire_mapcount) + 1)) { in free_tail_page_prepare()
1000 if (unlikely(atomic_read(&folio->_pincount))) { in free_tail_page_prepare()
1007 /* the second tail page: deferred_list overlaps ->mapping */ in free_tail_page_prepare()
1008 if (unlikely(!list_empty(&folio->_deferred_list))) { in free_tail_page_prepare()
1013 if (unlikely(atomic_read(&folio->_entire_mapcount) + 1)) { in free_tail_page_prepare()
1017 if (unlikely(atomic_read(&folio->_pincount))) { in free_tail_page_prepare()
1024 /* the third tail page: hugetlb specifics overlap ->mappings */ in free_tail_page_prepare()
1029 if (page->mapping != TAIL_MAPPING) { in free_tail_page_prepare()
1045 page->mapping = NULL; in free_tail_page_prepare()
1054 * Tag-based KASAN modes skip pages freed via deferred memory initialization
1056 * 2. For tag-based KASAN modes: the page has a match-all KASAN tag, indicating
1059 * Pages will have match-all tags in the following circumstances:
1076 * on-demand allocation and then freed again before the deferred pages
1122 alloc_tag_add(&ref, task->alloc_tag, PAGE_SIZE * nr); in __pgalloc_tag_add()
1159 this_cpu_sub(tag->counters->bytes, PAGE_SIZE * nr); in pgalloc_tag_sub_pages()
1198 zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages); in free_pages_prepare()
1221 * avoid checking PageCompound for order-0 pages. in free_pages_prepare()
1229 folio->_nr_pages = 0; in free_pages_prepare()
1241 (page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; in free_pages_prepare()
1246 mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); in free_pages_prepare()
1247 page->mapping = NULL; in free_pages_prepare()
1257 page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; in free_pages_prepare()
1276 * With hardware tag-based KASAN, memory tags must be set before the in free_pages_prepare()
1318 count = min(pcp->count, count); in free_pcppages_bulk()
1321 pindex = pindex - 1; in free_pcppages_bulk()
1323 spin_lock_irqsave(&zone->lock, flags); in free_pcppages_bulk()
1329 /* Remove pages from lists in a round-robin fashion. */ in free_pcppages_bulk()
1331 if (++pindex > NR_PCP_LISTS - 1) in free_pcppages_bulk()
1333 list = &pcp->lists[pindex]; in free_pcppages_bulk()
1347 list_del(&page->pcp_list); in free_pcppages_bulk()
1348 count -= nr_pages; in free_pcppages_bulk()
1349 pcp->count -= nr_pages; in free_pcppages_bulk()
1356 spin_unlock_irqrestore(&zone->lock, flags); in free_pcppages_bulk()
1359 /* Split a multi-block free page into its individual pageblocks. */
1387 page->order = order; in add_page_to_zone_llist()
1389 llist_add(&page->pcp_llist, &zone->trylock_free_pages); in add_page_to_zone_llist()
1400 if (!spin_trylock_irqsave(&zone->lock, flags)) { in free_one_page()
1405 spin_lock_irqsave(&zone->lock, flags); in free_one_page()
1409 llhead = &zone->trylock_free_pages; in free_one_page()
1416 unsigned int p_order = p->order; in free_one_page()
1423 spin_unlock_irqrestore(&zone->lock, flags); in free_one_page()
1469 atomic_long_add(nr_pages, &page_zone(page)->managed_pages); in __free_pages_core()
1501 * Note: the function may return non-NULL struct page even for a page block
1504 * will fall into 2 sub-sections, and the end pfn of the pageblock may be hole
1517 end_pfn--; in __pageblock_pfn_to_page()
1550 * -- nyc
1559 high--; in expand()
1587 nr_pages -= expand(zone, page, low, high, migratetype); in page_del_and_expand()
1588 account_freepages(zone, -nr_pages, migratetype); in page_del_and_expand()
1638 /* Skip, if hardware tag-based KASAN is not enabled. */ in should_skip_kasan_unpoison()
1643 * With hardware tag-based KASAN enabled, skip if this has been in should_skip_kasan_unpoison()
1651 /* Don't skip, if hardware tag-based KASAN is not enabled. */ in should_skip_init()
1655 /* For hardware tag-based KASAN, skip if requested. */ in should_skip_init()
1753 area = &(zone->free_area[current_order]); in __rmqueue_smallest()
1776 static int fallbacks[MIGRATE_PCPTYPES][MIGRATE_PCPTYPES - 1] = {
1805 VM_WARN_ON(start_pfn & (pageblock_nr_pages - 1)); in __move_freepages_block()
1851 if (!zone_spans_pfn(zone, end - 1)) in prep_move_freepages_block()
1888 return -1; in move_freepages_block()
1919 * move_freepages_block_isolate - move free pages in block for page isolation
1983 int nr_pageblocks = 1 << (start_order - pageblock_order); in change_pageblock_range()
1985 while (nr_pageblocks--) { in change_pageblock_range()
2006 max_boost = mult_frac(zone->_watermark[WMARK_HIGH], in boost_watermark()
2022 zone->watermark_boost = min(zone->watermark_boost + pageblock_nr_pages, in boost_watermark()
2080 * we would do this whole-block claiming. This would help to reduce
2089 if (area->nr_free == 0) in find_suitable_fallback()
2090 return -1; in find_suitable_fallback()
2093 for (i = 0; i < MIGRATE_PCPTYPES - 1 ; i++) { in find_suitable_fallback()
2105 return -1; in find_suitable_fallback()
2140 set_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); in try_to_claim_block()
2157 * to MOVABLE pageblock, consider all non-movable pages as in try_to_claim_block()
2160 * exact migratetype of non-movable pages. in try_to_claim_block()
2164 - (free_pages + movable_pages); in try_to_claim_block()
2172 if (free_pages + alike_pages >= (1 << (pageblock_order-1)) || in try_to_claim_block()
2214 --current_order) { in __rmqueue_claim()
2215 area = &(zone->free_area[current_order]); in __rmqueue_claim()
2218 if (fallback_mt == -1) in __rmqueue_claim()
2252 area = &(zone->free_area[current_order]); in __rmqueue_steal()
2255 if (fallback_mt == -1) in __rmqueue_steal()
2277 * Call me with the zone->lock already held.
2305 * a loop with the zone->lock held, meaning the freelists are in __rmqueue()
2307 * we found pay dirt, to save us the search on the next call. in __rmqueue()
2358 if (!spin_trylock_irqsave(&zone->lock, flags)) in rmqueue_bulk()
2361 spin_lock_irqsave(&zone->lock, flags); in rmqueue_bulk()
2379 list_add_tail(&page->pcp_list, list); in rmqueue_bulk()
2381 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_bulk()
2395 high_min = READ_ONCE(pcp->high_min); in decay_pcp_high()
2396 batch = READ_ONCE(pcp->batch); in decay_pcp_high()
2398 * Decrease pcp->high periodically to try to free possible in decay_pcp_high()
2400 * control latency. This caps pcp->high decrement too. in decay_pcp_high()
2402 if (pcp->high > high_min) { in decay_pcp_high()
2403 pcp->high = max3(pcp->count - (batch << CONFIG_PCP_BATCH_SCALE_MAX), in decay_pcp_high()
2404 pcp->high - (pcp->high >> 3), high_min); in decay_pcp_high()
2405 if (pcp->high > high_min) in decay_pcp_high()
2409 to_drain = pcp->count - pcp->high; in decay_pcp_high()
2411 spin_lock(&pcp->lock); in decay_pcp_high()
2413 spin_unlock(&pcp->lock); in decay_pcp_high()
2430 batch = READ_ONCE(pcp->batch); in drain_zone_pages()
2431 to_drain = min(pcp->count, batch); in drain_zone_pages()
2433 spin_lock(&pcp->lock); in drain_zone_pages()
2435 spin_unlock(&pcp->lock); in drain_zone_pages()
2445 struct per_cpu_pages *pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in drain_pages_zone()
2449 spin_lock(&pcp->lock); in drain_pages_zone()
2450 count = pcp->count; in drain_pages_zone()
2453 pcp->batch << CONFIG_PCP_BATCH_SCALE_MAX); in drain_pages_zone()
2456 count -= to_drain; in drain_pages_zone()
2458 spin_unlock(&pcp->lock); in drain_pages_zone()
2475 * Spill all of this CPU's per-cpu pages back into the buddy allocator.
2492 * not empty. The check for non-emptiness can however race with a free to
2493 * pcplist that has not yet increased the pcp->count from 0 to 1. Callers
2536 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in __drain_all_pages()
2537 if (pcp->count) in __drain_all_pages()
2541 pcp = per_cpu_ptr(z->per_cpu_pageset, cpu); in __drain_all_pages()
2542 if (pcp->count) { in __drain_all_pages()
2566 * Spill all the per-cpu pages from all CPUs back into the buddy allocator.
2568 * When zone parameter is non-NULL, spill just the single zone's pages.
2579 /* Free as much as possible if batch freeing high-order pages. */ in nr_pcp_free()
2581 return min(pcp->count, batch << CONFIG_PCP_BATCH_SCALE_MAX); in nr_pcp_free()
2587 /* Leave at least pcp->batch pages on the list */ in nr_pcp_free()
2589 max_nr_free = high - batch; in nr_pcp_free()
2595 batch = clamp_t(int, pcp->free_count, min_nr_free, max_nr_free); in nr_pcp_free()
2605 high_min = READ_ONCE(pcp->high_min); in nr_pcp_high()
2606 high_max = READ_ONCE(pcp->high_max); in nr_pcp_high()
2607 high = pcp->high = clamp(pcp->high, high_min, high_max); in nr_pcp_high()
2613 pcp->high = max(high - (batch << CONFIG_PCP_BATCH_SCALE_MAX), in nr_pcp_high()
2622 if (test_bit(ZONE_RECLAIM_ACTIVE, &zone->flags)) { in nr_pcp_high()
2623 int free_count = max_t(int, pcp->free_count, batch); in nr_pcp_high()
2625 pcp->high = max(high - free_count, high_min); in nr_pcp_high()
2626 return min(batch << 2, pcp->high); in nr_pcp_high()
2632 if (test_bit(ZONE_BELOW_HIGH, &zone->flags)) { in nr_pcp_high()
2633 int free_count = max_t(int, pcp->free_count, batch); in nr_pcp_high()
2635 pcp->high = max(high - free_count, high_min); in nr_pcp_high()
2636 high = max(pcp->count, high_min); in nr_pcp_high()
2637 } else if (pcp->count >= high) { in nr_pcp_high()
2638 int need_high = pcp->free_count + batch; in nr_pcp_high()
2640 /* pcp->high should be large enough to hold batch freed pages */ in nr_pcp_high()
2641 if (pcp->high < need_high) in nr_pcp_high()
2642 pcp->high = clamp(need_high, high_min, high_max); in nr_pcp_high()
2661 pcp->alloc_factor >>= 1; in free_frozen_page_commit()
2664 list_add(&page->pcp_list, &pcp->lists[pindex]); in free_frozen_page_commit()
2665 pcp->count += 1 << order; in free_frozen_page_commit()
2667 batch = READ_ONCE(pcp->batch); in free_frozen_page_commit()
2669 * As high-order pages other than THP's stored on PCP can contribute in free_frozen_page_commit()
2675 free_high = (pcp->free_count >= batch && in free_frozen_page_commit()
2676 (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) && in free_frozen_page_commit()
2677 (!(pcp->flags & PCPF_FREE_HIGH_BATCH) || in free_frozen_page_commit()
2678 pcp->count >= READ_ONCE(batch))); in free_frozen_page_commit()
2679 pcp->flags |= PCPF_PREV_FREE_HIGH_ORDER; in free_frozen_page_commit()
2680 } else if (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) { in free_frozen_page_commit()
2681 pcp->flags &= ~PCPF_PREV_FREE_HIGH_ORDER; in free_frozen_page_commit()
2683 if (pcp->free_count < (batch << CONFIG_PCP_BATCH_SCALE_MAX)) in free_frozen_page_commit()
2684 pcp->free_count += (1 << order); in free_frozen_page_commit()
2688 * Do not attempt to take a zone lock. Let pcp->count get in free_frozen_page_commit()
2694 if (pcp->count >= high) { in free_frozen_page_commit()
2697 if (test_bit(ZONE_BELOW_HIGH, &zone->flags) && in free_frozen_page_commit()
2700 clear_bit(ZONE_BELOW_HIGH, &zone->flags); in free_frozen_page_commit()
2747 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in __free_frozen_pages()
2773 for (i = 0, j = 0; i < folios->nr; i++) { in free_unref_folios()
2774 struct folio *folio = folios->folios[i]; in free_unref_folios()
2778 if (!free_pages_prepare(&folio->page, order)) in free_unref_folios()
2785 free_one_page(folio_zone(folio), &folio->page, in free_unref_folios()
2789 folio->private = (void *)(unsigned long)order; in free_unref_folios()
2791 folios->folios[j] = folio; in free_unref_folios()
2794 folios->nr = j; in free_unref_folios()
2796 for (i = 0; i < folios->nr; i++) { in free_unref_folios()
2797 struct folio *folio = folios->folios[i]; in free_unref_folios()
2800 unsigned int order = (unsigned long)folio->private; in free_unref_folios()
2803 folio->private = NULL; in free_unref_folios()
2804 migratetype = get_pfnblock_migratetype(&folio->page, pfn); in free_unref_folios()
2821 free_one_page(zone, &folio->page, pfn, in free_unref_folios()
2831 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in free_unref_folios()
2834 free_one_page(zone, &folio->page, pfn, in free_unref_folios()
2842 * Non-isolated types over MIGRATE_PCPTYPES get added in free_unref_folios()
2848 trace_mm_page_free_batched(&folio->page); in free_unref_folios()
2849 free_frozen_page_commit(zone, pcp, &folio->page, migratetype, in free_unref_folios()
2861 * split_page takes a non-compound higher-order page, and splits it into
2862 * n (1<<order) sub-pages: page[0..n]
2863 * Each sub-page must be freed individually.
2892 * emulate a high-order watermark check with a raised order-0 in __isolate_free_page()
2893 * watermark, because we already know our high-order page in __isolate_free_page()
2896 watermark = zone->_watermark[WMARK_MIN] + (1UL << order); in __isolate_free_page()
2907 if (order >= pageblock_order - 1) { in __isolate_free_page()
2908 struct page *endpage = page + (1 << order) - 1; in __isolate_free_page()
2925 * __putback_isolated_page - Return a now-isolated page back where we got it
2938 lockdep_assert_held(&zone->lock); in __putback_isolated_page()
2982 if (!spin_trylock_irqsave(&zone->lock, flags)) in rmqueue_buddy()
2985 spin_lock_irqsave(&zone->lock, flags); in rmqueue_buddy()
2996 * order-0 (atomic) allocs access to HIGHATOMIC in rmqueue_buddy()
2998 * high-order atomic allocation in the future. in rmqueue_buddy()
3004 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_buddy()
3008 spin_unlock_irqrestore(&zone->lock, flags); in rmqueue_buddy()
3022 base_batch = READ_ONCE(pcp->batch); in nr_pcp_alloc()
3023 high_min = READ_ONCE(pcp->high_min); in nr_pcp_alloc()
3024 high_max = READ_ONCE(pcp->high_max); in nr_pcp_alloc()
3025 high = pcp->high = clamp(pcp->high, high_min, high_max); in nr_pcp_alloc()
3034 batch = (base_batch << pcp->alloc_factor); in nr_pcp_alloc()
3037 * If we had larger pcp->high, we could avoid to allocate from in nr_pcp_alloc()
3040 if (high_min != high_max && !test_bit(ZONE_BELOW_HIGH, &zone->flags)) in nr_pcp_alloc()
3041 high = pcp->high = min(high + batch, high_max); in nr_pcp_alloc()
3044 max_nr_alloc = max(high - pcp->count - base_batch, base_batch); in nr_pcp_alloc()
3047 * subsequent allocation of order-0 pages without any freeing. in nr_pcp_alloc()
3050 pcp->alloc_factor < CONFIG_PCP_BATCH_SCALE_MAX) in nr_pcp_alloc()
3051 pcp->alloc_factor++; in nr_pcp_alloc()
3067 /* Remove page from the per-cpu list, caller must protect the list */
3086 pcp->count += alloced << order; in __rmqueue_pcplist()
3092 list_del(&page->pcp_list); in __rmqueue_pcplist()
3093 pcp->count -= 1 << order; in __rmqueue_pcplist()
3099 /* Lock and remove page from the per-cpu list */
3111 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in rmqueue_pcplist()
3122 pcp->free_count >>= 1; in rmqueue_pcplist()
3123 list = &pcp->lists[order_to_pindex(migratetype, order)]; in rmqueue_pcplist()
3136 * Use pcplists for THP or "cheap" high-order allocations.
3167 unlikely(test_bit(ZONE_BOOSTED_WATERMARK, &zone->flags))) { in rmqueue()
3168 clear_bit(ZONE_BOOSTED_WATERMARK, &zone->flags); in rmqueue()
3178 * exclusive use of high-order atomic allocations if there are no
3191 * Check is race-prone but harmless. in reserve_highatomic_pageblock()
3196 if (zone->nr_reserved_highatomic >= max_managed) in reserve_highatomic_pageblock()
3199 spin_lock_irqsave(&zone->lock, flags); in reserve_highatomic_pageblock()
3202 if (zone->nr_reserved_highatomic >= max_managed) in reserve_highatomic_pageblock()
3212 if (move_freepages_block(zone, page, mt, MIGRATE_HIGHATOMIC) == -1) in reserve_highatomic_pageblock()
3214 zone->nr_reserved_highatomic += pageblock_nr_pages; in reserve_highatomic_pageblock()
3217 zone->nr_reserved_highatomic += 1 << order; in reserve_highatomic_pageblock()
3221 spin_unlock_irqrestore(&zone->lock, flags); in reserve_highatomic_pageblock()
3226 * potentially hurts the reliability of high-order allocations when under
3236 struct zonelist *zonelist = ac->zonelist; in unreserve_highatomic_pageblock()
3244 for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->highest_zoneidx, in unreserve_highatomic_pageblock()
3245 ac->nodemask) { in unreserve_highatomic_pageblock()
3250 if (!force && zone->nr_reserved_highatomic <= in unreserve_highatomic_pageblock()
3254 spin_lock_irqsave(&zone->lock, flags); in unreserve_highatomic_pageblock()
3256 struct free_area *area = &(zone->free_area[order]); in unreserve_highatomic_pageblock()
3266 * locking could inadvertently allow a per-cpu in unreserve_highatomic_pageblock()
3271 if (WARN_ON_ONCE(size > zone->nr_reserved_highatomic)) in unreserve_highatomic_pageblock()
3272 size = zone->nr_reserved_highatomic; in unreserve_highatomic_pageblock()
3273 zone->nr_reserved_highatomic -= size; in unreserve_highatomic_pageblock()
3276 * Convert to ac->migratetype and avoid the normal in unreserve_highatomic_pageblock()
3287 ac->migratetype); in unreserve_highatomic_pageblock()
3291 ac->migratetype); in unreserve_highatomic_pageblock()
3293 ac->migratetype); in unreserve_highatomic_pageblock()
3300 WARN_ON_ONCE(ret == -1); in unreserve_highatomic_pageblock()
3302 spin_unlock_irqrestore(&zone->lock, flags); in unreserve_highatomic_pageblock()
3306 spin_unlock_irqrestore(&zone->lock, flags); in unreserve_highatomic_pageblock()
3315 long unusable_free = (1 << order) - 1; in __zone_watermark_unusable_free()
3322 unusable_free += READ_ONCE(z->nr_free_highatomic); in __zone_watermark_unusable_free()
3334 * Return true if free base pages are above 'mark'. For high-order checks it
3335 * will return true of the order-0 watermark is reached and there is at least
3346 /* free_pages may go negative - that's OK */ in __zone_watermark_ok()
3347 free_pages -= __zone_watermark_unusable_free(z, order, alloc_flags); in __zone_watermark_ok()
3355 min -= min / 2; in __zone_watermark_ok()
3358 * Non-blocking allocations (e.g. GFP_ATOMIC) can in __zone_watermark_ok()
3360 * non-blocking allocations requests such as GFP_NOWAIT in __zone_watermark_ok()
3365 min -= min / 4; in __zone_watermark_ok()
3372 * makes during the free path will be small and short-lived. in __zone_watermark_ok()
3375 min -= min / 2; in __zone_watermark_ok()
3379 * Check watermarks for an order-0 allocation request. If these in __zone_watermark_ok()
3380 * are not met, then a high-order request also cannot go ahead in __zone_watermark_ok()
3383 if (free_pages <= min + z->lowmem_reserve[highest_zoneidx]) in __zone_watermark_ok()
3386 /* If this is an order-0 request then the watermark is fine */ in __zone_watermark_ok()
3390 /* For a high-order request, check at least one suitable page is free */ in __zone_watermark_ok()
3392 struct free_area *area = &z->free_area[o]; in __zone_watermark_ok()
3395 if (!area->nr_free) in __zone_watermark_ok()
3433 * Fast check for order-0 only. If this fails then the reserves in zone_watermark_fast()
3443 /* reserved may over estimate high-atomic reserves. */ in zone_watermark_fast()
3444 usable_free -= min(usable_free, reserved); in zone_watermark_fast()
3445 if (usable_free > mark + z->lowmem_reserve[highest_zoneidx]) in zone_watermark_fast()
3454 * Ignore watermark boosting for __GFP_HIGH order-0 allocations in zone_watermark_fast()
3459 if (unlikely(!order && (alloc_flags & ALLOC_MIN_RESERVE) && z->watermark_boost in zone_watermark_fast()
3461 mark = z->_watermark[WMARK_MIN]; in zone_watermark_fast()
3517 * the pointer is within zone->zone_pgdat->node_zones[]. Also assume in alloc_flags_nofragment()
3520 BUILD_BUG_ON(ZONE_NORMAL - ZONE_DMA32 != 1); in alloc_flags_nofragment()
3521 if (nr_online_nodes > 1 && !populated_zone(--zone)) in alloc_flags_nofragment()
3560 z = ac->preferred_zoneref; in get_page_from_freelist()
3561 for_next_zone_zonelist_nodemask(zone, z, ac->highest_zoneidx, in get_page_from_freelist()
3562 ac->nodemask) { in get_page_from_freelist()
3581 * exceed the per-node dirty limit in the slowpath in get_page_from_freelist()
3587 * dirty-throttling and the flusher threads. in get_page_from_freelist()
3589 if (ac->spread_dirty_pages) { in get_page_from_freelist()
3590 if (last_pgdat != zone->zone_pgdat) { in get_page_from_freelist()
3591 last_pgdat = zone->zone_pgdat; in get_page_from_freelist()
3592 last_pgdat_dirty_ok = node_dirty_ok(zone->zone_pgdat); in get_page_from_freelist()
3600 zone != zonelist_zone(ac->preferred_zoneref)) { in get_page_from_freelist()
3608 local_nid = zonelist_node_idx(ac->preferred_zoneref); in get_page_from_freelist()
3619 * watermark. If so, we will decrease pcp->high and free in get_page_from_freelist()
3624 if (test_bit(ZONE_BELOW_HIGH, &zone->flags)) in get_page_from_freelist()
3629 ac->highest_zoneidx, alloc_flags, in get_page_from_freelist()
3633 set_bit(ZONE_BELOW_HIGH, &zone->flags); in get_page_from_freelist()
3638 ac->highest_zoneidx, alloc_flags, in get_page_from_freelist()
3659 !zone_allows_reclaim(zonelist_zone(ac->preferred_zoneref), zone)) in get_page_from_freelist()
3662 ret = node_reclaim(zone->zone_pgdat, gfp_mask, order); in get_page_from_freelist()
3673 ac->highest_zoneidx, alloc_flags)) in get_page_from_freelist()
3681 page = rmqueue(zonelist_zone(ac->preferred_zoneref), zone, order, in get_page_from_freelist()
3682 gfp_mask, alloc_flags, ac->migratetype); in get_page_from_freelist()
3687 * If this is a high-order atomic allocation then check in get_page_from_freelist()
3729 (current->flags & (PF_MEMALLOC | PF_EXITING))) in warn_alloc_show_mem()
3752 current->comm, &vaf, gfp_mask, &gfp_mask, in warn_alloc()
3785 struct oom_control oc = { in __alloc_pages_may_oom() local
3786 .zonelist = ac->zonelist, in __alloc_pages_may_oom()
3787 .nodemask = ac->nodemask, in __alloc_pages_may_oom()
3798 * making progress for us. in __alloc_pages_may_oom()
3820 if (current->flags & PF_DUMPCORE) in __alloc_pages_may_oom()
3836 if (ac->highest_zoneidx < ZONE_NORMAL) in __alloc_pages_may_oom()
3851 if (out_of_memory(&oc) || in __alloc_pages_may_oom()
3856 * Help non-failing allocations by giving them access to memory in __alloc_pages_may_oom()
3875 /* Try memory compaction for high-order allocations before reclaim */
3918 zone->compact_blockskip_flush = false; in __alloc_pages_direct_compact()
3954 * Compaction was skipped due to a lack of free order-0 in should_compact_retry()
3992 (*compact_priority)--; in should_compact_retry()
4025 * Let's give them a good hope and keep retrying while the order-0 in should_compact_retry()
4028 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in should_compact_retry()
4029 ac->highest_zoneidx, ac->nodemask) { in should_compact_retry()
4031 ac->highest_zoneidx, alloc_flags)) in should_compact_retry()
4049 if (current->flags & PF_MEMALLOC) in __need_reclaim()
4136 progress = try_to_free_pages(ac->zonelist, order, gfp_mask, in __perform_reclaim()
4137 ac->nodemask); in __perform_reclaim()
4167 * pages are pinned on the per-cpu lists or in high alloc reserves. in __alloc_pages_direct_reclaim()
4188 enum zone_type highest_zoneidx = ac->highest_zoneidx; in wake_all_kswapds()
4196 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, highest_zoneidx, in wake_all_kswapds()
4197 ac->nodemask) { in wake_all_kswapds()
4200 if (last_pgdat == zone->zone_pgdat) in wake_all_kswapds()
4203 last_pgdat = zone->zone_pgdat; in wake_all_kswapds()
4242 * Ignore cpuset mems for non-blocking __GFP_HIGH (probably in gfp_to_alloc_flags()
4284 if (in_serving_softirq() && (current->flags & PF_MEMALLOC)) in __gfp_pfmemalloc_flags()
4287 if (current->flags & PF_MEMALLOC) in __gfp_pfmemalloc_flags()
4340 for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, in should_reclaim_retry()
4341 ac->highest_zoneidx, ac->nodemask) { in should_reclaim_retry()
4360 ac->highest_zoneidx, alloc_flags, available); in should_reclaim_retry()
4376 if (current->flags & PF_WQ_WORKER) in should_reclaim_retry()
4397 * This assumes that for all allocations, ac->nodemask can come only in check_retry_cpuset()
4402 if (cpusets_enabled() && ac->nodemask && in check_retry_cpuset()
4403 !cpuset_nodemask_valid_mems_allowed(ac->nodemask)) { in check_retry_cpuset()
4404 ac->nodemask = NULL; in check_retry_cpuset()
4443 * allocate greater than order-1 page units with __GFP_NOFAIL. in __alloc_pages_slowpath()
4454 * for somebody to do a work for us. in __alloc_pages_slowpath()
4456 WARN_ON_ONCE(current->flags & PF_MEMALLOC); in __alloc_pages_slowpath()
4477 * there was a cpuset modification and we are retrying - otherwise we in __alloc_pages_slowpath()
4478 * could end up iterating over non-eligible zones endlessly. in __alloc_pages_slowpath()
4480 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath()
4481 ac->highest_zoneidx, ac->nodemask); in __alloc_pages_slowpath()
4482 if (!zonelist_zone(ac->preferred_zoneref)) in __alloc_pages_slowpath()
4487 * any suitable zone to satisfy the request - e.g. non-movable in __alloc_pages_slowpath()
4491 struct zoneref *z = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath()
4492 ac->highest_zoneidx, in __alloc_pages_slowpath()
4511 * that we have enough base pages and don't need to reclaim. For non- in __alloc_pages_slowpath()
4512 * movable high-order allocations, do that as well, as compaction will in __alloc_pages_slowpath()
4520 (order > 0 && ac->migratetype != MIGRATE_MOVABLE)) in __alloc_pages_slowpath()
4542 * - potentially very expensive because zones are far in __alloc_pages_slowpath()
4545 * - not guaranteed to help because isolate_freepages() in __alloc_pages_slowpath()
4548 * - unlikely to make entire pageblocks free on its in __alloc_pages_slowpath()
4588 ac->nodemask = NULL; in __alloc_pages_slowpath()
4589 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in __alloc_pages_slowpath()
4590 ac->highest_zoneidx, ac->nodemask); in __alloc_pages_slowpath()
4603 if (current->flags & PF_MEMALLOC) in __alloc_pages_slowpath()
4635 * It doesn't make any sense to retry for the compaction if the order-0 in __alloc_pages_slowpath()
4660 /* Reclaim has failed us, start killing things */ in __alloc_pages_slowpath()
4700 * Help non-failing allocations by giving some access to memory in __alloc_pages_slowpath()
4701 * reserves normally used for high priority non-blocking in __alloc_pages_slowpath()
4714 warn_alloc(gfp_mask, ac->nodemask, in __alloc_pages_slowpath()
4725 ac->highest_zoneidx = gfp_zone(gfp_mask); in prepare_alloc_pages()
4726 ac->zonelist = node_zonelist(preferred_nid, gfp_mask); in prepare_alloc_pages()
4727 ac->nodemask = nodemask; in prepare_alloc_pages()
4728 ac->migratetype = gfp_migratetype(gfp_mask); in prepare_alloc_pages()
4736 if (in_task() && !ac->nodemask) in prepare_alloc_pages()
4737 ac->nodemask = &cpuset_current_mems_allowed; in prepare_alloc_pages()
4755 ac->spread_dirty_pages = (gfp_mask & __GFP_WRITE); in prepare_alloc_pages()
4762 ac->preferred_zoneref = first_zones_zonelist(ac->zonelist, in prepare_alloc_pages()
4763 ac->highest_zoneidx, ac->nodemask); in prepare_alloc_pages()
4769 * __alloc_pages_bulk - Allocate a number of order-0 pages to an array
4811 if (unlikely(nr_pages - nr_populated == 0)) in alloc_pages_bulk_noprof()
4819 if (nr_pages - nr_populated == 1) in alloc_pages_bulk_noprof()
4884 pcp = pcp_spin_trylock(zone->per_cpu_pageset); in alloc_pages_bulk_noprof()
4889 pcp_list = &pcp->lists[order_to_pindex(ac.migratetype, 0)]; in alloc_pages_bulk_noprof()
4983 * &cpuset_current_mems_allowed to optimize the fast-path attempt. in __alloc_frozen_pages_noprof()
5047 * ___free_pages - Free pages allocated with alloc_pages().
5052 * This function can free multi-page allocations that are not compound
5058 * by put_page() which only frees the first page of a non-compound
5078 pgalloc_tag_sub_pages(tag, (1 << order) - 1); in ___free_pages()
5079 while (order-- > 0) in ___free_pages()
5120 while (page < --last) in make_alloc_exact()
5131 * alloc_pages_exact - allocate an exact number physically-contiguous pages.
5137 * allocate memory in power-of-two pages.
5159 * alloc_pages_exact_nid - allocate an exact number of physically-contiguous
5185 * free_pages_exact - release memory allocated via alloc_pages_exact()
5204 * nr_free_zone_pages - count number of pages beyond high watermark
5211 * nr_free_zone_pages = managed_pages - high_pages
5229 sum += size - high; in nr_free_zone_pages()
5236 * nr_free_buffer_pages - count number of pages beyond high watermark
5252 zoneref->zone = zone; in zoneref_set_zone()
5253 zoneref->zone_idx = zone_idx(zone); in zoneref_set_zone()
5268 zone_type--; in build_zonerefs_node()
5269 zone = pgdat->node_zones + zone_type; in build_zonerefs_node()
5291 return -EINVAL; in __parse_numa_zonelist_order()
5312 * find_next_best_node - find the next node that should appear in a given node's fallback list
5350 /* Penalize nodes under us ("prefer the next node") */ in find_next_best_node()
5376 * This results in maximum locality--normal zone overflows into local
5377 * DMA zone, if any--but risks exhausting DMA zone.
5385 zonerefs = pgdat->node_zonelists[ZONELIST_FALLBACK]._zonerefs; in build_zonelists_in_node_order()
5395 zonerefs->zone = NULL; in build_zonelists_in_node_order()
5396 zonerefs->zone_idx = 0; in build_zonelists_in_node_order()
5407 zonerefs = pgdat->node_zonelists[ZONELIST_NOFALLBACK]._zonerefs; in build_thisnode_zonelists()
5410 zonerefs->zone = NULL; in build_thisnode_zonelists()
5411 zonerefs->zone_idx = 0; in build_thisnode_zonelists()
5421 /* NUMA-aware ordering of nodes */ in build_zonelists()
5422 local_node = pgdat->node_id; in build_zonelists()
5430 * distance group to make it round-robin. in build_zonelists()
5475 zonerefs = pgdat->node_zonelists[ZONELIST_FALLBACK]._zonerefs; in build_zonelists()
5479 zonerefs->zone = NULL; in build_zonelists()
5480 zonerefs->zone_idx = 0; in build_zonelists()
5521 * trying to hold port->lock, for in __build_all_zonelists()
5523 * calling kmalloc(GFP_ATOMIC | __GFP_NOWARN) with port->lock held. in __build_all_zonelists()
5533 * building zonelists is fine - no need to touch other nodes. in __build_all_zonelists()
5535 if (self && !node_online(self->node_id)) { in __build_all_zonelists()
5550 * We now know the "local memory node" for each node-- in __build_all_zonelists()
5552 * Set up numa_mem percpu variable for on-line cpus. During in __build_all_zonelists()
5553 * boot, only the boot cpu should be on-line; we'll init the in __build_all_zonelists()
5554 * secondary cpus' numa_mem as they come on-line. During in __build_all_zonelists()
5555 * node/memory hotplug, we'll fixup all on-line cpus. in __build_all_zonelists()
5584 * (a chicken-egg dilemma). in build_all_zonelists_init()
5614 * more accurate, but expensive to check per-zone. This check is in build_all_zonelists()
5615 * made on memory-hotadd so a system can start with mobility in build_all_zonelists()
5649 * Clamp the batch to a 2^n - 1 value. Having a power in zone_batchsize()
5658 batch = rounddown_pow_of_two(batch + batch/2) - 1; in zone_batchsize()
5672 * can be a significant delay between the individual batches being in zone_batchsize()
5674 * fragmented and becoming unavailable for high-order allocations. in zone_batchsize()
5731 * pcp->high and pcp->batch values are related and generally batch is lower
5732 * than high. They are also related to pcp->count such that count is lower
5738 * store tearing. Any new users of pcp->batch, pcp->high_min and pcp->high_max
5740 * fully trust only the pcp->count field on the local CPU with interrupts
5750 WRITE_ONCE(pcp->batch, batch); in pageset_update()
5751 WRITE_ONCE(pcp->high_min, high_min); in pageset_update()
5752 WRITE_ONCE(pcp->high_max, high_max); in pageset_update()
5762 spin_lock_init(&pcp->lock); in per_cpu_pages_init()
5764 INIT_LIST_HEAD(&pcp->lists[pindex]); in per_cpu_pages_init()
5772 pcp->high_min = BOOT_PAGESET_HIGH; in per_cpu_pages_init()
5773 pcp->high_max = BOOT_PAGESET_HIGH; in per_cpu_pages_init()
5774 pcp->batch = BOOT_PAGESET_BATCH; in per_cpu_pages_init()
5775 pcp->free_count = 0; in per_cpu_pages_init()
5785 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in __zone_set_pageset_high_and_batch()
5791 * Calculate and set new high and batch values for all per-cpu pagesets of a
5803 * PCP high is tuned manually, disable auto-tuning via in zone_set_pageset_high_and_batch()
5813 if (zone->pageset_high_min == new_high_min && in zone_set_pageset_high_and_batch()
5814 zone->pageset_high_max == new_high_max && in zone_set_pageset_high_and_batch()
5815 zone->pageset_batch == new_batch) in zone_set_pageset_high_and_batch()
5818 zone->pageset_high_min = new_high_min; in zone_set_pageset_high_and_batch()
5819 zone->pageset_high_max = new_high_max; in zone_set_pageset_high_and_batch()
5820 zone->pageset_batch = new_batch; in zone_set_pageset_high_and_batch()
5832 zone->per_cpu_zonestats = alloc_percpu(struct per_cpu_zonestat); in setup_zone_pageset()
5834 zone->per_cpu_pageset = alloc_percpu(struct per_cpu_pages); in setup_zone_pageset()
5839 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in setup_zone_pageset()
5840 pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); in setup_zone_pageset()
5863 pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); in zone_pcp_update_cacheinfo()
5866 * If data cache slice of CPU is large enough, "pcp->batch" in zone_pcp_update_cacheinfo()
5868 * consecutive high-order pages freeing without allocation. in zone_pcp_update_cacheinfo()
5870 * cache-hot pages sharing. in zone_pcp_update_cacheinfo()
5872 spin_lock(&pcp->lock); in zone_pcp_update_cacheinfo()
5873 if ((cci->per_cpu_data_slice_size >> PAGE_SHIFT) > 3 * pcp->batch) in zone_pcp_update_cacheinfo()
5874 pcp->flags |= PCPF_FREE_HIGH_BATCH; in zone_pcp_update_cacheinfo()
5876 pcp->flags &= ~PCPF_FREE_HIGH_BATCH; in zone_pcp_update_cacheinfo()
5877 spin_unlock(&pcp->lock); in zone_pcp_update_cacheinfo()
5910 memset(pzstats->vm_numa_event, 0, in setup_per_cpu_pageset()
5911 sizeof(pzstats->vm_numa_event)); in setup_per_cpu_pageset()
5916 pgdat->per_cpu_nodestats = in setup_per_cpu_pageset()
5927 zone->per_cpu_pageset = &boot_pageset; in zone_pcp_init()
5928 zone->per_cpu_zonestats = &boot_zonestats; in zone_pcp_init()
5929 zone->pageset_high_min = BOOT_PAGESET_HIGH; in zone_pcp_init()
5930 zone->pageset_high_max = BOOT_PAGESET_HIGH; in zone_pcp_init()
5931 zone->pageset_batch = BOOT_PAGESET_BATCH; in zone_pcp_init()
5934 pr_debug(" %s zone: %lu pages, LIFO batch:%u\n", zone->name, in zone_pcp_init()
5935 zone->present_pages, zone_batchsize(zone)); in zone_pcp_init()
5942 atomic_long_add(count, &page_zone(page)->managed_pages); in adjust_managed_page_count()
5968 * Perform a kasan-unchecked memset() since this memory in free_reserved_area()
6046 * calculate_totalreserve_pages - called when sysctl_lowmem_reserve_ratio
6057 pgdat->totalreserve_pages = 0; in calculate_totalreserve_pages()
6060 struct zone *zone = pgdat->node_zones + i; in calculate_totalreserve_pages()
6066 if (zone->lowmem_reserve[j] > max) in calculate_totalreserve_pages()
6067 max = zone->lowmem_reserve[j]; in calculate_totalreserve_pages()
6076 pgdat->totalreserve_pages += max; in calculate_totalreserve_pages()
6086 * setup_per_zone_lowmem_reserve - called whenever
6097 for (i = 0; i < MAX_NR_ZONES - 1; i++) { in setup_per_zone_lowmem_reserve()
6098 struct zone *zone = &pgdat->node_zones[i]; in setup_per_zone_lowmem_reserve()
6104 struct zone *upper_zone = &pgdat->node_zones[j]; in setup_per_zone_lowmem_reserve()
6109 zone->lowmem_reserve[j] = 0; in setup_per_zone_lowmem_reserve()
6111 zone->lowmem_reserve[j] = managed_pages / ratio; in setup_per_zone_lowmem_reserve()
6113 zone->lowmem_reserve[j]); in setup_per_zone_lowmem_reserve()
6124 unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT - 10); in __setup_per_zone_wmarks()
6138 spin_lock_irqsave(&zone->lock, flags); in __setup_per_zone_wmarks()
6147 * The WMARK_HIGH-WMARK_LOW and (WMARK_LOW-WMARK_MIN) in __setup_per_zone_wmarks()
6155 zone->_watermark[WMARK_MIN] = min_pages; in __setup_per_zone_wmarks()
6161 zone->_watermark[WMARK_MIN] = tmp; in __setup_per_zone_wmarks()
6173 zone->watermark_boost = 0; in __setup_per_zone_wmarks()
6174 zone->_watermark[WMARK_LOW] = min_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
6175 zone->_watermark[WMARK_HIGH] = low_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
6176 zone->_watermark[WMARK_PROMO] = high_wmark_pages(zone) + tmp; in __setup_per_zone_wmarks()
6179 spin_unlock_irqrestore(&zone->lock, flags); in __setup_per_zone_wmarks()
6187 * setup_per_zone_wmarks - called when min_free_kbytes changes
6188 * or when memory is hot-{added|removed}
6269 * min_free_kbytes_sysctl_handler - just a wrapper around proc_dointvec() so in postcore_initcall()
6311 pgdat->min_unmapped_pages = 0; in setup_min_unmapped_ratio()
6314 zone->zone_pgdat->min_unmapped_pages += (zone_managed_pages(zone) * in setup_min_unmapped_ratio()
6339 pgdat->min_slab_pages = 0; in setup_min_slab_ratio()
6342 zone->zone_pgdat->min_slab_pages += (zone_managed_pages(zone) * in setup_min_slab_ratio()
6362 * lowmem_reserve_ratio_sysctl_handler - just a wrapper around
6387 * percpu_pagelist_high_fraction - changes the pcp->high for each zone on each
6409 ret = -EINVAL; in percpu_pagelist_high_fraction_sysctl_handler()
6509 /* Usage: See admin-guide/dynamic-debug-howto.rst */
6537 .nid = zone_to_nid(cc->zone), in __alloc_contig_migrate_range()
6538 .gfp_mask = cc->gfp_mask, in __alloc_contig_migrate_range()
6548 while (pfn < end || !list_empty(&cc->migratepages)) { in __alloc_contig_migrate_range()
6550 ret = -EINTR; in __alloc_contig_migrate_range()
6554 if (list_empty(&cc->migratepages)) { in __alloc_contig_migrate_range()
6555 cc->nr_migratepages = 0; in __alloc_contig_migrate_range()
6557 if (ret && ret != -EAGAIN) in __alloc_contig_migrate_range()
6559 pfn = cc->migrate_pfn; in __alloc_contig_migrate_range()
6562 ret = -EBUSY; in __alloc_contig_migrate_range()
6566 nr_reclaimed = reclaim_clean_pages_from_list(cc->zone, in __alloc_contig_migrate_range()
6567 &cc->migratepages); in __alloc_contig_migrate_range()
6568 cc->nr_migratepages -= nr_reclaimed; in __alloc_contig_migrate_range()
6572 list_for_each_entry(page, &cc->migratepages, lru) { in __alloc_contig_migrate_range()
6580 ret = migrate_pages(&cc->migratepages, alloc_migration_target, in __alloc_contig_migrate_range()
6581 NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE, NULL); in __alloc_contig_migrate_range()
6584 total_migrated += cc->nr_migratepages; in __alloc_contig_migrate_range()
6587 * On -ENOMEM, migrate_pages() bails out right away. It is pointless in __alloc_contig_migrate_range()
6590 if (ret == -ENOMEM) in __alloc_contig_migrate_range()
6596 if (!(cc->gfp_mask & __GFP_NOWARN) && ret == -EBUSY) in __alloc_contig_migrate_range()
6597 alloc_contig_dump_pages(&cc->migratepages); in __alloc_contig_migrate_range()
6598 putback_movable_pages(&cc->migratepages); in __alloc_contig_migrate_range()
6626 /* Add all subpages to the order-0 head, in sequence. */ in split_free_pages()
6627 list_del(&page->lru); in split_free_pages()
6653 return -EINVAL; in __alloc_contig_verify_gfp_mask()
6669 * alloc_contig_range() -- tries to allocate given range of pages
6671 * @end: one-past-the-last PFN to allocate
6699 .order = -1, in alloc_contig_range_noprof()
6710 return -EINVAL; in alloc_contig_range_noprof()
6727 * This lets us mark the pageblocks back as in alloc_contig_range_noprof()
6740 * In case of -EBUSY, we'd like to know which page causes problem. in alloc_contig_range_noprof()
6747 * -EBUSY is not accidentally used or returned to caller. in alloc_contig_range_noprof()
6750 if (ret && ret != -EBUSY) in alloc_contig_range_noprof()
6754 * When in-use hugetlb pages are migrated, they may simply be released in alloc_contig_range_noprof()
6756 * buddy system. After the migration of in-use huge pages is completed, in alloc_contig_range_noprof()
6777 * We don't have to hold zone->lock here because the pages are in alloc_contig_range_noprof()
6784 ret = -EBUSY; in alloc_contig_range_noprof()
6791 ret = -EBUSY; in alloc_contig_range_noprof()
6800 free_contig_range(outer_start, start - outer_start); in alloc_contig_range_noprof()
6802 free_contig_range(end, outer_end - end); in alloc_contig_range_noprof()
6803 } else if (start == outer_start && end == outer_end && is_power_of_2(end - start)) { in alloc_contig_range_noprof()
6805 int order = ilog2(end - start); in alloc_contig_range_noprof()
6811 ret = -EINVAL; in alloc_contig_range_noprof()
6856 unsigned long last_pfn = start_pfn + nr_pages - 1; in zone_spans_last_pfn()
6862 * alloc_contig_pages() -- tries to find and allocate contiguous range of pages
6895 spin_lock_irqsave(&zone->lock, flags); in alloc_contig_pages_noprof()
6897 pfn = ALIGN(zone->zone_start_pfn, nr_pages); in alloc_contig_pages_noprof()
6907 spin_unlock_irqrestore(&zone->lock, flags); in alloc_contig_pages_noprof()
6912 spin_lock_irqsave(&zone->lock, flags); in alloc_contig_pages_noprof()
6916 spin_unlock_irqrestore(&zone->lock, flags); in alloc_contig_pages_noprof()
6938 for (; nr_pages--; pfn++) { in free_contig_range()
6965 __zone_set_pageset_high_and_batch(zone, zone->pageset_high_min, in zone_pcp_enable()
6966 zone->pageset_high_max, zone->pageset_batch); in zone_pcp_enable()
6975 if (zone->per_cpu_pageset != &boot_pageset) { in zone_pcp_reset()
6977 pzstats = per_cpu_ptr(zone->per_cpu_zonestats, cpu); in zone_pcp_reset()
6980 free_percpu(zone->per_cpu_pageset); in zone_pcp_reset()
6981 zone->per_cpu_pageset = &boot_pageset; in zone_pcp_reset()
6982 if (zone->per_cpu_zonestats != &boot_zonestats) { in zone_pcp_reset()
6983 free_percpu(zone->per_cpu_zonestats); in zone_pcp_reset()
6984 zone->per_cpu_zonestats = &boot_zonestats; in zone_pcp_reset()
6994 * Returns the number of managed (non-PageOffline()) pages in the range: the
7009 spin_lock_irqsave(&zone->lock, flags); in __offline_isolated_pages()
7039 spin_unlock_irqrestore(&zone->lock, flags); in __offline_isolated_pages()
7041 return end_pfn - start_pfn - already_offline; in __offline_isolated_pages()
7054 const struct page *head = page - (pfn & ((1 << order) - 1)); in is_free_buddy_page()
7075 * Break down a higher-order page in sub-pages, and keep our target out of
7086 high--; in break_down_buddy_pages()
7115 spin_lock_irqsave(&zone->lock, flags); in take_page_off_buddy()
7117 struct page *page_head = page - (pfn & ((1 << order) - 1)); in take_page_off_buddy()
7136 spin_unlock_irqrestore(&zone->lock, flags); in take_page_off_buddy()
7149 spin_lock_irqsave(&zone->lock, flags); in put_page_back_buddy()
7160 spin_unlock_irqrestore(&zone->lock, flags); in put_page_back_buddy()
7172 struct zone *zone = &pgdat->node_zones[ZONE_DMA]; in has_managed_dma()
7194 return -EINVAL; in accept_memory_parse()
7209 list_del(&page->lru); in __accept_page()
7210 account_freepages(zone, -MAX_ORDER_NR_PAGES, MIGRATE_MOVABLE); in __accept_page()
7211 __mod_zone_page_state(zone, NR_UNACCEPTED, -MAX_ORDER_NR_PAGES); in __accept_page()
7213 spin_unlock_irqrestore(&zone->lock, *flags); in __accept_page()
7225 spin_lock_irqsave(&zone->lock, flags); in accept_page()
7227 spin_unlock_irqrestore(&zone->lock, flags); in accept_page()
7231 /* Unlocks zone->lock */ in accept_page()
7240 spin_lock_irqsave(&zone->lock, flags); in try_to_accept_memory_one()
7241 page = list_first_entry_or_null(&zone->unaccepted_pages, in try_to_accept_memory_one()
7244 spin_unlock_irqrestore(&zone->lock, flags); in try_to_accept_memory_one()
7248 /* Unlocks zone->lock */ in try_to_accept_memory_one()
7260 if (list_empty(&zone->unaccepted_pages)) in cond_accept_memory()
7278 to_accept = wmark - in cond_accept_memory()
7279 (zone_page_state(zone, NR_FREE_PAGES) - in cond_accept_memory()
7280 __zone_watermark_unusable_free(zone, order, 0) - in cond_accept_memory()
7287 to_accept -= MAX_ORDER_NR_PAGES; in cond_accept_memory()
7301 spin_lock_irqsave(&zone->lock, flags); in __free_unaccepted()
7302 list_add_tail(&page->lru, &zone->unaccepted_pages); in __free_unaccepted()
7306 spin_unlock_irqrestore(&zone->lock, flags); in __free_unaccepted()
7333 * try_alloc_pages - opportunistic reentrant allocation from any context
7339 * allocator -> tracepoint -> try_alloc_pages_noprof).
7402 * If it's empty attempt to spin_trylock zone->lock. in try_alloc_pages_noprof()