Contributors: 24
Author Tokens Token Proportion Commits Commit Proportion
Yasunori Goto 129 31.77% 2 5.56%
Song Muchun 92 22.66% 2 5.56%
Matthew Wilcox 29 7.14% 2 5.56%
Yasuaki Ishimatsu 25 6.16% 1 2.78%
Linus Torvalds (pre-git) 21 5.17% 3 8.33%
Dave Hansen 19 4.68% 3 8.33%
Liu Shixin 16 3.94% 2 5.56%
David Hildenbrand (Red Hat) 15 3.69% 1 2.78%
Andrea Arcangeli 10 2.46% 1 2.78%
van der Linden, Frank 8 1.97% 1 2.78%
Andi Kleen 7 1.72% 2 5.56%
Badari Pulavarty 6 1.48% 1 2.78%
Dan J Williams 5 1.23% 2 5.56%
Kamezawa Hiroyuki 4 0.99% 2 5.56%
Andy Whitcroft 4 0.99% 1 2.78%
Yinghai Lu 3 0.74% 1 2.78%
Jiang Liu 3 0.74% 2 5.56%
Wen Congyang 3 0.74% 1 2.78%
JoonSoo Kim 2 0.49% 1 2.78%
David Howells 1 0.25% 1 2.78%
Adrian Bunk 1 0.25% 1 2.78%
Oscar Salvador 1 0.25% 1 2.78%
Linus Torvalds 1 0.25% 1 2.78%
Greg Kroah-Hartman 1 0.25% 1 2.78%
Total 406 36


// SPDX-License-Identifier: GPL-2.0
/*
 * Bootmem core functions.
 *
 * Copyright (c) 2020, Bytedance.
 *
 *     Author: Muchun Song <songmuchun@bytedance.com>
 *
 */
#include <linux/mm.h>
#include <linux/compiler.h>
#include <linux/memblock.h>
#include <linux/bootmem_info.h>
#include <linux/memory_hotplug.h>
#include <linux/kmemleak.h>

void get_page_bootmem(unsigned long info, struct page *page,
		enum bootmem_type type)
{
	BUG_ON(type > 0xf);
	BUG_ON(info > (ULONG_MAX >> 4));
	SetPagePrivate(page);
	set_page_private(page, info << 4 | type);
	page_ref_inc(page);
}

void put_page_bootmem(struct page *page)
{
	enum bootmem_type type = bootmem_type(page);

	BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE ||
	       type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);

	if (page_ref_dec_return(page) == 1) {
		ClearPagePrivate(page);
		set_page_private(page, 0);
		INIT_LIST_HEAD(&page->lru);
		kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
		free_reserved_page(page);
	}
}

static void __init register_page_bootmem_info_section(unsigned long start_pfn)
{
	unsigned long mapsize, section_nr, i;
	struct mem_section *ms;
	struct mem_section_usage *usage;
	struct page *page;

	start_pfn = SECTION_ALIGN_DOWN(start_pfn);
	section_nr = pfn_to_section_nr(start_pfn);
	ms = __nr_to_section(section_nr);

	if (!preinited_vmemmap_section(ms))
		register_page_bootmem_memmap(section_nr, pfn_to_page(start_pfn),
					     PAGES_PER_SECTION);

	usage = ms->usage;
	page = virt_to_page(usage);

	mapsize = PAGE_ALIGN(mem_section_usage_size()) >> PAGE_SHIFT;

	for (i = 0; i < mapsize; i++, page++)
		get_page_bootmem(section_nr, page, MIX_SECTION_INFO);
}

void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
{
	unsigned long i, pfn, end_pfn, nr_pages;
	int node = pgdat->node_id;
	struct page *page;

	nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
	page = virt_to_page(pgdat);

	for (i = 0; i < nr_pages; i++, page++)
		get_page_bootmem(node, page, NODE_INFO);

	pfn = pgdat->node_start_pfn;
	end_pfn = pgdat_end_pfn(pgdat);

	/* register section info */
	for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
		/*
		 * Some platforms can assign the same pfn to multiple nodes - on
		 * node0 as well as nodeN.  To avoid registering a pfn against
		 * multiple nodes we check that this pfn does not already
		 * reside in some other nodes.
		 */
		if (pfn_valid(pfn) && (early_pfn_to_nid(pfn) == node))
			register_page_bootmem_info_section(pfn);
	}
}