]> Gentwo Git Trees - linux/.git/commit
bcachefs: Fix striping behaviour
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 31 Mar 2025 01:15:57 +0000 (21:15 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 31 Mar 2025 21:39:10 +0000 (17:39 -0400)
commitf540876f4eea82295f3af72f786aae51b7378fb2
tree865b651179cd521f301ee94d405bbb4fd2bb4ea2
parent650f5353dcc9b6e690a1c763754fa1e98d217bfc
bcachefs: Fix striping behaviour

For striping across devices, we maintain "clocks", and we advance them
by the inverse of "how much free space this device has left", so that we
round robin biased in favor of devices with more free space.

This code was originally trying to do EWMA-ish stuff when originally
written, ~10 years ago, and was never properly cleaned up when it was
realized that an EWMA is not the right approach here.

That left a bug, when we rescale to keep all the clocks in the correct
range and prevent overflow.

It was assumed that we'd always be allocated from the device with the
smallest clock hand, but that's actually not correct: with the target
options, allocations will be first tried from a subset of devices, and
then the entire filesystem if that fails.

Thus, the rescale from the first allocation - allocating from a subset
of devices - can pick the wrong rescale value and cause the rest of the
clocks to go to 0, losing information.

This resuls in incorrect striping behaviour when the desired number of
replicas doesn't fit on the foreground target.

Link: https://www.reddit.com/r/bcachefs/comments/1jn3t26/replica_allocation_not_evenly_distributed_among/
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_foreground.c