Skip to content

Commit abaa93d

Browse files
committed
rcu: Simplify priority boosting by putting rt_mutex in rcu_node
RCU priority boosting currently checks for boosting via a pointer in task_struct. However, this is not needed: As Oleg noted, if the rt_mutex is placed in the rcu_node instead of on the booster's stack, the boostee can simply check it see if it owns the lock. This commit makes this change, shrinking task_struct by one pointer and the kernel by thirteen lines. Suggested-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 48bd8e9 commit abaa93d

4 files changed

Lines changed: 15 additions & 28 deletions

File tree

‎include/linux/init_task.h‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ extern struct group_info init_groups;
102102
#define INIT_IDS
103103
#endif
104104

105-
#ifdef CONFIG_RCU_BOOST
106-
#define INIT_TASK_RCU_BOOST() \
107-
.rcu_boost_mutex = NULL,
108-
#else
109-
#define INIT_TASK_RCU_BOOST()
110-
#endif
111105
#ifdef CONFIG_TREE_PREEMPT_RCU
112106
#define INIT_TASK_RCU_TREE_PREEMPT() \
113107
.rcu_blocked_node = NULL,
@@ -119,8 +113,7 @@ extern struct group_info init_groups;
119113
.rcu_read_lock_nesting = 0, \
120114
.rcu_read_unlock_special = 0, \
121115
.rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry), \
122-
INIT_TASK_RCU_TREE_PREEMPT() \
123-
INIT_TASK_RCU_BOOST()
116+
INIT_TASK_RCU_TREE_PREEMPT()
124117
#else
125118
#define INIT_TASK_RCU_PREEMPT(tsk)
126119
#endif

‎include/linux/sched.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,9 +1270,6 @@ struct task_struct {
12701270
#ifdef CONFIG_TREE_PREEMPT_RCU
12711271
struct rcu_node *rcu_blocked_node;
12721272
#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
1273-
#ifdef CONFIG_RCU_BOOST
1274-
struct rt_mutex *rcu_boost_mutex;
1275-
#endif /* #ifdef CONFIG_RCU_BOOST */
12761273

12771274
#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
12781275
struct sched_info sched_info;
@@ -2009,9 +2006,6 @@ static inline void rcu_copy_process(struct task_struct *p)
20092006
#ifdef CONFIG_TREE_PREEMPT_RCU
20102007
p->rcu_blocked_node = NULL;
20112008
#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
2012-
#ifdef CONFIG_RCU_BOOST
2013-
p->rcu_boost_mutex = NULL;
2014-
#endif /* #ifdef CONFIG_RCU_BOOST */
20152009
INIT_LIST_HEAD(&p->rcu_node_entry);
20162010
}
20172011

‎kernel/rcu/tree.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ struct rcu_node {
177177
/* to carry out the boosting is fully */
178178
/* released with no future boostee accesses */
179179
/* before that rt_mutex is re-initialized. */
180+
struct rt_mutex boost_mtx;
181+
/* Used only for the priority-boosting */
182+
/* side effect, not as a lock. */
180183
unsigned long boost_time;
181184
/* When to start boosting (jiffies). */
182185
struct task_struct *boost_kthread_task;

‎kernel/rcu/tree_plugin.h‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define RCU_KTHREAD_PRIO 1
3434

3535
#ifdef CONFIG_RCU_BOOST
36+
#include "../locking/rtmutex_common.h"
3637
#define RCU_BOOST_PRIO CONFIG_RCU_BOOST_PRIO
3738
#else
3839
#define RCU_BOOST_PRIO RCU_KTHREAD_PRIO
@@ -336,7 +337,7 @@ void rcu_read_unlock_special(struct task_struct *t)
336337
unsigned long flags;
337338
struct list_head *np;
338339
#ifdef CONFIG_RCU_BOOST
339-
struct rt_mutex *rbmp = NULL;
340+
bool drop_boost_mutex = false;
340341
#endif /* #ifdef CONFIG_RCU_BOOST */
341342
struct rcu_node *rnp;
342343
int special;
@@ -398,11 +399,8 @@ void rcu_read_unlock_special(struct task_struct *t)
398399
#ifdef CONFIG_RCU_BOOST
399400
if (&t->rcu_node_entry == rnp->boost_tasks)
400401
rnp->boost_tasks = np;
401-
/* Snapshot/clear ->rcu_boost_mutex with rcu_node lock held. */
402-
if (t->rcu_boost_mutex) {
403-
rbmp = t->rcu_boost_mutex;
404-
t->rcu_boost_mutex = NULL;
405-
}
402+
/* Snapshot ->boost_mtx ownership with rcu_node lock held. */
403+
drop_boost_mutex = rt_mutex_owner(&rnp->boost_mtx) == t;
406404
#endif /* #ifdef CONFIG_RCU_BOOST */
407405

408406
/*
@@ -427,8 +425,8 @@ void rcu_read_unlock_special(struct task_struct *t)
427425

428426
#ifdef CONFIG_RCU_BOOST
429427
/* Unboost if we were boosted. */
430-
if (rbmp) {
431-
rt_mutex_unlock(rbmp);
428+
if (drop_boost_mutex) {
429+
rt_mutex_unlock(&rnp->boost_mtx);
432430
complete(&rnp->boost_completion);
433431
}
434432
#endif /* #ifdef CONFIG_RCU_BOOST */
@@ -1151,7 +1149,6 @@ static void rcu_wake_cond(struct task_struct *t, int status)
11511149
static int rcu_boost(struct rcu_node *rnp)
11521150
{
11531151
unsigned long flags;
1154-
struct rt_mutex mtx;
11551152
struct task_struct *t;
11561153
struct list_head *tb;
11571154

@@ -1202,14 +1199,14 @@ static int rcu_boost(struct rcu_node *rnp)
12021199
* section.
12031200
*/
12041201
t = container_of(tb, struct task_struct, rcu_node_entry);
1205-
rt_mutex_init_proxy_locked(&mtx, t);
1206-
t->rcu_boost_mutex = &mtx;
1202+
rt_mutex_init_proxy_locked(&rnp->boost_mtx, t);
12071203
init_completion(&rnp->boost_completion);
12081204
raw_spin_unlock_irqrestore(&rnp->lock, flags);
1209-
rt_mutex_lock(&mtx); /* Side effect: boosts task t's priority. */
1210-
rt_mutex_unlock(&mtx); /* Keep lockdep happy. */
1205+
/* Lock only for side effect: boosts task t's priority. */
1206+
rt_mutex_lock(&rnp->boost_mtx);
1207+
rt_mutex_unlock(&rnp->boost_mtx); /* Then keep lockdep happy. */
12111208

1212-
/* Wait until boostee is done accessing mtx before reinitializing. */
1209+
/* Wait for boostee to be done w/boost_mtx before reinitializing. */
12131210
wait_for_completion(&rnp->boost_completion);
12141211

12151212
return ACCESS_ONCE(rnp->exp_tasks) != NULL ||

0 commit comments

Comments
 (0)