btrfs-progs icon indicating copy to clipboard operation
btrfs-progs copied to clipboard

badblocks support on user space

Open axet opened this issue 3 years ago • 15 comments
trafficstars

Hello!

It would be nice to have badblocks support on btrfs. It is already described here:

  • https://btrfs.wiki.kernel.org/index.php/Project_ideas#Bad_block_tracking

My microsd card on rasberry PI failing. Some LBA sector constantly keep corrupting data, without causing any IO errors:

[/dev/mmcblk0p2].write_io_errs 0 [/dev/mmcblk0p2].read_io_errs 0 [/dev/mmcblk0p2].flush_io_errs 0 [/dev/mmcblk0p2].corruption_errs 263165505 [/dev/mmcblk0p2].generation_errs 0

After I moved to DUP data profile, all errors gone, probably because it have been masked by btrfs kernel driver and automatically corrected.

Since badblocks not yet implemented on kernel driver I have idea how to implement it on user space.

Btrfs know to support swap files. And swap files has to stick to specific sectors. We can use this feature to cover badblocks with badblocks-swap-files (size from 512bytes up to 1MB) located on top of badblocks sectors and stored inside /badblocks directory on filesystem.

Another solution is to use dm-liner to cover badblocks but it is very heavy and destructive.

EDIT: this drive reports no badblocks:

root@rpi:/home/axet# badblocks -s /dev/mmcblk0p2 Checking for bad blocks (read-only test): done

to clean all corruption dmesg spam (corruption_errs 263165505) I had only remove few files:

rm /var/log/daemon.log rm /var/log/syslog.1 rm /var/log/syslog rm /var/log/kern.log rm /var/log/messages

I guess btrfs can be smarter and mark corruption sectors to prevent corruption spam.

axet avatar Jul 31 '22 08:07 axet

IMHO this would be a welcome feature.

Some thoughts:

  • If Btrfs discovers corrupt sectors it could even mark those as 'non-use' to prevent further errors.
  • Scrub could be enhanced to mark bad sectors as well as re-test sectors. Useful if device is replaced using dd or if there were false positives.
  • btrfs check could import badblocks file from the badblocks utility.
  • btrfs device stats could list count of bad blocks.

The use cases are many.

  • Not all users can quickly replace a bad device.
  • Badblocks could help the filesystem survive much longer, giving users more time to act.
  • It may not be possible to run RAID1

Forza-tng avatar Jul 31 '22 08:07 Forza-tng

This has been discussed already, I'm not sure where, will try to find it. The general advice is to stop using such hardware as the numer of bad sectors will only grow, but there was some use case for tracking "unallocatable" blocks.

kdave avatar Aug 01 '22 12:08 kdave

@kdave for production yes. But what if you have home 2TB harddrive with few badblocks? I'm using such. I start failing in about 5 years ago, and it keep working. I'm using it for my multimedia storage. Replacing such drive is quite expensive, I'd like to keep using it until 90% of it would be covered in badblocks. It can work next 20 years or so. Hope btrfs can help me.

axet avatar Aug 05 '22 09:08 axet