@@ -556,6 +556,7 @@ void __fscache_use_cookie(struct fscache_cookie *cookie, bool will_modify)
556
556
{
557
557
enum fscache_cookie_state state ;
558
558
bool queue = false;
559
+ int n_active ;
559
560
560
561
_enter ("c=%08x" , cookie -> debug_id );
561
562
@@ -565,7 +566,11 @@ void __fscache_use_cookie(struct fscache_cookie *cookie, bool will_modify)
565
566
566
567
spin_lock (& cookie -> lock );
567
568
568
- atomic_inc (& cookie -> n_active );
569
+ n_active = atomic_inc_return (& cookie -> n_active );
570
+ trace_fscache_active (cookie -> debug_id , refcount_read (& cookie -> ref ),
571
+ n_active , atomic_read (& cookie -> n_accesses ),
572
+ will_modify ?
573
+ fscache_active_use_modify : fscache_active_use );
569
574
570
575
again :
571
576
state = fscache_cookie_state (cookie );
@@ -638,13 +643,29 @@ static void fscache_unuse_cookie_locked(struct fscache_cookie *cookie)
638
643
void __fscache_unuse_cookie (struct fscache_cookie * cookie ,
639
644
const void * aux_data , const loff_t * object_size )
640
645
{
646
+ unsigned int debug_id = cookie -> debug_id ;
647
+ unsigned int r = refcount_read (& cookie -> ref );
648
+ unsigned int a = atomic_read (& cookie -> n_accesses );
649
+ unsigned int c ;
650
+
641
651
if (aux_data || object_size )
642
652
__fscache_update_cookie (cookie , aux_data , object_size );
643
653
644
- if (atomic_dec_and_lock (& cookie -> n_active , & cookie -> lock )) {
645
- fscache_unuse_cookie_locked (cookie );
646
- spin_unlock (& cookie -> lock );
654
+ /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
655
+ c = atomic_fetch_add_unless (& cookie -> n_active , -1 , 1 );
656
+ if (c != 1 ) {
657
+ trace_fscache_active (debug_id , r , c - 1 , a , fscache_active_unuse );
658
+ return ;
647
659
}
660
+
661
+ spin_lock (& cookie -> lock );
662
+ r = refcount_read (& cookie -> ref );
663
+ a = atomic_read (& cookie -> n_accesses );
664
+ c = atomic_dec_return (& cookie -> n_active );
665
+ trace_fscache_active (debug_id , r , c , a , fscache_active_unuse );
666
+ if (c == 0 )
667
+ fscache_unuse_cookie_locked (cookie );
668
+ spin_unlock (& cookie -> lock );
648
669
}
649
670
EXPORT_SYMBOL (__fscache_unuse_cookie );
650
671
0 commit comments