@@ -1762,45 +1762,45 @@ static void bch_btree_gc(struct cache_set *c)
17621762 bch_moving_gc (c );
17631763}
17641764
1765- static int bch_gc_thread ( void * arg )
1765+ static bool gc_should_run ( struct cache_set * c )
17661766{
1767- struct cache_set * c = arg ;
17681767 struct cache * ca ;
17691768 unsigned i ;
17701769
1771- while ( 1 ) {
1772- again :
1773- bch_btree_gc ( c ) ;
1770+ for_each_cache ( ca , c , i )
1771+ if ( ca -> invalidate_needs_gc )
1772+ return true ;
17741773
1775- set_current_state (TASK_INTERRUPTIBLE );
1776- if (kthread_should_stop ())
1777- break ;
1774+ if (atomic_read (& c -> sectors_to_gc ) < 0 )
1775+ return true;
17781776
1779- mutex_lock (& c -> bucket_lock );
1777+ return false;
1778+ }
17801779
1781- for_each_cache (ca , c , i )
1782- if (ca -> invalidate_needs_gc ) {
1783- mutex_unlock (& c -> bucket_lock );
1784- set_current_state (TASK_RUNNING );
1785- goto again ;
1786- }
1780+ static int bch_gc_thread (void * arg )
1781+ {
1782+ struct cache_set * c = arg ;
17871783
1788- mutex_unlock (& c -> bucket_lock );
1784+ while (1 ) {
1785+ wait_event_interruptible (c -> gc_wait ,
1786+ kthread_should_stop () || gc_should_run (c ));
17891787
1790- try_to_freeze ();
1791- schedule ();
1788+ if (kthread_should_stop ())
1789+ break ;
1790+
1791+ set_gc_sectors (c );
1792+ bch_btree_gc (c );
17921793 }
17931794
17941795 return 0 ;
17951796}
17961797
17971798int bch_gc_thread_start (struct cache_set * c )
17981799{
1799- c -> gc_thread = kthread_create (bch_gc_thread , c , "bcache_gc" );
1800+ c -> gc_thread = kthread_run (bch_gc_thread , c , "bcache_gc" );
18001801 if (IS_ERR (c -> gc_thread ))
18011802 return PTR_ERR (c -> gc_thread );
18021803
1803- set_task_state (c -> gc_thread , TASK_INTERRUPTIBLE );
18041804 return 0 ;
18051805}
18061806
0 commit comments