Skip to content

Commit a6a82ce

Browse files
joelagnelpaulmckrcu
authored andcommitted
rcu/tree: Count number of batched kfree_rcu() locklessly
We can relax the correctness of counting of number of queued objects in favor of not hurting performance, by locklessly sampling per-cpu counters. This should be Ok since under high memory pressure, it should not matter if we are off by a few objects while counting. The shrinker will still do the reclaim. Signed-off-by: Joel Fernandes (Google) <[email protected]> [ paulmck: Remove unused "flags" variable. ] Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 9154244 commit a6a82ce

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

kernel/rcu/tree.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ static inline bool queue_kfree_rcu_work(struct kfree_rcu_cpu *krcp)
29392939
krcp->head = NULL;
29402940
}
29412941

2942-
krcp->count = 0;
2942+
WRITE_ONCE(krcp->count, 0);
29432943

29442944
/*
29452945
* One work is per one batch, so there are two "free channels",
@@ -3077,7 +3077,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
30773077
krcp->head = head;
30783078
}
30793079

3080-
krcp->count++;
3080+
WRITE_ONCE(krcp->count, krcp->count + 1);
30813081

30823082
// Set timer to drain after KFREE_DRAIN_JIFFIES.
30833083
if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING &&
@@ -3097,15 +3097,13 @@ static unsigned long
30973097
kfree_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
30983098
{
30993099
int cpu;
3100-
unsigned long flags, count = 0;
3100+
unsigned long count = 0;
31013101

31023102
/* Snapshot count of all CPUs */
31033103
for_each_online_cpu(cpu) {
31043104
struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu);
31053105

3106-
spin_lock_irqsave(&krcp->lock, flags);
3107-
count += krcp->count;
3108-
spin_unlock_irqrestore(&krcp->lock, flags);
3106+
count += READ_ONCE(krcp->count);
31093107
}
31103108

31113109
return count;

0 commit comments

Comments
 (0)