mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 07:03:28 -04:00
mm: split out internal page_alloc.h
internal.h is a bit bloated, seems like time for a page_alloc.h. Where it wasn't obvious, the heuristic for deciding what goes into this new header was "does it support/correspond to a definition in mm/page_alloc.c?" Only need to include it from ~20 .c files out of ~150 so this does seem like a genuine reduction in scopes, which is nice. And there's no circular internal.h<->page_alloc.h dependency, so it seems worthwhile to split this up before that inevitably emerges! Link: https://lore.kernel.org/20260703-alloc-trylock-v5-4-c87b714e19d3@google.com Signed-off-by: Brendan Jackman <jackmanb@google.com> Suggested-by: "David Hildenbrand (Arm)" <david@kernel.org> Link: https://lore.kernel.org/all/41e92bab-6882-401a-8de9-154adbdcfb36@kernel.org/ Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org> Acked-by: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
2666382a4f
commit
d0850de699
@@ -17173,6 +17173,7 @@ F: mm/debug_page_alloc.c
|
||||
F: mm/debug_page_ref.c
|
||||
F: mm/fail_page_alloc.c
|
||||
F: mm/page_alloc.c
|
||||
F: mm/page_alloc.h
|
||||
F: mm/page_ext.c
|
||||
F: mm/page_frag_cache.c
|
||||
F: mm/page_isolation.c
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <linux/page_owner.h>
|
||||
#include <linux/psi.h>
|
||||
#include <linux/cpuset.h>
|
||||
#include "page_alloc.h"
|
||||
#include "internal.h"
|
||||
|
||||
#ifdef CONFIG_COMPACTION
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <linux/node.h>
|
||||
#include <linux/page_owner.h>
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "hugetlb_vmemmap.h"
|
||||
#include "hugetlb_cma.h"
|
||||
#include "hugetlb_internal.h"
|
||||
|
||||
252
mm/internal.h
252
mm/internal.h
@@ -658,165 +658,6 @@ extern int defrag_mode;
|
||||
void setup_per_zone_wmarks(void);
|
||||
void calculate_min_free_kbytes(void);
|
||||
int __meminit init_per_zone_wmark_min(void);
|
||||
void page_alloc_sysctl_init(void);
|
||||
|
||||
/*
|
||||
* Structure for holding the mostly immutable allocation parameters passed
|
||||
* between functions involved in allocations, including the alloc_pages*
|
||||
* family of functions.
|
||||
*
|
||||
* nodemask, migratetype and highest_zoneidx are initialized only once in
|
||||
* __alloc_pages() and then never change.
|
||||
*
|
||||
* zonelist, preferred_zone and highest_zoneidx are set first in
|
||||
* __alloc_pages() for the fast path, and might be later changed
|
||||
* in __alloc_pages_slowpath(). All other functions pass the whole structure
|
||||
* by a const pointer.
|
||||
*/
|
||||
struct alloc_context {
|
||||
struct zonelist *zonelist;
|
||||
const nodemask_t *nodemask;
|
||||
struct zoneref *preferred_zoneref;
|
||||
int migratetype;
|
||||
|
||||
/*
|
||||
* highest_zoneidx represents highest usable zone index of
|
||||
* the allocation request. Due to the nature of the zone,
|
||||
* memory on lower zone than the highest_zoneidx will be
|
||||
* protected by lowmem_reserve[highest_zoneidx].
|
||||
*
|
||||
* highest_zoneidx is also used by reclaim/compaction to limit
|
||||
* the target zone since higher zone than this index cannot be
|
||||
* usable for this allocation request.
|
||||
*/
|
||||
enum zone_type highest_zoneidx;
|
||||
bool spread_dirty_pages;
|
||||
};
|
||||
|
||||
/*
|
||||
* This function returns the order of a free page in the buddy system. In
|
||||
* general, page_zone(page)->lock must be held by the caller to prevent the
|
||||
* page from being allocated in parallel and returning garbage as the order.
|
||||
* If a caller does not hold page_zone(page)->lock, it must guarantee that the
|
||||
* page cannot be allocated or merged in parallel. Alternatively, it must
|
||||
* handle invalid values gracefully, and use buddy_order_unsafe() below.
|
||||
*/
|
||||
static inline unsigned int buddy_order(struct page *page)
|
||||
{
|
||||
/* PageBuddy() must be checked by the caller */
|
||||
return page_private(page);
|
||||
}
|
||||
|
||||
/*
|
||||
* Like buddy_order(), but for callers who cannot afford to hold the zone lock.
|
||||
* PageBuddy() should be checked first by the caller to minimize race window,
|
||||
* and invalid values must be handled gracefully.
|
||||
*
|
||||
* READ_ONCE is used so that if the caller assigns the result into a local
|
||||
* variable and e.g. tests it for valid range before using, the compiler cannot
|
||||
* decide to remove the variable and inline the page_private(page) multiple
|
||||
* times, potentially observing different values in the tests and the actual
|
||||
* use of the result.
|
||||
*/
|
||||
#define buddy_order_unsafe(page) READ_ONCE(page_private(page))
|
||||
|
||||
/*
|
||||
* This function checks whether a page is free && is the buddy
|
||||
* we can coalesce a page and its buddy if
|
||||
* (a) the buddy is not in a hole (check before calling!) &&
|
||||
* (b) the buddy is in the buddy system &&
|
||||
* (c) a page and its buddy have the same order &&
|
||||
* (d) a page and its buddy are in the same zone.
|
||||
*
|
||||
* For recording whether a page is in the buddy system, we set PageBuddy.
|
||||
* Setting, clearing, and testing PageBuddy is serialized by zone->lock.
|
||||
*
|
||||
* For recording page's order, we use page_private(page).
|
||||
*/
|
||||
static inline bool page_is_buddy(struct page *page, struct page *buddy,
|
||||
unsigned int order)
|
||||
{
|
||||
if (!page_is_guard(buddy) && !PageBuddy(buddy))
|
||||
return false;
|
||||
|
||||
if (buddy_order(buddy) != order)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* zone check is done late to avoid uselessly calculating
|
||||
* zone/node ids for pages that could never merge.
|
||||
*/
|
||||
if (page_zone_id(page) != page_zone_id(buddy))
|
||||
return false;
|
||||
|
||||
VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate the struct page for both the matching buddy in our
|
||||
* pair (buddy1) and the combined O(n+1) page they form (page).
|
||||
*
|
||||
* 1) Any buddy B1 will have an order O twin B2 which satisfies
|
||||
* the following equation:
|
||||
* B2 = B1 ^ (1 << O)
|
||||
* For example, if the starting buddy (buddy2) is #8 its order
|
||||
* 1 buddy is #10:
|
||||
* B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
|
||||
*
|
||||
* 2) Any buddy B will have an order O+1 parent P which
|
||||
* satisfies the following equation:
|
||||
* P = B & ~(1 << O)
|
||||
*
|
||||
* Assumption: *_mem_map is contiguous at least up to MAX_PAGE_ORDER
|
||||
*/
|
||||
static inline unsigned long
|
||||
__find_buddy_pfn(unsigned long page_pfn, unsigned int order)
|
||||
{
|
||||
return page_pfn ^ (1 << order);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the buddy of @page and validate it.
|
||||
* @page: The input page
|
||||
* @pfn: The pfn of the page, it saves a call to page_to_pfn() when the
|
||||
* function is used in the performance-critical __free_one_page().
|
||||
* @order: The order of the page
|
||||
* @buddy_pfn: The output pointer to the buddy pfn, it also saves a call to
|
||||
* page_to_pfn().
|
||||
*
|
||||
* The found buddy can be a non PageBuddy, out of @page's zone, or its order is
|
||||
* not the same as @page. The validation is necessary before use it.
|
||||
*
|
||||
* Return: the found buddy page or NULL if not found.
|
||||
*/
|
||||
static inline struct page *find_buddy_page_pfn(struct page *page,
|
||||
unsigned long pfn, unsigned int order, unsigned long *buddy_pfn)
|
||||
{
|
||||
unsigned long __buddy_pfn = __find_buddy_pfn(pfn, order);
|
||||
struct page *buddy;
|
||||
|
||||
buddy = page + (__buddy_pfn - pfn);
|
||||
if (buddy_pfn)
|
||||
*buddy_pfn = __buddy_pfn;
|
||||
|
||||
if (page_is_buddy(page, buddy, order))
|
||||
return buddy;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern struct page *__pageblock_pfn_to_page(unsigned long start_pfn,
|
||||
unsigned long end_pfn, struct zone *zone);
|
||||
|
||||
static inline struct page *pageblock_pfn_to_page(unsigned long start_pfn,
|
||||
unsigned long end_pfn, struct zone *zone)
|
||||
{
|
||||
if (zone->contiguous)
|
||||
return pfn_to_page(start_pfn);
|
||||
|
||||
return __pageblock_pfn_to_page(start_pfn, end_pfn, zone);
|
||||
}
|
||||
|
||||
void set_zone_contiguous(struct zone *zone);
|
||||
bool pfn_range_intersects_zones(int nid, unsigned long start_pfn,
|
||||
@@ -831,8 +672,6 @@ extern int __isolate_free_page(struct page *page, unsigned int order);
|
||||
extern void __putback_isolated_page(struct page *page, unsigned int order,
|
||||
int mt);
|
||||
extern void memblock_free_pages(unsigned long pfn, unsigned int order);
|
||||
extern void __free_pages_core(struct page *page, unsigned int order,
|
||||
enum meminit_context context);
|
||||
|
||||
/*
|
||||
* This will have no effect, other than possibly generating a warning, if the
|
||||
@@ -914,40 +753,6 @@ static inline void init_compound_tail(struct page *tail,
|
||||
prep_compound_tail(tail, head, order);
|
||||
}
|
||||
|
||||
void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flags);
|
||||
extern bool free_pages_prepare(struct page *page, unsigned int order);
|
||||
|
||||
extern int user_min_free_kbytes;
|
||||
|
||||
struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, int nid,
|
||||
nodemask_t *nodemask);
|
||||
#define __alloc_frozen_pages(...) \
|
||||
alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__))
|
||||
void free_frozen_pages(struct page *page, unsigned int order);
|
||||
void free_unref_folios(struct folio_batch *fbatch);
|
||||
|
||||
#ifdef CONFIG_NUMA
|
||||
struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order);
|
||||
#else
|
||||
static inline struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order)
|
||||
{
|
||||
return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define alloc_frozen_pages(...) \
|
||||
alloc_hooks(alloc_frozen_pages_noprof(__VA_ARGS__))
|
||||
|
||||
struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order);
|
||||
#define alloc_frozen_pages_nolock(...) \
|
||||
alloc_hooks(alloc_frozen_pages_nolock_noprof(__VA_ARGS__))
|
||||
void free_frozen_pages_nolock(struct page *page, unsigned int order);
|
||||
|
||||
extern void zone_pcp_reset(struct zone *zone);
|
||||
extern void zone_pcp_disable(struct zone *zone);
|
||||
extern void zone_pcp_enable(struct zone *zone);
|
||||
extern void zone_pcp_init(struct zone *zone);
|
||||
|
||||
extern void *memmap_alloc(phys_addr_t size, phys_addr_t align,
|
||||
phys_addr_t min_addr,
|
||||
int nid, bool exact_nid);
|
||||
@@ -1101,23 +906,6 @@ static inline void init_cma_pageblock(struct page *page)
|
||||
}
|
||||
#endif
|
||||
|
||||
enum fallback_result {
|
||||
/* Found suitable migratetype, *mt_out is valid. */
|
||||
FALLBACK_FOUND,
|
||||
/* No fallback found in requested order. */
|
||||
FALLBACK_EMPTY,
|
||||
/* Passed @claimable, but claiming whole block is a bad idea. */
|
||||
FALLBACK_NOCLAIM,
|
||||
};
|
||||
enum fallback_result
|
||||
find_suitable_fallback(struct free_area *area, unsigned int order,
|
||||
int migratetype, bool claimable, int *mt_out);
|
||||
|
||||
static inline bool free_area_empty(struct free_area *area, int migratetype)
|
||||
{
|
||||
return list_empty(&area->free_list[migratetype]);
|
||||
}
|
||||
|
||||
/* mm/util.c */
|
||||
struct anon_vma *folio_anon_vma(const struct folio *folio);
|
||||
|
||||
@@ -1445,46 +1233,6 @@ extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,
|
||||
unsigned long reclaim_pages(struct list_head *folio_list);
|
||||
unsigned int reclaim_clean_pages_from_list(struct zone *zone,
|
||||
struct list_head *folio_list);
|
||||
/* The ALLOC_WMARK bits are used as an index to zone->watermark */
|
||||
#define ALLOC_WMARK_MIN WMARK_MIN
|
||||
#define ALLOC_WMARK_LOW WMARK_LOW
|
||||
#define ALLOC_WMARK_HIGH WMARK_HIGH
|
||||
#define ALLOC_NO_WATERMARKS 0x04 /* don't check watermarks at all */
|
||||
|
||||
/* Mask to get the watermark bits */
|
||||
#define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1)
|
||||
|
||||
/*
|
||||
* Only MMU archs have async oom victim reclaim - aka oom_reaper so we
|
||||
* cannot assume a reduced access to memory reserves is sufficient for
|
||||
* !MMU
|
||||
*/
|
||||
#ifdef CONFIG_MMU
|
||||
#define ALLOC_OOM 0x08
|
||||
#else
|
||||
#define ALLOC_OOM ALLOC_NO_WATERMARKS
|
||||
#endif
|
||||
|
||||
#define ALLOC_NON_BLOCK 0x10 /* Caller cannot block. Allow access
|
||||
* to 25% of the min watermark or
|
||||
* 62.5% if __GFP_HIGH is set.
|
||||
*/
|
||||
#define ALLOC_MIN_RESERVE 0x20 /* __GFP_HIGH set. Allow access to 50%
|
||||
* of the min watermark.
|
||||
*/
|
||||
#define ALLOC_CPUSET 0x40 /* check for correct cpuset */
|
||||
#define ALLOC_CMA 0x80 /* allow allocations from CMA areas */
|
||||
#ifdef CONFIG_ZONE_DMA32
|
||||
#define ALLOC_NOFRAGMENT 0x100 /* avoid mixing pageblock types */
|
||||
#else
|
||||
#define ALLOC_NOFRAGMENT 0x0
|
||||
#endif
|
||||
#define ALLOC_HIGHATOMIC 0x200 /* Allows access to MIGRATE_HIGHATOMIC */
|
||||
#define ALLOC_NOLOCK 0x400 /* Only use spin_trylock in allocation path */
|
||||
#define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */
|
||||
|
||||
/* Flags that allow allocations below the min watermark. */
|
||||
#define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM)
|
||||
|
||||
enum ttu_flags;
|
||||
struct tlbflush_unmap_batch;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <asm/tlb.h>
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "mm_slot.h"
|
||||
|
||||
enum scan_result {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <linux/mm.h>
|
||||
#include <linux/memblock.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../page_alloc.h"
|
||||
|
||||
#define NUM_FUTURE_RANGES 128
|
||||
struct start_end_pair {
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
#include <trace/events/memory-failure.h>
|
||||
|
||||
#include "swap.h"
|
||||
#include "page_alloc.h"
|
||||
#include "internal.h"
|
||||
|
||||
static int sysctl_memory_failure_early_kill __read_mostly;
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <asm/tlbflush.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "shuffle.h"
|
||||
|
||||
enum {
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
#include <linux/memory.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
|
||||
/* Internal flags */
|
||||
#define MPOL_MF_DISCONTIG_OK (MPOL_MF_INTERNAL << 0) /* Skip checks for continuous vmas */
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <trace/events/migrate.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "swap.h"
|
||||
|
||||
static const struct movable_operations *offline_movable_ops;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <linux/kexec_handover.h>
|
||||
#include <linux/hugetlb.h>
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "slab.h"
|
||||
#include "shuffle.h"
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include <linux/pgalloc_tag.h>
|
||||
#include <asm/div64.h>
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "shuffle.h"
|
||||
#include "page_reporting.h"
|
||||
|
||||
|
||||
269
mm/page_alloc.h
Normal file
269
mm/page_alloc.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* mm-internal API for the page (buddy) allocator. Public API lives in
|
||||
* include/linux/gfp.h.
|
||||
*/
|
||||
#ifndef __MM_PAGE_ALLOC_H
|
||||
#define __MM_PAGE_ALLOC_H
|
||||
|
||||
#include <linux/mm.h>
|
||||
#include <linux/mmzone.h>
|
||||
#include <linux/nodemask.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
/* The ALLOC_WMARK bits are used as an index to zone->watermark */
|
||||
#define ALLOC_WMARK_MIN WMARK_MIN
|
||||
#define ALLOC_WMARK_LOW WMARK_LOW
|
||||
#define ALLOC_WMARK_HIGH WMARK_HIGH
|
||||
#define ALLOC_NO_WATERMARKS 0x04 /* don't check watermarks at all */
|
||||
|
||||
/* Mask to get the watermark bits */
|
||||
#define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1)
|
||||
|
||||
/*
|
||||
* Only MMU archs have async oom victim reclaim - aka oom_reaper so we
|
||||
* cannot assume a reduced access to memory reserves is sufficient for
|
||||
* !MMU
|
||||
*/
|
||||
#ifdef CONFIG_MMU
|
||||
#define ALLOC_OOM 0x08
|
||||
#else
|
||||
#define ALLOC_OOM ALLOC_NO_WATERMARKS
|
||||
#endif
|
||||
|
||||
#define ALLOC_NON_BLOCK 0x10 /* Caller cannot block. Allow access
|
||||
* to 25% of the min watermark or
|
||||
* 62.5% if __GFP_HIGH is set.
|
||||
*/
|
||||
#define ALLOC_MIN_RESERVE 0x20 /* __GFP_HIGH set. Allow access to 50%
|
||||
* of the min watermark.
|
||||
*/
|
||||
#define ALLOC_CPUSET 0x40 /* check for correct cpuset */
|
||||
#define ALLOC_CMA 0x80 /* allow allocations from CMA areas */
|
||||
#ifdef CONFIG_ZONE_DMA32
|
||||
#define ALLOC_NOFRAGMENT 0x100 /* avoid mixing pageblock types */
|
||||
#else
|
||||
#define ALLOC_NOFRAGMENT 0x0
|
||||
#endif
|
||||
#define ALLOC_HIGHATOMIC 0x200 /* Allows access to MIGRATE_HIGHATOMIC */
|
||||
#define ALLOC_NOLOCK 0x400 /* Only use spin_trylock in allocation path */
|
||||
#define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */
|
||||
|
||||
/* Flags that allow allocations below the min watermark. */
|
||||
#define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM)
|
||||
|
||||
/*
|
||||
* Structure for holding the mostly immutable allocation parameters passed
|
||||
* between functions involved in allocations, including the alloc_pages*
|
||||
* family of functions.
|
||||
*
|
||||
* nodemask, migratetype and highest_zoneidx are initialized only once in
|
||||
* __alloc_pages() and then never change.
|
||||
*
|
||||
* zonelist, preferred_zone and highest_zoneidx are set first in
|
||||
* __alloc_pages() for the fast path, and might be later changed
|
||||
* in __alloc_pages_slowpath(). All other functions pass the whole structure
|
||||
* by a const pointer.
|
||||
*/
|
||||
struct alloc_context {
|
||||
struct zonelist *zonelist;
|
||||
const nodemask_t *nodemask;
|
||||
struct zoneref *preferred_zoneref;
|
||||
int migratetype;
|
||||
|
||||
/*
|
||||
* highest_zoneidx represents highest usable zone index of
|
||||
* the allocation request. Due to the nature of the zone,
|
||||
* memory on lower zone than the highest_zoneidx will be
|
||||
* protected by lowmem_reserve[highest_zoneidx].
|
||||
*
|
||||
* highest_zoneidx is also used by reclaim/compaction to limit
|
||||
* the target zone since higher zone than this index cannot be
|
||||
* usable for this allocation request.
|
||||
*/
|
||||
enum zone_type highest_zoneidx;
|
||||
bool spread_dirty_pages;
|
||||
};
|
||||
|
||||
/*
|
||||
* This function returns the order of a free page in the buddy system. In
|
||||
* general, page_zone(page)->lock must be held by the caller to prevent the
|
||||
* page from being allocated in parallel and returning garbage as the order.
|
||||
* If a caller does not hold page_zone(page)->lock, it must guarantee that the
|
||||
* page cannot be allocated or merged in parallel. Alternatively, it must
|
||||
* handle invalid values gracefully, and use buddy_order_unsafe() below.
|
||||
*/
|
||||
static inline unsigned int buddy_order(struct page *page)
|
||||
{
|
||||
/* PageBuddy() must be checked by the caller */
|
||||
return page_private(page);
|
||||
}
|
||||
|
||||
/*
|
||||
* Like buddy_order(), but for callers who cannot afford to hold the zone lock.
|
||||
* PageBuddy() should be checked first by the caller to minimize race window,
|
||||
* and invalid values must be handled gracefully.
|
||||
*
|
||||
* READ_ONCE is used so that if the caller assigns the result into a local
|
||||
* variable and e.g. tests it for valid range before using, the compiler cannot
|
||||
* decide to remove the variable and inline the page_private(page) multiple
|
||||
* times, potentially observing different values in the tests and the actual
|
||||
* use of the result.
|
||||
*/
|
||||
#define buddy_order_unsafe(page) READ_ONCE(page_private(page))
|
||||
|
||||
/*
|
||||
* This function checks whether a page is free && is the buddy
|
||||
* we can coalesce a page and its buddy if
|
||||
* (a) the buddy is not in a hole (check before calling!) &&
|
||||
* (b) the buddy is in the buddy system &&
|
||||
* (c) a page and its buddy have the same order &&
|
||||
* (d) a page and its buddy are in the same zone.
|
||||
*
|
||||
* For recording whether a page is in the buddy system, we set PageBuddy.
|
||||
* Setting, clearing, and testing PageBuddy is serialized by zone->lock.
|
||||
*
|
||||
* For recording page's order, we use page_private(page).
|
||||
*/
|
||||
static inline bool page_is_buddy(struct page *page, struct page *buddy,
|
||||
unsigned int order)
|
||||
{
|
||||
if (!page_is_guard(buddy) && !PageBuddy(buddy))
|
||||
return false;
|
||||
|
||||
if (buddy_order(buddy) != order)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* zone check is done late to avoid uselessly calculating
|
||||
* zone/node ids for pages that could never merge.
|
||||
*/
|
||||
if (page_zone_id(page) != page_zone_id(buddy))
|
||||
return false;
|
||||
|
||||
VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate the struct page for both the matching buddy in our
|
||||
* pair (buddy1) and the combined O(n+1) page they form (page).
|
||||
*
|
||||
* 1) Any buddy B1 will have an order O twin B2 which satisfies
|
||||
* the following equation:
|
||||
* B2 = B1 ^ (1 << O)
|
||||
* For example, if the starting buddy (buddy2) is #8 its order
|
||||
* 1 buddy is #10:
|
||||
* B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
|
||||
*
|
||||
* 2) Any buddy B will have an order O+1 parent P which
|
||||
* satisfies the following equation:
|
||||
* P = B & ~(1 << O)
|
||||
*
|
||||
* Assumption: *_mem_map is contiguous at least up to MAX_PAGE_ORDER
|
||||
*/
|
||||
static inline unsigned long
|
||||
__find_buddy_pfn(unsigned long page_pfn, unsigned int order)
|
||||
{
|
||||
return page_pfn ^ (1 << order);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the buddy of @page and validate it.
|
||||
* @page: The input page
|
||||
* @pfn: The pfn of the page, it saves a call to page_to_pfn() when the
|
||||
* function is used in the performance-critical __free_one_page().
|
||||
* @order: The order of the page
|
||||
* @buddy_pfn: The output pointer to the buddy pfn, it also saves a call to
|
||||
* page_to_pfn().
|
||||
*
|
||||
* The found buddy can be a non PageBuddy, out of @page's zone, or its order is
|
||||
* not the same as @page. The validation is necessary before use it.
|
||||
*
|
||||
* Return: the found buddy page or NULL if not found.
|
||||
*/
|
||||
static inline struct page *find_buddy_page_pfn(struct page *page,
|
||||
unsigned long pfn, unsigned int order, unsigned long *buddy_pfn)
|
||||
{
|
||||
unsigned long __buddy_pfn = __find_buddy_pfn(pfn, order);
|
||||
struct page *buddy;
|
||||
|
||||
buddy = page + (__buddy_pfn - pfn);
|
||||
if (buddy_pfn)
|
||||
*buddy_pfn = __buddy_pfn;
|
||||
|
||||
if (page_is_buddy(page, buddy, order))
|
||||
return buddy;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern struct page *__pageblock_pfn_to_page(unsigned long start_pfn,
|
||||
unsigned long end_pfn, struct zone *zone);
|
||||
|
||||
static inline struct page *pageblock_pfn_to_page(unsigned long start_pfn,
|
||||
unsigned long end_pfn, struct zone *zone)
|
||||
{
|
||||
if (zone->contiguous)
|
||||
return pfn_to_page(start_pfn);
|
||||
|
||||
return __pageblock_pfn_to_page(start_pfn, end_pfn, zone);
|
||||
}
|
||||
|
||||
extern void __free_pages_core(struct page *page, unsigned int order,
|
||||
enum meminit_context context);
|
||||
|
||||
void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flags);
|
||||
extern bool free_pages_prepare(struct page *page, unsigned int order);
|
||||
|
||||
extern int user_min_free_kbytes;
|
||||
|
||||
struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, int nid,
|
||||
nodemask_t *nodemask);
|
||||
#define __alloc_frozen_pages(...) \
|
||||
alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__))
|
||||
void free_frozen_pages(struct page *page, unsigned int order);
|
||||
void free_unref_folios(struct folio_batch *fbatch);
|
||||
|
||||
#ifdef CONFIG_NUMA
|
||||
struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order);
|
||||
#else
|
||||
static inline struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order)
|
||||
{
|
||||
return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define alloc_frozen_pages(...) \
|
||||
alloc_hooks(alloc_frozen_pages_noprof(__VA_ARGS__))
|
||||
|
||||
struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order);
|
||||
#define alloc_frozen_pages_nolock(...) \
|
||||
alloc_hooks(alloc_frozen_pages_nolock_noprof(__VA_ARGS__))
|
||||
void free_frozen_pages_nolock(struct page *page, unsigned int order);
|
||||
|
||||
extern void zone_pcp_reset(struct zone *zone);
|
||||
extern void zone_pcp_disable(struct zone *zone);
|
||||
extern void zone_pcp_enable(struct zone *zone);
|
||||
extern void zone_pcp_init(struct zone *zone);
|
||||
|
||||
enum fallback_result {
|
||||
/* Found suitable migratetype, *mt_out is valid. */
|
||||
FALLBACK_FOUND,
|
||||
/* No fallback found in requested order. */
|
||||
FALLBACK_EMPTY,
|
||||
/* Passed @claimable, but claiming whole block is a bad idea. */
|
||||
FALLBACK_NOCLAIM,
|
||||
};
|
||||
enum fallback_result
|
||||
find_suitable_fallback(struct free_area *area, unsigned int order,
|
||||
int migratetype, bool claimable, int *mt_out);
|
||||
|
||||
static inline bool free_area_empty(struct free_area *area, int migratetype)
|
||||
{
|
||||
return list_empty(&area->free_list[migratetype]);
|
||||
}
|
||||
|
||||
void page_alloc_sysctl_init(void);
|
||||
|
||||
#endif /* __MM_PAGE_ALLOC_H */
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <linux/init.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/page_frag_cache.h>
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
|
||||
static unsigned long encoded_page_create(struct page *page, unsigned int order,
|
||||
bool pfmemalloc)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <linux/page_owner.h>
|
||||
#include <linux/migrate.h>
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include <trace/events/page_isolation.h>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <linux/memcontrol.h>
|
||||
#include <linux/sched/clock.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
|
||||
/*
|
||||
* TODO: teach PAGE_OWNER_STACK_DEPTH (__dump_page_owner and save_stack)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <linux/delay.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
#include "page_alloc.h"
|
||||
#include "page_reporting.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <linux/vmstat.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "swap.h"
|
||||
|
||||
atomic_long_t _totalram_pages __read_mostly;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <linux/random.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "shuffle.h"
|
||||
|
||||
DEFINE_STATIC_KEY_FALSE(page_alloc_shuffle_key);
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include <trace/events/kmem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
|
||||
/*
|
||||
* Lock order:
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <linux/buffer_head.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include <trace/events/pagemap.h>
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
#include <linux/sched/sysctl.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "page_alloc.h"
|
||||
#include "swap.h"
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
|
||||
Reference in New Issue
Block a user