entry.m_entry_cost.m_extents_delta = debt.m_extents_delta;
entry.m_entry_cost.m_physical_freed = debt.m_physical_freed;
}
+
+ // Per-dst benefit gate. Plan B executes each dst independently (each is a
+ // reversed Plan A against the single start src), so each must beat the
+ // do-nothing floor on its own. The aggregate cost below sums the entries,
+ // which without this gate lets a batch of profitable singleton dedupes
+ // subsidize an individually-catastrophic drain — redirecting a high-ref
+ // extent's references onto a fresh src costs refs_created * ref-op-cost,
+ // which do-nothing avoids entirely, yet the group's summed debt can still
+ // be negative and carry the drain along. Drop a candidate whose own signed
+ // debt does not beat do-nothing (>= 0); the profitable candidates are
+ // unaffected. A force-marked candidate must be rewritten regardless, so it
+ // bypasses the gate (mirroring the FullRewrite floor's benefit-gate bypass).
+ if (!m_filter_cache->force_rewrite(candidate.bytenr())
+ && !(entry.m_entry_cost.space_debt(m_policy) < 0.0)) {
+ return;
+ }
+
m_impl->m_entries.push_back(std::move(entry));
// Aggregate from scratch — O(entries) per accept is fine because