Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __LINUX_BOOTMEM_INFO_H
3#define __LINUX_BOOTMEM_INFO_H
4
5#include <linux/mm.h>
6#include <linux/kmemleak.h>
7
8/*
9 * Types for free bootmem stored in the low bits of page->private.
10 */
11enum bootmem_type {
12 MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 1,
13 SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE,
14 MIX_SECTION_INFO,
15 NODE_INFO,
16 MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
17};
18
19#ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
20void __init register_page_bootmem_info_node(struct pglist_data *pgdat);
21void register_page_bootmem_memmap(unsigned long section_nr, struct page *map,
22 unsigned long nr_pages);
23
24void get_page_bootmem(unsigned long info, struct page *page,
25 enum bootmem_type type);
26void put_page_bootmem(struct page *page);
27
28static inline enum bootmem_type bootmem_type(const struct page *page)
29{
30 return (unsigned long)page->private & 0xf;
31}
32
33static inline unsigned long bootmem_info(const struct page *page)
34{
35 return (unsigned long)page->private >> 4;
36}
37
38/*
39 * Any memory allocated via the memblock allocator and not via the
40 * buddy will be marked reserved already in the memmap. For those
41 * pages, we can call this function to free it to buddy allocator.
42 */
43static inline void free_bootmem_page(struct page *page)
44{
45 enum bootmem_type type = bootmem_type(page);
46
47 VM_BUG_ON_PAGE(page_ref_count(page) != 2, page);
48
49 if (type == SECTION_INFO || type == MIX_SECTION_INFO)
50 put_page_bootmem(page);
51 else
52 VM_BUG_ON_PAGE(1, page);
53}
54#else
55static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
56{
57}
58
59static inline void register_page_bootmem_memmap(unsigned long section_nr,
60 struct page *map, unsigned long nr_pages)
61{
62}
63
64static inline void put_page_bootmem(struct page *page)
65{
66}
67
68static inline enum bootmem_type bootmem_type(const struct page *page)
69{
70 return SECTION_INFO;
71}
72
73static inline unsigned long bootmem_info(const struct page *page)
74{
75 return 0;
76}
77
78static inline void get_page_bootmem(unsigned long info, struct page *page,
79 enum bootmem_type type)
80{
81}
82
83static inline void free_bootmem_page(struct page *page)
84{
85 kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
86 free_reserved_page(page);
87}
88#endif
89
90#endif /* __LINUX_BOOTMEM_INFO_H */