Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

18.2 Radix Tree Initialization

The initialization function for radix trees is defined within the source file git/lib/radix-tree.c, and its definition is implemented as follows:

void __init radix_tree_init(void)
{
	int ret;
	BUILD_BUG_ON(RADIX_TREE_MAX_TAGS + __GFP_BITS_SHIFT > 32);
	BUILD_BUG_ON(ROOT_IS_IDR & ~GFP_ZONEMASK);
	BUILD_BUG_ON(XA_CHUNK_SIZE > 255);
	radix_tree_node_cachep = kmem_cache_create("radix_tree_node",
			sizeof(struct radix_tree_node), 0,
			SLAB_PANIC | SLAB_RECLAIM_ACCOUNT,
			radix_tree_node_ctor);
	ret = cpuhp_setup_state_nocalls(CPUHP_RADIX_DEAD, "lib/radix:dead",
					NULL, radix_tree_cpu_dead);
	WARN_ON(ret < 0);
}

The function first leverages three BUILD_BUG_ON macro definitions to execute static assertions during the compilation phase. The first macro guarantees that the maximum number of tags supported by the radix tree (typically evaluating to 3) combined with the bit width consumed by the zone memory allocation flags (GFP flags, such as GFP_KERNEL) does not breach a 32-bit threshold. The second macro ensures that the active radix tree instance is not conflict-occupied by the IDR framework, where evaluating ROOT_IS_IDR & ~GFP_ZONEMASK isolates the specific tracking bits used to flag whether the tree is currently active under IDR management. The third macro asserts that the aggregate number of child slots partitioned within a single radix tree chunk node (XA_CHUNK_SIZE) does not exceed 255.

The first concrete runtime task performed by radix_tree_init() is to invoke the function kmem_cache_create() to carve out a dedicated lookaside cache within the slab allocator named "radix_tree_node". This allocation pool is sized to precisely match the byte footprint demanded by the struct radix_tree_node structure—which describes individual nodes across the tree topology—and assigns the base memory address of this slab registry to the tracking pointer radix_tree_node_cachep.

Finally, the radix tree initialization function calls cpuhp_setup_state_nocalls() to register a CPU hotplug tracking step named "lib/radix:dead" targeted at the CPUHP_RADIX_DEAD hotplug state threshold. This is leveraged to manage radix tree internal states whenever a CPU core undergoes a hotplug transition. When a CPU comes online, no callback handler is specified. Conversely, when a CPU drops offline, the system triggers the callback routine radix_tree_cpu_dead() to release orphan resources and migrate pending workloads. The _nocalls suffix dictates that the registration pass will not instantly fire a synchronous invocation of the callback handler.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com