Skip to content

Commit

Permalink
rcu: Make kfree_rcu() use a non-atomic ->monitor_todo
Browse files Browse the repository at this point in the history
Because the ->monitor_todo field is always protected by krcp->lock,
this commit downgrades from xchg() to non-atomic unmarked assignment
statements.

Signed-off-by: Joel Fernandes <joel@joelfernandes.org>
[ paulmck: Update to include early-boot kick code. ]
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
  • Loading branch information
Joel Fernandes authored and Paul E. McKenney committed Jan 24, 2020
1 parent e6e78b0 commit 569d767
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions kernel/rcu/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@ struct kfree_rcu_cpu {
struct rcu_head *head_free;
spinlock_t lock;
struct delayed_work monitor_work;
int monitor_todo;
bool monitor_todo;
bool initialized;
};

Expand Down Expand Up @@ -2765,15 +2765,16 @@ static inline void kfree_rcu_drain_unlock(struct kfree_rcu_cpu *krcp,
unsigned long flags)
{
// Attempt to start a new batch.
krcp->monitor_todo = false;
if (queue_kfree_rcu_work(krcp)) {
// Success! Our job is done here.
spin_unlock_irqrestore(&krcp->lock, flags);
return;
}

// Previous RCU batch still in progress, try again later.
if (!xchg(&krcp->monitor_todo, true))
schedule_delayed_work(&krcp->monitor_work, KFREE_DRAIN_JIFFIES);
krcp->monitor_todo = true;
schedule_delayed_work(&krcp->monitor_work, KFREE_DRAIN_JIFFIES);
spin_unlock_irqrestore(&krcp->lock, flags);
}

Expand All @@ -2788,7 +2789,7 @@ 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)
kfree_rcu_drain_unlock(krcp, flags);
else
spin_unlock_irqrestore(&krcp->lock, flags);
Expand Down Expand Up @@ -2837,8 +2838,10 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)

// Set timer to drain after KFREE_DRAIN_JIFFIES.
if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING &&
!xchg(&krcp->monitor_todo, true))
!krcp->monitor_todo) {
krcp->monitor_todo = true;
schedule_delayed_work(&krcp->monitor_work, KFREE_DRAIN_JIFFIES);
}

if (krcp->initialized)
spin_unlock(&krcp->lock);
Expand All @@ -2855,10 +2858,11 @@ void __init kfree_rcu_scheduler_running(void)
struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu);

spin_lock_irqsave(&krcp->lock, flags);
if (!krcp->head || xchg(&krcp->monitor_todo, true)) {
if (!krcp->head || krcp->monitor_todo) {
spin_unlock_irqrestore(&krcp->lock, flags);
continue;
}
krcp->monitor_todo = true;
schedule_delayed_work(&krcp->monitor_work, KFREE_DRAIN_JIFFIES);
spin_unlock_irqrestore(&krcp->lock, flags);
}
Expand Down

0 comments on commit 569d767

Please sign in to comment.