kfree_rcu() additions for -rcu
Subsystems (4)
v2 cover kfree_rcu() additions for -rcu
Hi,
This is a series on top of the patch "rcu/tree: Add basic support for kfree_rcu() batching".
It adds performance tests, some clean ups and removal of "lazy" RCU callbacks.
Now that kfree_rcu() is handled separately from call_rcu(), we also get rid of kfree "lazy" handling from tree RCU as suggested by Paul which will be unused.
Based on patch:
v1 series:
https://lkml.org/lkml/2019/8/27/1315 https://lore.kernel.org/patchwork/project/lkml/list/?series=408218
Joel Fernandes (Google) (5):
rcu/rcuperf: Add kfree_rcu() performance Tests rcu/tree: Add multiple in-flight batches of kfree_rcu work rcu/tree: Add support for debug_objects debugging for kfree_rcu()
rcu: Remove kfree_rcu() special casing and lazy handling
rcu: Remove kfree_call_rcu_nobatch()
Documentation/RCU/stallwarn.txt | 11 +- .../admin-guide/kernel-parameters.txt | 13 ++ include/linux/rcu_segcblist.h | 2 - include/linux/rcutiny.h | 5 - include/linux/rcutree.h | 1 - include/trace/events/rcu.h | 32 ++-- kernel/rcu/rcu.h | 27 --- kernel/rcu/rcu_segcblist.c | 25 +-- kernel/rcu/rcu_segcblist.h | 25 +-- kernel/rcu/rcuperf.c | 173 +++++++++++++++++- kernel/rcu/srcutree.c | 4 +- kernel/rcu/tiny.c | 29 ++- kernel/rcu/tree.c | 155 ++++++++++------ kernel/rcu/tree.h | 1 - kernel/rcu/tree_plugin.h | 48 ++--- kernel/rcu/tree_stall.h | 6 +- 16 files changed, 343 insertions(+), 214 deletions(-)
--
2.23.0.187.g17f5b7556c-goog
PATCH v2 1/5 rcu/rcuperf: Add kfree_rcu() performance Tests
This test runs kfree_rcu() in a loop to measure performance of the new kfree_rcu() batching functionality.
The following table shows results when booting with arguments:
rcuperf.kfree_loops=20000 rcuperf.kfree_alloc_num=8000 rcuperf.kfree_rcu_test=1 rcuperf.kfree_no_batch=X
rcuperf.kfree_no_batch=X # Grace Periods Test Duration (s)
X=1 (old behavior) 9133 11.5 X=0 (new behavior) 1732 12.5
On a 16 CPU system with the above boot parameters, we see that the total number of grace periods that elapse during the test drops from 9133 when not batching to 1732 when batching (a 5X improvement). The kfree_rcu() flood itself slows down a bit when batching, though, as shown.
Note that the active memory consumption during the kfree_rcu() flood does increase to around 200-250MB due to the batching (from around 50MB without batching). However, this memory consumption is relatively constant. In other words, the system is able to keep up with the kfree_rcu() load. The memory consumption comes down considerably if KFREE_DRAIN_JIFFIES is increased from HZ/50 to HZ/80. A later patch will reduce memory consumption further by using multiple lists.
Also, when running the test, please disable CONFIG_DEBUG_PREEMPT and CONFIG_PROVE_RCU for realistic comparisons with/without batching.
--- .../admin-guide/kernel-parameters.txt | 17 ++ kernel/rcu/rcuperf.c | 181 +++++++++++++++++- 2 files changed, 190 insertions(+), 8 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +17 -0
@@ -3896,6 +3896,23 @@ test until boot completes in order to avoid interference. + rcuperf.kfree_rcu_test= [KNL] + Set to measure performance of kfree_rcu() flooding. + + rcuperf.kfree_nthreads= [KNL] + The number of threads running loops of kfree_rcu(). + + rcuperf.kfree_alloc_num= [KNL] + Number of allocations and frees done in an iteration. + + rcuperf.kfree_loops= [KNL] + Number of loops doing rcuperf.kfree_alloc_num number + of allocations and frees. + + rcuperf.kfree_no_batch= [KNL] + Use the non-batching (less efficient) version of kfree_rcu(). + This is useful for comparing with the batched version. + rcuperf.nreaders= [KNL] Set number of RCU readers. The value -1 selects N, where N is the number of CPUs. A value
kernel/rcu/rcuperf.c +173 -8
227 lines not on this page · raw message
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 2/5 rcu/tree: Add multiple in-flight batches of kfree_rcu work
In reply to Joel Fernandes (Google)During testing, it was observed that amount of memory consumed due kfree_rcu() batching is 300-400MB. Previously we had only a single head_free pointer pointing to the list of rcu_head(s) that are to be freed after a grace period. Until this list is drained, we cannot queue any more objects on it since such objects may not be ready to be reclaimed when the worker thread eventually gets to drainin g the head_free list.
We can do better by maintaining multiple lists as done by this patch. Testing shows that memory consumption came down by around 100-150MB with just adding another list. Adding more than 1 additional list did not show any improvement.
--- kernel/rcu/tree.c | 80 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 24 deletions(-)
kernel/rcu/tree.c +56 -24
@@ -2688,28 +2688,37 @@ EXPORT_SYMBOL_GPL(call_rcu);/* Maximum number of jiffies to wait before draining a batch. */ #define KFREE_DRAIN_JIFFIES (HZ / 50) +#define KFREE_N_BATCHES 2 + +struct kfree_rcu_work { +/* The rcu_work node for queuing work with queue_rcu_work(). The work +* is done after a grace period. +*/ +struct rcu_work rcu_work; + +/* The list of objects that have now left ->head and are queued for +* freeing after a grace period. +*/ +struct rcu_head *head_free; + +struct kfree_rcu_cpu *krcp; +};/* * Maximum number of kfree(s) to batch, if this limit is hit then the batch of * kfree(s) is queued for freeing after a grace period, right away. */ struct kfree_rcu_cpu { -/* The rcu_work node for queuing work with queue_rcu_work(). The work -* is done after a grace period. -*/ -struct rcu_work rcu_work;/* The list of objects being queued in a batch but are not yet * scheduled to be freed. */ struct rcu_head *head; -/* The list of objects that have now left ->head and are queued for -* freeing after a grace period. -*/ -struct rcu_head *head_free; +/* Pointer to the per-cpu array of kfree_rcu_work structures */ +struct kfree_rcu_work krw_arr[KFREE_N_BATCHES ]; -/* Protect concurrent access to this structure. */ +/* Protect concurrent access to this structure and kfree_rcu_work. */ spinlock_t lock;/* The delayed work that flushes ->head to ->head_free incase ->head
@@ -2717,7 +2726,7 @@ struct kfree_rcu_cpu {* is busy, ->head just continues to grow and we retry flushing later. */ struct delayed_work monitor_work; -int monitor_todo;/* Is a delayed work pending execution? */ +bool monitor_todo;/* Is a delayed work pending execution? */ }; static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc);
@@ -2730,12 +2739,15 @@ static void kfree_rcu_work(struct work_struct *work) {unsigned long flags;struct rcu_head *head, *next; -struct kfree_rcu_cpu *krcp =container_of (to_rcu_work (work), - struct kfree_rcu_cpu, rcu_work); +struct kfree_rcu_work *krwp =container_of (to_rcu_work (work), + struct kfree_rcu_work, rcu_work); +struct kfree_rcu_cpu *krcp; + + krcp = krwp->krcp;spin_lock_irqsave (&krcp->lock, flags); - head = krcp->head_free; - krcp->head_free =NULL ; + head = krwp->head_free; + krwp->head_free =NULL ;spin_unlock_irqrestore (&krcp->lock, flags);/*
@@ -2758,19 +2770,30 @@ static void kfree_rcu_work(struct work_struct *work)*/ static inline bool queue_kfree_rcu_work (struct kfree_rcu_cpu *krcp) { +int i =0 ; +struct kfree_rcu_work *krwp =NULL ; +lockdep_assert_held (&krcp->lock); +while (i <KFREE_N_BATCHES ) { +if (!krcp->krw_arr[i].head_free) { + krwp = &(krcp->krw_arr[i]); +break ; + } + i++; + } -/* If a previous RCU batch work is already in progress, we cannot queue +/* +* If both RCU batches are already in progress, we cannot queue * another one, just refuse the optimization and it will be retried * again in KFREE_DRAIN_JIFFIES time. */ -if (krcp->head_free) +if (!krwp)return false; - krcp->head_free = krcp->head; + krwp->head_free = krcp->head; krcp->head =NULL ; -INIT_RCU_WORK (&krcp->rcu_work, kfree_rcu_work); -queue_rcu_work (system_wq, &krcp->rcu_work); +INIT_RCU_WORK (&krwp->rcu_work, kfree_rcu_work); +queue_rcu_work (system_wq, &krwp->rcu_work);return true; }
@@ -2778,7 +2801,8 @@ static inline bool queue_kfree_rcu_work(struct kfree_rcu_cpu *krcp)static inline void kfree_rcu_drain_unlock (struct kfree_rcu_cpu *krcp,unsigned long flags) { -/* Flush ->head to ->head_free, all objects on ->head_free will be +/* +* Flush ->head to ->head_free, all objects on ->head_free will be * kfree'd after a grace period. */ if (queue_kfree_rcu_work (krcp)) {
@@ -2787,11 +2811,14 @@ static inline void kfree_rcu_drain_unlock(struct kfree_rcu_cpu *krcp,return ; } -/* Previous batch that was queued to RCU did not get free yet, let us +/* +* Previous batch that was queued to RCU did not get free yet, let us * try again soon. */ -if (!xchg (&krcp->monitor_todo, true)) +if (!krcp->monitor_todo) { + krcp->monitor_todo = true;schedule_delayed_work (&krcp->monitor_work,KFREE_DRAIN_JIFFIES ); + }spin_unlock_irqrestore (&krcp->lock, flags); }
@@ -2806,10 +2833,12 @@ static void kfree_rcu_monitor(struct work_struct *work) monitor_work.work);spin_lock_irqsave (&krcp->lock, flags); -if (xchg (&krcp->monitor_todo, false)) +if (krcp->monitor_todo) { + krcp->monitor_todo = false;kfree_rcu_drain_unlock (krcp, flags); -else + }else {spin_unlock_irqrestore (&krcp->lock, flags); + } }/*
@@ -3736,8 +3765,11 @@ static void __init kfree_rcu_batch_init(void)for_each_possible_cpu (cpu) {struct kfree_rcu_cpu *krcp =per_cpu_ptr (&krc, cpu); +int i;spin_lock_init (&krcp->lock); +for (i =0 ; i <KFREE_N_BATCHES ; i++) + krcp->krw_arr[i].krcp = krcp;INIT_DELAYED_WORK (&krcp->monitor_work, kfree_rcu_monitor); } }
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 3/5 rcu/tree: Add support for debug_objects debugging for kfree_rcu()
In reply to Joel Fernandes (Google)Make use of RCU's debug_objects debugging support (CONFIG_DEBUG_OBJECTS_RCU_HEAD) similar to call_rcu() and other flavors. We queue the object during the kfree_rcu() call and dequeue it during reclaim.
Tested that enabling CONFIG_DEBUG_OBJECTS_RCU_HEAD successfully detects double kfree_rcu() calls.
--- kernel/rcu/tree.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/rcu/tree.c +8 -0
@@ -2757,6 +2757,7 @@ static void kfree_rcu_work(struct work_struct *work)for (; head; head = next) { next = head->next;/* Could be possible to optimize with kfree_bulk in future */ +debug_rcu_head_unqueue (head);__rcu_reclaim (rcu_state.name, head);cond_resched_tasks_rcu_qs (); }
@@ -2876,6 +2877,13 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)if (rcu_scheduler_active !=RCU_SCHEDULER_RUNNING )return kfree_call_rcu_nobatch (head, func); +if (debug_rcu_head_queue (head)) { +/* Probable double kfree_rcu() */ +WARN_ONCE (1 ,"kfree_call_rcu(): Double-freed call. rcu_head %p\n" , + head); +return ; + } + head->func = func;local_irq_save (flags);/* For safely calling this_cpu_ptr(). */
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 4/5 rcu: Remove kfree_rcu() special casing and lazy handling
In reply to Joel Fernandes (Google)Remove kfree_rcu() special casing and lazy handling from RCU. For Tiny RCU we fold the special handling into just Tiny RCU code.
Results in a nice negative delta as well.
--- Documentation/RCU/stallwarn.txt | 11 +++----- include/linux/rcu_segcblist.h | 2 -- include/trace/events/rcu.h | 32 +++++++++------------- kernel/rcu/rcu.h | 27 ------------------- kernel/rcu/rcu_segcblist.c | 25 +++-------------- kernel/rcu/rcu_segcblist.h | 25 ++--------------- kernel/rcu/srcutree.c | 4 +-- kernel/rcu/tiny.c | 29 +++++++++++++++++++- kernel/rcu/tree.c | 41 +++++++++++++++++++--------- kernel/rcu/tree.h | 1 - kernel/rcu/tree_plugin.h | 48 ++++++++------------------------- kernel/rcu/tree_stall.h | 6 ++--- 12 files changed, 91 insertions(+), 160 deletions(-)
Documentation/RCU/stallwarn.txt +3 -8
@@ -225,18 +225,13 @@ an estimate of the total number of RCU callbacks queued across all CPUs In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed for each CPU: - 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 Nonlazy posted: ..D + 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 dyntick_enabled: 1 The "last_accelerate:" prints the low-order 16 bits (in hex) of the jiffies counter when this CPU last invoked rcu_try_advance_all_cbs() from rcu_needs_cpu() or last invoked rcu_accelerate_cbs() from -rcu_prepare_for_idle(). The "Nonlazy posted:" indicates lazy-callback -status, so that an "l" indicates that all callbacks were lazy at the start -of the last idle period and an "L" indicates that there are currently -no non-lazy callbacks (in both cases, "." is printed otherwise, as -shown above) and "D" indicates that dyntick-idle processing is enabled -("." is printed otherwise, for example, if disabled via the "nohz=" -kernel boot parameter). +rcu_prepare_for_idle(). "dyntick_enabled: 1" indicates that dyntick-idle +processing is enabled. If the grace period ends just as the stall warning starts printing, there will be a spurious stall-warning message, which will include
include/linux/rcu_segcblist.h +0 -2
@@ -22,7 +22,6 @@ struct rcu_cblist {struct rcu_head *head;struct rcu_head **tail;long len; -long len_lazy; };#define RCU_CBLIST_INITIALIZER (n) { .head = NULL, .tail = &n.head }
@@ -73,7 +72,6 @@ struct rcu_segcblist {#else long len;#endif -long len_lazy;u8 enabled;u8 offloaded; };
include/trace/events/rcu.h +12 -20
@@ -481,16 +481,14 @@ TRACE_EVENT_RCU(rcu_dyntick,*/ TRACE_EVENT_RCU(rcu_callback, - TP_PROTO(const char *rcuname, struct rcu_head *rhp, long qlen_lazy, - long qlen), + TP_PROTO(const char *rcuname, struct rcu_head *rhp, long qlen), - TP_ARGS(rcuname, rhp, qlen_lazy, qlen), + TP_ARGS(rcuname, rhp, qlen), TP_STRUCT__entry( __field(const char *, rcuname) __field(void *, rhp) __field(void *, func) - __field(long, qlen_lazy) __field(long, qlen) ),
@@ -498,13 +496,12 @@ TRACE_EVENT_RCU(rcu_callback, __entry->rcuname = rcuname; __entry->rhp = rhp; __entry->func = rhp->func; - __entry->qlen_lazy = qlen_lazy; __entry->qlen = qlen; ), -TP_printk ("%s rhp=%p func=%ps %ld/%ld" , +TP_printk ("%s rhp=%p func=%ps %ld" , __entry->rcuname, __entry->rhp, __entry->func, - __entry->qlen_lazy, __entry->qlen) + __entry->qlen) );/*
@@ -518,15 +515,14 @@ TRACE_EVENT_RCU(rcu_callback, TRACE_EVENT_RCU(rcu_kfree_callback, TP_PROTO(const char *rcuname, struct rcu_head *rhp, unsigned long offset, - long qlen_lazy, long qlen), + long qlen), - TP_ARGS(rcuname, rhp, offset, qlen_lazy, qlen), + TP_ARGS(rcuname, rhp, offset, qlen), TP_STRUCT__entry( __field(const char *, rcuname) __field(void *, rhp) __field(unsigned long, offset) - __field(long, qlen_lazy) __field(long, qlen) ),
@@ -534,13 +530,12 @@ TRACE_EVENT_RCU(rcu_kfree_callback, __entry->rcuname = rcuname; __entry->rhp = rhp; __entry->offset = offset; - __entry->qlen_lazy = qlen_lazy; __entry->qlen = qlen; ), -TP_printk ("%s rhp=%p func=%ld %ld/%ld" , +TP_printk ("%s rhp=%p func=%ld %ld" , __entry->rcuname, __entry->rhp, __entry->offset, - __entry->qlen_lazy, __entry->qlen) + __entry->qlen) );/*
@@ -552,27 +547,24 @@ TRACE_EVENT_RCU(rcu_kfree_callback,*/ TRACE_EVENT_RCU (rcu_batch_start, - TP_PROTO(const char *rcuname, long qlen_lazy, long qlen, long blimit), + TP_PROTO(const char *rcuname, long qlen, long blimit), -TP_ARGS (rcuname, qlen_lazy, qlen, blimit), +TP_ARGS (rcuname, qlen, blimit),TP_STRUCT__entry ( __field(const char *, rcuname) - __field(long, qlen_lazy) __field(long, qlen)__field (long, blimit) ),TP_fast_assign ( __entry->rcuname = rcuname; - __entry->qlen_lazy = qlen_lazy; __entry->qlen = qlen; __entry->blimit = blimit; ), -TP_printk ("%s CBs=%ld/%ld bl=%ld" , - __entry->rcuname, __entry->qlen_lazy, __entry->qlen, - __entry->blimit) +TP_printk ("%s CBs=%ld bl=%ld" , + __entry->rcuname, __entry->qlen, __entry->blimit) );/*
kernel/rcu/rcu.h +0 -27
@@ -198,33 +198,6 @@ static inline void debug_rcu_head_unqueue(struct rcu_head *head) }#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ -void kfree (const void *); - -/* -* Reclaim the specified callback, either by invoking it (non-lazy case) -* or freeing it directly (lazy case). Return true if lazy, false otherwise. -*/ -static inline bool __rcu_reclaim (const char *rn,struct rcu_head *head) -{ -rcu_callback_t f; -unsigned long offset = (unsigned long )head->func; - -rcu_lock_acquire (&rcu_callback_map); -if (__is_kfree_rcu_offset (offset)) { -trace_rcu_invoke_kfree_callback (rn, head, offset); -kfree ((void *)head - offset); -rcu_lock_release (&rcu_callback_map); -return true; - }else { -trace_rcu_invoke_callback (rn, head); - f = head->func; -WRITE_ONCE (head->func, (rcu_callback_t )0L ); -f (head); -rcu_lock_release (&rcu_callback_map); -return false; - } -} -#ifdef CONFIG_RCU_STALL_COMMON extern int rcu_cpu_stall_ftrace_dump;
kernel/rcu/rcu_segcblist.c +3 -22
@@ -20,14 +20,10 @@ void rcu_cblist_init(struct rcu_cblist *rclp) rclp->head =NULL ; rclp->tail = &rclp->head; rclp->len =0 ; - rclp->len_lazy =0 ; }/* * Enqueue an rcu_head structure onto the specified callback list. -* This function assumes that the callback is non-lazy because it -* is intended for use by no-CBs CPUs, which do not distinguish -* between lazy and non-lazy RCU callbacks. */ void rcu_cblist_enqueue (struct rcu_cblist *rclp,struct rcu_head *rhp) {
@@ -54,7 +50,6 @@ void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp,else drclp->tail = &drclp->head; drclp->len = srclp->len; - drclp->len_lazy = srclp->len_lazy;if (!rhp) {rcu_cblist_init (srclp); }else {
@@ -62,16 +57,12 @@ void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp, srclp->head = rhp; srclp->tail = &rhp->next;WRITE_ONCE (srclp->len,1 ); - srclp->len_lazy =0 ; } }/* * Dequeue the oldest rcu_head structure from the specified callback -* list. This function assumes that the callback is non-lazy, but -* the caller can later invoke rcu_cblist_dequeued_lazy() if it -* finds otherwise (and if it cares about laziness). This allows -* different users to have different ways of determining laziness. +* list. */ struct rcu_head *rcu_cblist_dequeue (struct rcu_cblist *rclp) {
@@ -161,7 +152,6 @@ void rcu_segcblist_init(struct rcu_segcblist *rsclp)for (i =0 ; i <RCU_CBLIST_NSEGS ; i++) rsclp->tails[i] = &rsclp->head;rcu_segcblist_set_len (rsclp,0 ); - rsclp->len_lazy =0 ; rsclp->enabled =1 ; }
@@ -173,7 +163,6 @@ void rcu_segcblist_disable(struct rcu_segcblist *rsclp) {WARN_ON_ONCE (!rcu_segcblist_empty (rsclp));WARN_ON_ONCE (rcu_segcblist_n_cbs (rsclp)); -WARN_ON_ONCE (rcu_segcblist_n_lazy_cbs (rsclp)); rsclp->enabled =0 ; }
@@ -253,11 +242,9 @@ bool rcu_segcblist_nextgp(struct rcu_segcblist *rsclp, unsigned long *lp)* absolutely not OK for it to ever miss posting a callback. */ void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy) +struct rcu_head *rhp) {rcu_segcblist_inc_len (rsclp); -if (lazy) - rsclp->len_lazy++;smp_mb ();/* Ensure counts are updated before callback is enqueued. */ rhp->next =NULL ;WRITE_ONCE (*rsclp->tails[RCU_NEXT_TAIL ], rhp);
@@ -275,15 +262,13 @@ void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,* period. You have been warned. */ bool rcu_segcblist_entrain (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy) +struct rcu_head *rhp) {int i;if (rcu_segcblist_n_cbs (rsclp) ==0 )return false;rcu_segcblist_inc_len (rsclp); -if (lazy) - rsclp->len_lazy++;smp_mb ();/* Ensure counts are updated before callback is entrained. */ rhp->next =NULL ;for (i =RCU_NEXT_TAIL ; i >RCU_DONE_TAIL ; i--)
@@ -307,8 +292,6 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,void rcu_segcblist_extract_count (struct rcu_segcblist *rsclp,struct rcu_cblist *rclp) { - rclp->len_lazy += rsclp->len_lazy; - rsclp->len_lazy =0 ; rclp->len =rcu_segcblist_xchg_len (rsclp,0 ); }
@@ -361,9 +344,7 @@ void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp,void rcu_segcblist_insert_count (struct rcu_segcblist *rsclp,struct rcu_cblist *rclp) { - rsclp->len_lazy += rclp->len_lazy;rcu_segcblist_add_len (rsclp, rclp->len); - rclp->len_lazy =0 ; rclp->len =0 ; }
kernel/rcu/rcu_segcblist.h +2 -23
@@ -15,15 +15,6 @@ static inline long rcu_cblist_n_cbs(struct rcu_cblist *rclp)return READ_ONCE (rclp->len); } -/* -* Account for the fact that a previously dequeued callback turned out -* to be marked as lazy. -*/ -static inline void rcu_cblist_dequeued_lazy (struct rcu_cblist *rclp) -{ - rclp->len_lazy--; -} -void rcu_cblist_init (struct rcu_cblist *rclp);void rcu_cblist_enqueue (struct rcu_cblist *rclp,struct rcu_head *rhp); void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp,
@@ -59,18 +50,6 @@ static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp)#endif } -/* Return number of lazy callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_lazy_cbs (struct rcu_segcblist *rsclp) -{ -return rsclp->len_lazy; -} - -/* Return number of lazy callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_nonlazy_cbs (struct rcu_segcblist *rsclp) -{ -return rcu_segcblist_n_cbs (rsclp) - rsclp->len_lazy; -} -/* * Is the specified rcu_segcblist enabled, for example, not corresponding * to an offline CPU?
@@ -106,9 +85,9 @@ struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp);struct rcu_head *rcu_segcblist_first_pend_cb (struct rcu_segcblist *rsclp);bool rcu_segcblist_nextgp (struct rcu_segcblist *rsclp,unsigned long *lp);void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy); +struct rcu_head *rhp);bool rcu_segcblist_entrain (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy); +struct rcu_head *rhp);void rcu_segcblist_extract_count (struct rcu_segcblist *rsclp,struct rcu_cblist *rclp); void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp,
kernel/rcu/srcutree.c +2 -2
@@ -853,7 +853,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,local_irq_save (flags); sdp =this_cpu_ptr (ssp->sda);spin_lock_rcu_node (sdp); -rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp, false); +rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp);rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&ssp->srcu_gp_seq)); s =rcu_seq_snap (&ssp->srcu_gp_seq);
@@ -1052,7 +1052,7 @@ void srcu_barrier(struct srcu_struct *ssp) sdp->srcu_barrier_head.func = srcu_barrier_cb;debug_rcu_head_queue (&sdp->srcu_barrier_head);if (!rcu_segcblist_entrain (&sdp->srcu_cblist, - &sdp->srcu_barrier_head,0 )) { + &sdp->srcu_barrier_head)) {debug_rcu_head_unqueue (&sdp->srcu_barrier_head);atomic_dec (&ssp->srcu_barrier_cpu_cnt); }
kernel/rcu/tiny.c +28 -1
@@ -73,6 +73,33 @@ void rcu_sched_clock_irq(int user) } } +void kfree (const void *); + +/* +* Reclaim the specified callback, either by invoking it for non-kfree cases or +* freeing it directly (for kfree). Return true if kfreeing, false otherwise. +*/ +static inline bool rcu_reclaim_tiny (struct rcu_head *head) +{ +rcu_callback_t f; +unsigned long offset = (unsigned long )head->func; + +rcu_lock_acquire (&rcu_callback_map); +if (__is_kfree_rcu_offset (offset)) { +trace_rcu_invoke_kfree_callback ("" , head, offset); +kfree ((void *)head - offset); +rcu_lock_release (&rcu_callback_map); +return true; + } + +trace_rcu_invoke_callback ("" , head); + f = head->func; +WRITE_ONCE (head->func, (rcu_callback_t )0L ); +f (head); +rcu_lock_release (&rcu_callback_map); +return false; +} +/* Invoke the RCU callbacks whose grace period has elapsed. */ static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused) {
@@ -100,7 +127,7 @@ static __latent_entropy void rcu_process_callbacks(struct softirq_action *unusedprefetch (next);debug_rcu_head_unqueue (list);local_bh_disable (); -__rcu_reclaim ("" , list); +rcu_reclaim_tiny (list);local_bh_enable (); list = next; }
kernel/rcu/tree.c +28 -13
107 lines not on this page · raw message
kernel/rcu/tree.h +0 -1
@@ -183,7 +183,6 @@ struct rcu_data {bool rcu_urgent_qs;/* GP old need light quiescent state. */ bool rcu_forced_tick;/* Forced tick to provide QS. */ #ifdef CONFIG_RCU_FAST_NO_HZ -bool all_lazy;/* All CPU's CBs lazy at idle start? */ unsigned long last_accelerate;/* Last jiffy CBs were accelerated. */ unsigned long last_advance_all;/* Last jiffy CBs were all advanced. */ int tick_nohz_enabled_snap;/* Previously seen value from sysfs. */
kernel/rcu/tree_plugin.h +11 -37
92 lines not on this page · raw message
kernel/rcu/tree_stall.h +2 -4
@@ -263,11 +263,9 @@ static void print_cpu_stall_fast_no_hz(char *cp, int cpu) {struct rcu_data *rdp = &per_cpu (rcu_data, cpu); -sprintf (cp,"last_accelerate: %04lx/%04lx, Nonlazy posted: %c%c%c" , +sprintf (cp,"last_accelerate: %04lx/%04lx dyntick_enabled: %d" , rdp->last_accelerate &0xffff , jiffies &0xffff , -".l" [rdp->all_lazy], -".L" [!rcu_segcblist_n_nonlazy_cbs (&rdp->cblist)], -".D" [!!rdp->tick_nohz_enabled_snap]); + !!rdp->tick_nohz_enabled_snap); }#else /* #ifdef CONFIG_RCU_FAST_NO_HZ */
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 5/5 rcu: Remove kfree_call_rcu_nobatch()
In reply to Joel Fernandes (Google)Now that kfree_rcu() special casing have been removed from tree RCU, remove kfree_call_rcu_nobatch() since it is not needed.
--- .../admin-guide/kernel-parameters.txt | 4 --- include/linux/rcutiny.h | 5 --- include/linux/rcutree.h | 1 - kernel/rcu/rcuperf.c | 10 +----- kernel/rcu/tree.c | 34 ++++++++----------- 5 files changed, 15 insertions(+), 39 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -4
@@ -3909,10 +3909,6 @@ Number of loops doing rcuperf.kfree_alloc_num number of allocations and frees. - rcuperf.kfree_no_batch= [KNL] - Use the non-batching (less efficient) version of kfree_rcu(). - This is useful for comparing with the batched version. - rcuperf.nreaders= [KNL] Set number of RCU readers. The value -1 selects N, where N is the number of CPUs. A value
include/linux/rcutiny.h +0 -5
@@ -39,11 +39,6 @@ static inline void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)call_rcu (head, func); } -static inline void kfree_call_rcu_nobatch (struct rcu_head *head,rcu_callback_t func) -{ -call_rcu (head, func); -} -void rcu_qs (void );static inline void rcu_softirq_qs (void )
include/linux/rcutree.h +0 -1
@@ -34,7 +34,6 @@ static inline void rcu_virt_note_context_switch(int cpu)void synchronize_rcu_expedited (void );void kfree_call_rcu (struct rcu_head *head,rcu_callback_t func); -void kfree_call_rcu_nobatch (struct rcu_head *head,rcu_callback_t func);void rcu_barrier (void );bool rcu_eqs_special_set (int cpu);
kernel/rcu/rcuperf.c +1 -9
@@ -593,7 +593,6 @@ rcu_perf_shutdown(void *arg)torture_param (int, kfree_nthreads,-1 ,"Number of threads running loops of kfree_rcu()." );torture_param (int, kfree_alloc_num,8000 ,"Number of allocations and frees done in an iteration." );torture_param (int, kfree_loops,10 ,"Number of loops doing kfree_alloc_num allocations and frees." ); -torture_param (int, kfree_no_batch,0 ,"Use the non-batching (slower) version of kfree_rcu()." );static struct task_struct **kfree_reader_tasks;static int kfree_nrealthreads;
@@ -632,14 +631,7 @@ kfree_perf_thread(void *arg)if (!alloc_ptr)return -ENOMEM ; -if (!kfree_no_batch) { -kfree_rcu (alloc_ptr, rh); - }else { -rcu_callback_t cb; - - cb = (rcu_callback_t )(unsigned long )offsetof(struct kfree_obj , rh); -kfree_call_rcu_nobatch (&(alloc_ptr->rh), cb); - } +kfree_rcu (alloc_ptr, rh); }cond_resched ();
kernel/rcu/tree.c +14 -20
@@ -2770,8 +2770,10 @@ static void kfree_rcu_work(struct work_struct *work)rcu_lock_acquire (&rcu_callback_map);trace_rcu_invoke_kfree_callback (rcu_state.name, head, offset); -/* Could be possible to optimize with kfree_bulk in future */ -kfree ((void *)head - offset); +if (!WARN_ON_ONCE (!__is_kfree_rcu_offset (offset))) { +/* Could be optimized with kfree_bulk() in future. */ +kfree ((void *)head - offset); + }rcu_lock_release (&rcu_callback_map);cond_resched_tasks_rcu_qs ();
@@ -2857,16 +2859,6 @@ static void kfree_rcu_monitor(struct work_struct *work) } } -/* -* This version of kfree_call_rcu does not do batching of kfree_rcu() requests. -* Used only by rcuperf torture test for comparison with kfree_rcu_batch(). -*/ -void kfree_call_rcu_nobatch (struct rcu_head *head,rcu_callback_t func) -{ -__call_rcu (head, func); -} -EXPORT_SYMBOL_GPL (kfree_call_rcu_nobatch); -/* * Queue a request for lazy invocation of kfree() after a grace period. *
@@ -2886,12 +2878,6 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)unsigned long flags;struct kfree_rcu_cpu *krcp; -/* kfree_call_rcu() batching requires timers to be up. If the scheduler -* is not yet up, just skip batching and do the non-batched version. -*/ -if (rcu_scheduler_active !=RCU_SCHEDULER_RUNNING ) -return kfree_call_rcu_nobatch (head, func); -if (debug_rcu_head_queue (head)) {/* Probable double kfree_rcu() */ WARN_ONCE(1, "kfree_call_rcu(): Double-freed call. rcu_head %p\n",
@@ -2910,8 +2896,16 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func) krcp->head = head;/* Schedule monitor for timely drain after KFREE_DRAIN_JIFFIES. */ -if (!xchg (&krcp->monitor_todo, true)) -schedule_delayed_work (&krcp->monitor_work,KFREE_DRAIN_JIFFIES ); +if (!krcp->monitor_todo) { + krcp->monitor_todo = true; +/* Scheduling the monitor requires scheduler/timers to be up, +* if it is not, just skip it. An eventual kfree_rcu() will +* kick it again. +*/ +if (rcu_scheduler_active ==RCU_SCHEDULER_RUNNING ) { +schedule_delayed_work (&krcp->monitor_work,KFREE_DRAIN_JIFFIES ); + } + }spin_unlock (&krcp->lock);local_irq_restore (flags);
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Paul E. McKenney
maintainerQuoted 17 lines · Joel Fernandes (Google)
Hi,
This is a series on top of the patch "rcu/tree: Add basic support for
kfree_rcu()batching".It adds performance tests, some clean ups and removal of "lazy" RCU callbacks.
Now that
kfree_rcu()is handled separately fromcall_rcu(), we also get rid of kfree "lazy" handling from tree RCU as suggested by Paul which will be unused.Based on patch:
v1 series:
https://lkml.org/lkml/2019/8/27/1315 https://lore.kernel.org/patchwork/project/lkml/list/?series=408218
Quoted 6 lines
Joel Fernandes (Google) (5):
rcu/rcuperf: Addkfree_rcu()performance Tests rcu/tree: Add multiple in-flight batches ofkfree_rcuwork rcu/tree: Add support fordebug_objectsdebugging forkfree_rcu()
rcu: Removekfree_rcu()special casing and lazy handling
rcu: Removekfree_call_rcu_nobatch()
Hello, Joel,
I have reworked these as we discussed. Please see below for a preliminary series on -rcu. I say "preliminary" because most (if not all) of my patchlets should be merged with one or another of yours. I split them out to make it easier for you to review my changes. Also, I need to swap your first two commits, if I am not mistaken -- they are switched for ease of testing.
Thoughts?
Thanx, Paul
------------------------------------------------------------------------
b2674c7 rcuperf: Add kfree_rcu() performance Tests
ff8db00 rcu: Make batched kfree_rcu() work during early boot 0784b59 rcu: Add crude self-test for early boot kfree_rcu() 196c1d9 rcu: Kick kfree_rcu() state machine for early boot calls 52a10e8 rcu: Use docbook header comment for struct kfree_rcu_cpu 099f53b rcu: Rework comments, indentation, and line breaks for kfree_rcu() 7ab6387 rcu EXP: Non-atomic ->monitor_todo, step 14a908098 rcu EXP: Non-atomic ->monitor_todo, step 2
783f00d rcu EXP: Non-atomic ->monitor_todo, step 3
4fe2018 rcu EXP: Non-atomic ->monitor_todo, step 4
b389141 rcu EXP: Non-atomic ->monitor_todo, step 5
8889da8 rcu EXP: Non-atomic ->monitor_todo, step 6
149b93e rcu EXP: Non-atomic ->monitor_todo, step 7
733e6a7 rcu: Add multiple in-flight batches of kfree_rcu() work 3acdea0 rcu: Add support for debug_objects debugging for kfree_rcu() 463db53 rcu: Remove kfree_rcu() special casing and lazy-callback handling 49e601b rcu: Remove kfree_call_rcu_nobatch()