bcachefs with foreground_target/background_target/promote_target set appropriately does this automagically: https://bcachefs.org/Caching/