21.3 Offloading RCU Callbacks
As established during the prior architectural breakdown of the RCU mechanism, once a grace period terminates, RCU raises an execution interrupt to fire its callback routines, which physically releases the accumulated memory blocks waiting to be freed. This callback invocation can introduce computational noise and jitter, which penalizes high-performance computing (HPC) tasks and low-latency real-time operations. To insulate performance-sensitive workloads from this overhead under full dynamic clock tick configurations, it is necessary to delegate these memory deallocation tasks to dedicated background kernel threads (rcuo daemons) and completely offload the RCU callbacks from the CPUs running under the full dynamic tick modality.
The primary structural purpose of the function rcu_init_nohz() is to build this precise offloading mechanism, while ensuring that the RCU state machine can cleanly identify which specific CPU cores have entered an "idle/tickless" operational state. This setup prevents the kernel from deadlocking or freezing the entire system while fruitlessly waiting for these "sleeping" processor cores to report their local quiescent states—a bottleneck that would otherwise stall or prevent the RCU grace period from reaching its conclusion. The function rcu_init_nohz() is declared within the source file git/kernel/rcu/tree_plugin.h, and its definition is implemented as follows:
void __init rcu_init_nohz(void)
{
int cpu;
bool need_rcu_nocb_mask = false;
struct rcu_data *rdp;
#if defined(CONFIG_NO_HZ_FULL)
if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask))
need_rcu_nocb_mask = true;
#endif
if (!cpumask_available(rcu_nocb_mask) && need_rcu_nocb_mask) {
if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
return;
}
}
if (!cpumask_available(rcu_nocb_mask))
return;
#if defined(CONFIG_NO_HZ_FULL)
if (tick_nohz_full_running)
cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
#endif
if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
pr_info("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus='
contains nonexistent CPUs.\n");
cpumask_and(rcu_nocb_mask, cpu_possible_mask, rcu_nocb_mask);
}
if (cpumask_empty(rcu_nocb_mask))
pr_info("\tOffload RCU callbacks from CPUs: (none).\n");
else
pr_info("\tOffload RCU callbacks from CPUs: %*pbl.\n", cpumask_pr_args(rcu_nocb_mask));
if (rcu_nocb_poll)
pr_info("\tPoll for callbacks from no-CBs CPUs.\n");
for_each_cpu(cpu, rcu_nocb_mask) {
rdp = per_cpu_ptr(&rcu_data, cpu);
if (rcu_segcblist_empty(&rdp->cblist))
rcu_segcblist_init(&rdp->cblist);
rcu_segcblist_offload(&rdp->cblist);
}
rcu_organize_nocb_kthreads();
}
Figure 21-1 Execution Logic of RCU Callback Offloading
The function first evaluates the CPU mask tick_nohz_full_mask and the global boolean flag tick_nohz_full_running to determine whether any CPU cores require their RCU callbacks to be offloaded. The tick_nohz_full_mask records which explicit CPU cores are configured to operate in full dynamic tickless mode, while tick_nohz_full_running indicates whether the system is currently executing in a comprehensive tickless state. When a user explicitly targets a subset of CPU cores to enter a tickless state during boot via the kernel parameter nohz_full=<cpu_list>, and the kernel image incorporates CONFIG_NO_HZ_FULL, this tracking variable is set to true. If callback offloading is demanded, the system requires a dedicated bitmask variable to track the target cores; hence, need_rcu_nocb_mask evaluates to true.
Following this step, the routine verifies whether the RCU offload bitmask has already been allocated memory and determines if the current build profile requires its allocation, using these checks to dynamically allocate memory for rcu_nocb_mask. The rcu_nocb_mask variable serves as a CPU bitmask pointer (the RCU "offload/isolation" bitmask), whose core architectural purpose is to tag which CPU cores operate in a no-callbacks (no-CBs) modality.
Upon successfully allocating memory for rcu_nocb_mask, the routine invokes the function cpumask_or() to initialize RCU's offload bitmask. It inspects the kernel boot parameters (tick_nohz_full_mask) and copies these CPU assignments into RCU's internal mask array (the memory slot referenced by the rcu_nocb_mask pointer). Guided by this layout, the RCU subsystem identifies which processor cores are exempt from requiring high-frequency scheduling clock interrupts to drive the advancement of the grace period.
To guarantee system stability after resolving which CPU cores undergo callback offloading, the routine dispatches cpumask_and() to audit the target bits against cpu_possible_mask, safely pruning any non-existent physical CPU cores from the rcu_nocb_mask tracking layout.
The tracking variable rcu_nocb_poll leveraged within this routine represents a specialized Linux kernel boot option engineered to optimize systems configured with nohz_full or rcu_nocbs properties. Its primary functional purpose is to alter the operational behavior of RCU callback offloading (Offloading). When this tracking variable is false (the system default status), whenever an isolated CPU core delegates its pending RCU callback tasks over to the backend rcuo daemons, the arrival of a new callback prompts the kernel to assert an Inter-Processor Interrupt (IPI) to awaken the housekeeper CPU core responsible for processing those tasks. Conversely, when this tracking variable evaluates to true, the rcuo background daemon threads periodically poll the execution queues to verify if pending callbacks are present, completely bypassing the interrupt-driven wakeup path.
After emitting the CPU callback offload diagnostic logs via the pr_info() interface, the function executes a traversal via the loop statement for_each_cpu(cpu, rcu_nocb_mask) to iterate across every CPU core flagged within rcu_nocb_mask. It extracts the corresponding rcu_data structure pointer for the active core (the rcu_data descriptor block that preserves the collective RCU state metadata for that processor). If the segmented callback list (Segmented Callback List) belonging to that CPU core has not yet undergone initial configuration, the routine sets it up. The most critical operational pass executed inside this for loop is invoking rcu_segcblist_offload(), which flags the core's callback list to transition into the SEGCBLIST_OFFLOADED state.
Once this tracking state is applied, the subsystem invokes rcu_organize_nocb_kthreads() to instantiate a specialized Grace Period Control Kthread (typically named following the format rcuog/X) for each designated group of offloaded CPU cores, which assumes responsibility for monitoring the grace period state across that collective subset. Furthermore, the routine spawns an independent worker thread (Worker Kthread) for each individual offloaded CPU core, which is tasked exclusively with processing the literal callback functions generated by that core. rcu_organize_nocb_kthreads() links these worker threads directly to their respective leader grace period control threads. This hierarchical arrangement (the Leader-Follower paradigm) minimizes inter-core locking contention over the grace period detection logic and enhances multi-core scalability. Finally, it binds these background rcuo threads to execute exclusively on the designated housekeeper (Housekeeping) CPU cores (the cores operating outside the nohz_full mask), guaranteeing that the performance-sensitive nohz_full cores running critical application workloads are never preempted by these background RCU daemons.
Once this offloading pipeline is fully configured, all RCU callbacks generated by an isolated core bypass its local RCU_SOFTIRQ (software interrupt) handling paths entirely. Instead, they are funneled asynchronously over to the dedicated rcuo threads running on the housekeeper CPU cores.
The architectural essence of rcu_init_nohz() is to signal to the core RCU state machine which explicit CPU cores operate without the scheduling clock tick rhythm, while coordinating the delegation of background bookkeeping tasks to alternative cores to prevent isolated nodes from stalling the global garbage collection timeline.