@@ -1757,44 +1757,45 @@ static void bch_btree_gc(struct cache_set *c)
17571757 bch_moving_gc (c );
17581758}
17591759
1760- static int bch_gc_thread ( void * arg )
1760+ static bool gc_should_run ( struct cache_set * c )
17611761{
1762- struct cache_set * c = arg ;
17631762 struct cache * ca ;
17641763 unsigned i ;
17651764
1766- while ( 1 ) {
1767- again :
1768- bch_btree_gc ( c ) ;
1765+ for_each_cache ( ca , c , i )
1766+ if ( ca -> invalidate_needs_gc )
1767+ return true ;
17691768
1770- set_current_state (TASK_INTERRUPTIBLE );
1771- if (kthread_should_stop ())
1772- break ;
1769+ if (atomic_read (& c -> sectors_to_gc ) < 0 )
1770+ return true;
17731771
1774- mutex_lock (& c -> bucket_lock );
1772+ return false;
1773+ }
17751774
1776- for_each_cache (ca , c , i )
1777- if (ca -> invalidate_needs_gc ) {
1778- mutex_unlock (& c -> bucket_lock );
1779- set_current_state (TASK_RUNNING );
1780- goto again ;
1781- }
1775+ static int bch_gc_thread (void * arg )
1776+ {
1777+ struct cache_set * c = arg ;
17821778
1783- mutex_unlock (& c -> bucket_lock );
1779+ while (1 ) {
1780+ wait_event_interruptible (c -> gc_wait ,
1781+ kthread_should_stop () || gc_should_run (c ));
17841782
1785- schedule ();
1783+ if (kthread_should_stop ())
1784+ break ;
1785+
1786+ set_gc_sectors (c );
1787+ bch_btree_gc (c );
17861788 }
17871789
17881790 return 0 ;
17891791}
17901792
17911793int bch_gc_thread_start (struct cache_set * c )
17921794{
1793- c -> gc_thread = kthread_create (bch_gc_thread , c , "bcache_gc" );
1795+ c -> gc_thread = kthread_run (bch_gc_thread , c , "bcache_gc" );
17941796 if (IS_ERR (c -> gc_thread ))
17951797 return PTR_ERR (c -> gc_thread );
17961798
1797- set_task_state (c -> gc_thread , TASK_INTERRUPTIBLE );
17981799 return 0 ;
17991800}
18001801
0 commit comments