Skip to content

Commit db13710

Browse files
committed
rcu-tasks: Cancel callback laziness if too many callbacks
The various RCU Tasks flavors now do lazy grace periods when there are only asynchronous grace period requests. By default, the system will let 250 milliseconds elapse after the first call_rcu_tasks*() callbacki is queued before starting a grace period. In contrast, synchronous grace period requests such as synchronize_rcu_tasks*() will start a grace period immediately. However, invoking one of the call_rcu_tasks*() functions in a too-tight loop can result in a callback flood, which in turn can exhaust memory if grace periods are delayed for too long. This commit therefore sets a limit so that the grace-period kthread will be awakened when any CPU's callback list expands to contain rcupdate.rcu_task_lazy_lim callbacks elements (defaulting to 32, set to -1 to disable), the grace-period kthread will be awakened, thus cancelling any ongoing laziness and getting out in front of the potential callback flood. Cc: Alexei Starovoitov <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Andrii Nakryiko <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 450d461 commit db13710

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5264,6 +5264,13 @@
52645264
number avoids disturbing real-time workloads,
52655265
but lengthens grace periods.
52665266

5267+
rcupdate.rcu_task_lazy_lim= [KNL]
5268+
Number of callbacks on a given CPU that will
5269+
cancel laziness on that CPU. Use -1 to disable
5270+
cancellation of laziness, but be advised that
5271+
doing so increases the danger of OOM due to
5272+
callback flooding.
5273+
52675274
rcupdate.rcu_task_stall_info= [KNL]
52685275
Set initial timeout in jiffies for RCU task stall
52695276
informational messages, which give some indication

kernel/rcu/tasks.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ static int rcu_task_contend_lim __read_mostly = 100;
176176
module_param(rcu_task_contend_lim, int, 0444);
177177
static int rcu_task_collapse_lim __read_mostly = 10;
178178
module_param(rcu_task_collapse_lim, int, 0444);
179+
static int rcu_task_lazy_lim __read_mostly = 32;
180+
module_param(rcu_task_lazy_lim, int, 0444);
179181

180182
/* RCU tasks grace-period state for debugging. */
181183
#define RTGS_INIT 0
@@ -354,8 +356,9 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
354356
cblist_init_generic(rtp);
355357
raw_spin_lock_rcu_node(rtpcp); // irqs already disabled.
356358
}
357-
needwake = func == wakeme_after_rcu;
358-
if (havekthread && !timer_pending(&rtpcp->lazy_timer)) {
359+
needwake = (func == wakeme_after_rcu) ||
360+
(rcu_segcblist_n_cbs(&rtpcp->cblist) == rcu_task_lazy_lim);
361+
if (havekthread && !needwake && !timer_pending(&rtpcp->lazy_timer)) {
359362
if (rtp->lazy_jiffies)
360363
mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp));
361364
else

0 commit comments

Comments
 (0)