diff --git a/pageserver/src/tenant/timeline/eviction_task.rs b/pageserver/src/tenant/timeline/eviction_task.rs index 5485cc42b4..354f971e11 100644 --- a/pageserver/src/tenant/timeline/eviction_task.rs +++ b/pageserver/src/tenant/timeline/eviction_task.rs @@ -308,8 +308,13 @@ impl Timeline { ctx: &RequestContext, ) -> ControlFlow<()> { let mut state = self.eviction_task_timeline_state.lock().await; + + // Only do the imitate_layer accesses approximately as often as the threshold. A little + // more frequently, to avoid this period racing with the threshold/period-th eviction iteration. + let inter_imitate_period = p.threshold.checked_sub(p.period).unwrap_or(p.threshold); + match state.last_layer_access_imitation { - Some(ts) if ts.elapsed() < p.threshold => { /* no need to run */ } + Some(ts) if ts.elapsed() < inter_imitate_period => { /* no need to run */ } _ => { self.imitate_timeline_cached_layer_accesses(cancel, ctx) .await; @@ -332,7 +337,7 @@ impl Timeline { }; let mut state = tenant.eviction_task_tenant_state.lock().await; match state.last_layer_access_imitation { - Some(ts) if ts.elapsed() < p.threshold => { /* no need to run */ } + Some(ts) if ts.elapsed() < inter_imitate_period => { /* no need to run */ } _ => { self.imitate_synthetic_size_calculation_worker(&tenant, ctx, cancel) .await;