Skip to content

Commit 95cd356

Browse files
morbidrsakdave
authored andcommitted
btrfs: fix percent calculation for bg reclaim message
We have a report, that the info message for block-group reclaim is crossing the 100% used mark. This is happening as we were truncating the divisor for the division (the block_group->length) to a 32bit value. Fix this by using div64_u64() to not truncate the divisor. In the worst case, it can lead to a div by zero error and should be possible to trigger on 4 disks RAID0, and each device is large enough: $ mkfs.btrfs -f /dev/test/scratch[1234] -m raid1 -d raid0 btrfs-progs v6.1 [...] Filesystem size: 40.00GiB Block group profiles: Data: RAID0 4.00GiB <<< Metadata: RAID1 256.00MiB System: RAID1 8.00MiB Reported-by: Forza <[email protected]> Link: https://lore.kernel.org/linux-btrfs/[email protected]/ Fixes: 5f93e77 ("btrfs: zoned: print unusable percentage when reclaiming block groups") CC: [email protected] # 5.15+ Reviewed-by: Anand Jain <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> [ add Qu's note ] Signed-off-by: David Sterba <[email protected]>
1 parent 98e8d36 commit 95cd356

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/btrfs/block-group.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,8 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
18261826

18271827
btrfs_info(fs_info,
18281828
"reclaiming chunk %llu with %llu%% used %llu%% unusable",
1829-
bg->start, div_u64(bg->used * 100, bg->length),
1829+
bg->start,
1830+
div64_u64(bg->used * 100, bg->length),
18301831
div64_u64(zone_unusable * 100, bg->length));
18311832
trace_btrfs_reclaim_block_group(bg);
18321833
ret = btrfs_relocate_chunk(fs_info, bg->start);

0 commit comments

Comments
 (0)