Skip to content

Commit 80eb65c

Browse files
fdmananakdave
authored andcommitted
btrfs: annotate block group access with data_race() when sorting for reclaim
When sorting the block group list for reclaim we are using a block group's used bytes counter without taking the block group's spinlock, so we can race with a concurrent task updating it (at btrfs_update_block_group()), which makes tools like KCSAN unhappy and report a race. Since the sorting is not strictly needed from a functional perspective and such races should rarely cause any ordering changes (only load/store tearing could cause them), not to mention that after the sorting the ordering may no longer be accurate due to concurrent allocations and deallocations of extents in a block group, annotate the accesses to the used counter with data_race() to silence KCSAN and similar tools. Reviewed-by: Qu Wenruo <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 8679d26 commit 80eb65c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/btrfs/block-group.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,14 @@ static int reclaim_bgs_cmp(void *unused, const struct list_head *a,
17951795
bg1 = list_entry(a, struct btrfs_block_group, bg_list);
17961796
bg2 = list_entry(b, struct btrfs_block_group, bg_list);
17971797

1798-
return bg1->used > bg2->used;
1798+
/*
1799+
* Some other task may be updating the ->used field concurrently, but it
1800+
* is not serious if we get a stale value or load/store tearing issues,
1801+
* as sorting the list of block groups to reclaim is not critical and an
1802+
* occasional imperfect order is ok. So silence KCSAN and avoid the
1803+
* overhead of locking or any other synchronization.
1804+
*/
1805+
return data_race(bg1->used > bg2->used);
17991806
}
18001807

18011808
static inline bool btrfs_should_reclaim(const struct btrfs_fs_info *fs_info)

0 commit comments

Comments
 (0)