aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Fernandes (Google) <joel@joelfernandes.org>2024-03-07 02:24:24 -0500
committerJoel Fernandes (Google) <joel@joelfernandes.org>2024-03-07 09:44:24 -0500
commitaf05259b4aae58143d828d629599a3f90c299255 (patch)
treee594d3b9e44dc5bdae43f3063e961134ddebbd37
parent9b2778e8a6d2f03810c57861b87ec86751c32821 (diff)
downloadlinux-rcu/synchronize_opt.tar.gz
rcu/tree: Reduce kworker wake up for synchronize_rcu() common casercu/synchronize_opt
In the synchronize_rcu() common case, we will have less than SR_MAX_USERS_WAKE_FROM_GP number of users per GP. Waking up the kworker is pointless just to free the last injected wait head since at that point, all the users have already been awakened. Introduce a new counter to track this and prevent the wakeup in the common case. TODO: Look into workqueue crap, is it possible a work is not queued since the old one was pending and we still incremented the new counter. Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
-rw-r--r--kernel/rcu/tree.c32
-rw-r--r--kernel/rcu/tree.h1
2 files changed, 29 insertions, 4 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 12978049cb99b..2554074d4194c 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -96,6 +96,7 @@ static struct rcu_state rcu_state = {
.ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED,
.srs_cleanup_work = __WORK_INITIALIZER(rcu_state.srs_cleanup_work,
rcu_sr_normal_gp_cleanup_work),
+ .srs_cleanups_pending = ATOMIC_INIT(0),
};
/* Dump rcu_node combining tree at boot to verify correct setup. */
@@ -1641,8 +1642,11 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work)
* the done tail list manipulations are protected here.
*/
done = smp_load_acquire(&rcu_state.srs_done_tail);
- if (!done)
+ if (!done) {
+ /* See comments below. */
+ atomic_dec_return_release(&rcu_state.srs_cleanups_pending);
return;
+ }
WARN_ON_ONCE(!rcu_sr_is_wait_head(done));
head = done->next;
@@ -1665,6 +1669,9 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work)
rcu_sr_put_wait_head(rcu);
}
+
+ /* Order list manipulations with atomic access. */
+ atomic_dec_return_release(&rcu_state.srs_cleanups_pending);
}
/*
@@ -1672,7 +1679,7 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work)
*/
static void rcu_sr_normal_gp_cleanup(void)
{
- struct llist_node *wait_tail, *next, *rcu;
+ struct llist_node *wait_tail, *next = NULL, *rcu = NULL;
int done = 0;
wait_tail = rcu_state.srs_wait_tail;
@@ -1698,15 +1705,32 @@ static void rcu_sr_normal_gp_cleanup(void)
break;
}
- // concurrent sr_normal_gp_cleanup work might observe this update.
- smp_store_release(&rcu_state.srs_done_tail, wait_tail);
+ /*
+ * Fast path, no more users to process. Remove the last wait head
+ * if no inflight-workers. If there are in-flight workers, let them
+ * remove the last wait head.
+ */
+ WARN_ON_ONCE(!rcu);
ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_done_tail);
+ if (rcu && rcu_sr_is_wait_head(rcu) && rcu->next == NULL &&
+ /* Order atomic access with list manipulation. */
+ !atomic_read_acquire(&rcu_state.srs_cleanups_pending)) {
+ wait_tail->next = NULL;
+ rcu_sr_put_wait_head(rcu);
+ smp_store_release(&rcu_state.srs_done_tail, wait_tail);
+ return;
+ }
+
+ /* Concurrent sr_normal_gp_cleanup work might observe this update. */
+ smp_store_release(&rcu_state.srs_done_tail, wait_tail);
+
/*
* We schedule a work in order to perform a final processing
* of outstanding users(if still left) and releasing wait-heads
* added by rcu_sr_normal_gp_init() call.
*/
+ atomic_inc(&rcu_state.srs_cleanups_pending);
queue_work(system_highpri_wq, &rcu_state.srs_cleanup_work);
}
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 2832787cee1d0..f162b947c5b62 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -420,6 +420,7 @@ struct rcu_state {
struct llist_node *srs_done_tail; /* ready for GP users. */
struct sr_wait_node srs_wait_nodes[SR_NORMAL_GP_WAIT_HEAD_MAX];
struct work_struct srs_cleanup_work;
+ atomic_t srs_cleanups_pending; /* srs inflight worker cleanups. */
};
/* Values for rcu_state structure's gp_flags field. */