mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 18:20:25 +02:00 
			
		
		
		
	rcu/nocb: Recheck lazy callbacks under the ->nocb_lock from shrinker
The ->lazy_len is only checked locklessly. Recheck again under the ->nocb_lock to avoid spending more time on flushing/waking if not necessary. The ->lazy_len can still increment concurrently (from 1 to infinity) but under the ->nocb_lock we at least know for sure if there are lazy callbacks at all (->lazy_len > 0). Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
		
							parent
							
								
									7625926086
								
							
						
					
					
						commit
						b96a8b0b5b
					
				
					 1 changed files with 11 additions and 3 deletions
				
			
		| 
						 | 
					@ -1358,12 +1358,20 @@ lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 | 
				
			||||||
		if (!rcu_rdp_is_offloaded(rdp))
 | 
							if (!rcu_rdp_is_offloaded(rdp))
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_count = READ_ONCE(rdp->lazy_len);
 | 
							if (!READ_ONCE(rdp->lazy_len))
 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (_count == 0)
 | 
					 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		rcu_nocb_lock_irqsave(rdp, flags);
 | 
							rcu_nocb_lock_irqsave(rdp, flags);
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * Recheck under the nocb lock. Since we are not holding the bypass
 | 
				
			||||||
 | 
							 * lock we may still race with increments from the enqueuer but still
 | 
				
			||||||
 | 
							 * we know for sure if there is at least one lazy callback.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							_count = READ_ONCE(rdp->lazy_len);
 | 
				
			||||||
 | 
							if (!_count) {
 | 
				
			||||||
 | 
								rcu_nocb_unlock_irqrestore(rdp, flags);
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, jiffies, false));
 | 
							WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, jiffies, false));
 | 
				
			||||||
		rcu_nocb_unlock_irqrestore(rdp, flags);
 | 
							rcu_nocb_unlock_irqrestore(rdp, flags);
 | 
				
			||||||
		wake_nocb_gp(rdp, false);
 | 
							wake_nocb_gp(rdp, false);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue