Skip to content

Commit 90b211f

Browse files
author
Kent Overstreet
committed
bcachefs: Add a comment for bucket helper types
We've had bugs in the past with incorrect integer conversions in disk accounting code, which is why bucket helpers now always return s64s; add a comment explaining this. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 7442b5c commit 90b211f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/bcachefs/alloc_background.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ static inline bool bucket_data_type_mismatch(enum bch_data_type bucket,
8282
bucket_data_type(bucket) != bucket_data_type(ptr);
8383
}
8484

85+
/*
86+
* It is my general preference to use unsigned types for unsigned quantities -
87+
* however, these helpers are used in disk accounting calculations run by
88+
* triggers where the output will be negated and added to an s64. unsigned is
89+
* right out even though all these quantities will fit in 32 bits, since it
90+
* won't be sign extended correctly; u64 will negate "correctly", but s64 is the
91+
* simpler option here.
92+
*/
8593
static inline s64 bch2_bucket_sectors_total(struct bch_alloc_v4 a)
8694
{
8795
return a.stripe_sectors + a.dirty_sectors + a.cached_sectors;

0 commit comments

Comments
 (0)