mm/mm_init.c

Source file repositories/reference/linux-study-clean/mm/mm_init.c

File Facts

System
Linux kernel
Corpus path
mm/mm_init.c
Extension
.c
Size
77817 bytes
Lines
2750
Domain
Core OS
Bucket
Memory Management
Inferred role
Core OS: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mminit_pfnnid_cache {
	unsigned long last_start;
	unsigned long last_end;
	int last_nid;
};

static struct mminit_pfnnid_cache early_pfnnid_cache __meminitdata;

/*
 * Required by SPARSEMEM. Given a PFN, return what node the PFN is on.
 */
static int __meminit __early_pfn_to_nid(unsigned long pfn,
					struct mminit_pfnnid_cache *state)
{
	unsigned long start_pfn, end_pfn;
	int nid;

	if (state->last_start <= pfn && pfn < state->last_end)
		return state->last_nid;

	nid = memblock_search_pfn_nid(pfn, &start_pfn, &end_pfn);
	if (nid != NUMA_NO_NODE) {
		state->last_start = start_pfn;
		state->last_end = end_pfn;
		state->last_nid = nid;
	}

	return nid;
}

int __meminit early_pfn_to_nid(unsigned long pfn)
{
	static DEFINE_SPINLOCK(early_pfn_lock);
	int nid;

	spin_lock(&early_pfn_lock);
	nid = __early_pfn_to_nid(pfn, &early_pfnnid_cache);
	if (nid < 0)
		nid = first_online_node;
	spin_unlock(&early_pfn_lock);

	return nid;
}

bool hashdist = HASHDIST_DEFAULT;

static int __init set_hashdist(char *str)
{
	return kstrtobool(str, &hashdist) == 0;
}
__setup("hashdist=", set_hashdist);

static inline void fixup_hashdist(void)
{
	if (num_node_state(N_MEMORY) == 1)
		hashdist = false;
}
#else
static inline void fixup_hashdist(void) {}
#endif /* CONFIG_NUMA */

#ifdef CONFIG_ZONE_DEVICE
static __meminit void pageblock_migratetype_init_range(unsigned long pfn,
		unsigned long nr_pages, int migratetype)
{
	const unsigned long end = pfn + nr_pages;

	for (pfn = pageblock_align(pfn); pfn < end; pfn += pageblock_nr_pages) {
		init_pageblock_migratetype(pfn_to_page(pfn), migratetype, false);
		if (IS_ALIGNED(pfn, PAGES_PER_SECTION))
			cond_resched();
	}
}
#endif

/*
 * Initialize a reserved page unconditionally, finding its zone first.
 */
void __meminit __init_page_from_nid(unsigned long pfn, int nid)
{
	pg_data_t *pgdat;
	int zid;

	pgdat = NODE_DATA(nid);

	for (zid = 0; zid < MAX_NR_ZONES; zid++) {
		struct zone *zone = &pgdat->node_zones[zid];

		if (zone_spans_pfn(zone, pfn))
			break;

Annotation

Implementation Notes