@@ -10,6 +10,7 @@ use std::{
1010
1111use rustc_hash:: { FxHashMap , FxHasher } ;
1212use thread_local:: ThreadLocal ;
13+ use tracing:: span:: Id ;
1314use turbo_bincode:: TurboBincodeBuffer ;
1415use turbo_tasks:: { FxDashMap , TaskId , backend:: CachedTaskType , event:: Event , parallel} ;
1516
@@ -388,15 +389,23 @@ impl Storage {
388389 /// - `No`: skip
389390 ///
390391 /// Must be called when NOT in snapshot mode (i.e., after `end_snapshot()`).
391- pub fn evict_after_snapshot ( & self ) {
392+ pub fn evict_after_snapshot ( & self , parent_span : Option < Id > ) -> EvictionCounts {
392393 let span = tracing:: trace_span!(
394+ parent: parent_span,
393395 "evict_after_snapshot" ,
394- task_cache = tracing:: field:: Empty ,
396+ total_task_cache_keys = self . task_cache. len( ) ,
397+ total_map_keys = self . map. len( ) ,
398+ task_cache_evictions = tracing:: field:: Empty ,
395399 full = tracing:: field:: Empty ,
396400 data_and_meta = tracing:: field:: Empty ,
397401 data_only = tracing:: field:: Empty ,
398402 meta_only = tracing:: field:: Empty ,
399403 skipped = tracing:: field:: Empty ,
404+ skipped_in_progress = tracing:: field:: Empty ,
405+ skipped_restoring = tracing:: field:: Empty ,
406+ skipped_modified = tracing:: field:: Empty ,
407+ skipped_transient_or_stateful = tracing:: field:: Empty ,
408+ skipped_nothing_to_evict = tracing:: field:: Empty ,
400409 )
401410 . entered ( ) ;
402411 debug_assert ! (
@@ -418,14 +427,20 @@ impl Storage {
418427 }
419428 let ( key, data) = task. get ( ) . evictability ( ) ;
420429 if matches ! ( key, KeyEvictability :: Evictable ) {
421- evicted. key_evictions += 1 ;
422430 // The task type is persisted to backing storage (new_task = false),
423431 // so task_cache is a pure perf cache. Remove it now; it will be
424432 // re-populated by task_by_type() on the next cache miss.
425- if let Some ( task_type) = task. get ( ) . get_persistent_task_type ( ) {
426- self . task_cache . remove ( task_type. as_ref ( ) ) ;
433+
434+ if self
435+ . task_cache
436+ . remove ( task. get ( ) . get_persistent_task_type ( ) . unwrap ( ) . as_ref ( ) )
437+ . is_some ( )
438+ {
439+ evicted. key_evictions += 1 ;
427440 }
428441 }
442+ // KeyEvictability::AlreadyEvicted: strong_count == 1 means no
443+ // task_cache entry holds a reference — skip the hash lookup.
429444 match data {
430445 DataEvictability :: Full => {
431446 unsafe {
@@ -464,6 +479,7 @@ impl Storage {
464479 }
465480 ( evicted, reason_counts)
466481 } ) ;
482+
467483 let mut totals = EvictionCounts :: default ( ) ;
468484 let mut reasons: FxHashMap < UnevictableReason , usize > = FxHashMap :: default ( ) ;
469485 for ( evicted, r) in counts {
@@ -483,12 +499,49 @@ impl Storage {
483499 self . task_cache . shrink_to_fit ( ) ;
484500 }
485501 let skipped: usize = reasons. values ( ) . sum ( ) ;
486- span. record ( "task_cache " , totals. key_evictions ) ;
502+ span. record ( "task_cache_evictions " , totals. key_evictions ) ;
487503 span. record ( "full" , totals. full ) ;
488504 span. record ( "data_and_meta" , totals. data_and_meta ) ;
489505 span. record ( "data_only" , totals. data_only ) ;
490506 span. record ( "meta_only" , totals. meta_only ) ;
491507 span. record ( "skipped" , skipped) ;
508+ span. record (
509+ "skipped_in_progress" ,
510+ reasons
511+ . get ( & UnevictableReason :: InProgress )
512+ . copied ( )
513+ . unwrap_or ( 0 ) ,
514+ ) ;
515+ span. record (
516+ "skipped_restoring" ,
517+ reasons
518+ . get ( & UnevictableReason :: Restoring )
519+ . copied ( )
520+ . unwrap_or ( 0 ) ,
521+ ) ;
522+ span. record (
523+ "skipped_modified" ,
524+ reasons
525+ . get ( & UnevictableReason :: Modified )
526+ . copied ( )
527+ . unwrap_or ( 0 ) ,
528+ ) ;
529+ span. record (
530+ "skipped_transient_or_stateful" ,
531+ reasons
532+ . get ( & UnevictableReason :: TransientOrStateful )
533+ . copied ( )
534+ . unwrap_or ( 0 ) ,
535+ ) ;
536+ span. record (
537+ "skipped_nothing_to_evict" ,
538+ reasons
539+ . get ( & UnevictableReason :: NothingToEvict )
540+ . copied ( )
541+ . unwrap_or ( 0 ) ,
542+ ) ;
543+
544+ totals
492545 }
493546}
494547
0 commit comments