Skip to content

Commit 4e6ea4e

Browse files
committed
srcu: Make early-boot call_srcu() reuse workqueue lists
Allocating a list_head structure that is almost never used, and, when used, is used only during early boot (rcu_init() and earlier), is a bit wasteful. This commit therefore eliminates that list_head in favor of the one in the work_struct structure. This is safe because the work_struct structure cannot be used until after rcu_init() returns. Reported-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Tejun Heo <tj@kernel.org> Cc: Lai Jiangshan <jiangshanlai@gmail.com> Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 55cda22 commit 4e6ea4e

4 files changed

Lines changed: 11 additions & 15 deletions

File tree

‎include/linux/srcutiny.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct srcu_struct {
3636
struct rcu_head *srcu_cb_head; /* Pending callbacks: Head. */
3737
struct rcu_head **srcu_cb_tail; /* Pending callbacks: Tail. */
3838
struct work_struct srcu_work; /* For driving grace periods. */
39-
struct list_head srcu_boot_entry; /* Early-boot callbacks. */
4039
#ifdef CONFIG_DEBUG_LOCK_ALLOC
4140
struct lockdep_map dep_map;
4241
#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
@@ -49,7 +48,6 @@ void srcu_drive_gp(struct work_struct *wp);
4948
.srcu_wq = __SWAIT_QUEUE_HEAD_INITIALIZER(name.srcu_wq), \
5049
.srcu_cb_tail = &name.srcu_cb_head, \
5150
.srcu_work = __WORK_INITIALIZER(name.srcu_work, srcu_drive_gp), \
52-
.srcu_boot_entry = LIST_HEAD_INIT(name.srcu_boot_entry), \
5351
__SRCU_DEP_MAP_INIT(name) \
5452
}
5553

‎include/linux/srcutree.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ struct srcu_struct {
9494
/* callback for the barrier */
9595
/* operation. */
9696
struct delayed_work work;
97-
struct list_head srcu_boot_entry; /* Early-boot callbacks. */
9897
#ifdef CONFIG_DEBUG_LOCK_ALLOC
9998
struct lockdep_map dep_map;
10099
#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
@@ -110,7 +109,7 @@ struct srcu_struct {
110109
.sda = &pcpu_name, \
111110
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \
112111
.srcu_gp_seq_needed = -1UL, \
113-
.srcu_boot_entry = LIST_HEAD_INIT(name.srcu_boot_entry), \
112+
.work = __DELAYED_WORK_INITIALIZER(name.work, NULL, 0), \
114113
__SRCU_DEP_MAP_INIT(name) \
115114
}
116115

‎kernel/rcu/srcutiny.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int init_srcu_struct_fields(struct srcu_struct *sp)
4848
sp->srcu_gp_waiting = false;
4949
sp->srcu_idx = 0;
5050
INIT_WORK(&sp->srcu_work, srcu_drive_gp);
51-
INIT_LIST_HEAD(&sp->srcu_boot_entry);
51+
INIT_LIST_HEAD(&sp->srcu_work.entry);
5252
return 0;
5353
}
5454

@@ -185,8 +185,8 @@ void call_srcu(struct srcu_struct *sp, struct rcu_head *rhp,
185185
if (!READ_ONCE(sp->srcu_gp_running)) {
186186
if (likely(srcu_init_done))
187187
schedule_work(&sp->srcu_work);
188-
else if (list_empty(&sp->srcu_boot_entry))
189-
list_add(&sp->srcu_boot_entry, &srcu_boot_list);
188+
else if (list_empty(&sp->srcu_work.entry))
189+
list_add(&sp->srcu_work.entry, &srcu_boot_list);
190190
}
191191
}
192192
EXPORT_SYMBOL_GPL(call_srcu);
@@ -224,8 +224,8 @@ void __init srcu_init(void)
224224
srcu_init_done = true;
225225
while (!list_empty(&srcu_boot_list)) {
226226
sp = list_first_entry(&srcu_boot_list,
227-
struct srcu_struct, srcu_boot_entry);
228-
list_del_init(&sp->srcu_boot_entry);
227+
struct srcu_struct, srcu_work.entry);
228+
list_del_init(&sp->srcu_work.entry);
229229
schedule_work(&sp->srcu_work);
230230
}
231231
}

‎kernel/rcu/srcutree.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ static int init_srcu_struct_fields(struct srcu_struct *sp, bool is_static)
186186
mutex_init(&sp->srcu_barrier_mutex);
187187
atomic_set(&sp->srcu_barrier_cpu_cnt, 0);
188188
INIT_DELAYED_WORK(&sp->work, process_srcu);
189-
INIT_LIST_HEAD(&sp->srcu_boot_entry);
190189
if (!is_static)
191190
sp->sda = alloc_percpu(struct srcu_data);
192191
init_srcu_struct_nodes(sp, is_static);
@@ -708,8 +707,8 @@ static void srcu_funnel_gp_start(struct srcu_struct *sp, struct srcu_data *sdp,
708707
if (likely(srcu_init_done))
709708
queue_delayed_work(rcu_gp_wq, &sp->work,
710709
srcu_get_delay(sp));
711-
else if (list_empty(&sp->srcu_boot_entry))
712-
list_add(&sp->srcu_boot_entry, &srcu_boot_list);
710+
else if (list_empty(&sp->work.work.entry))
711+
list_add(&sp->work.work.entry, &srcu_boot_list);
713712
}
714713
spin_unlock_irqrestore_rcu_node(sp, flags);
715714
}
@@ -1323,10 +1322,10 @@ void __init srcu_init(void)
13231322

13241323
srcu_init_done = true;
13251324
while (!list_empty(&srcu_boot_list)) {
1326-
sp = list_first_entry(&srcu_boot_list,
1327-
struct srcu_struct, srcu_boot_entry);
1325+
sp = list_first_entry(&srcu_boot_list, struct srcu_struct,
1326+
work.work.entry);
13281327
check_init_srcu_struct(sp);
1329-
list_del_init(&sp->srcu_boot_entry);
1328+
list_del_init(&sp->work.work.entry);
13301329
queue_work(rcu_gp_wq, &sp->work.work);
13311330
}
13321331
}

0 commit comments

Comments
 (0)