I'd like to test my hard disks with badblocks, but I don't know which values I should use for the block size (-b option) and blocks number (-c option). I randomly tried a few values and it seems they can significantly change the speed of the process. But how can I choose the optimal values?
-
1Seems to be a duplicate of [How do I choose the right parameters when using badblocks?](http://askubuntu.com/q/59425) and [Using \`badblocks\` on modern disks.](http://superuser.com/q/528176). – doktor5000 May 10 '15 at 18:34
-
1@doktor5000 the same question on different sites of the SE network is not considered a duplicate and there is no way of marking it as such. If it were from the same poster, that would be considered cross-posting which is something we don't like, but different users with the same issue on different sites is not considered a problem. Oh, and to format links in comments, you need to write: `[link text](http://www.linktarget.com)`. – terdon May 10 '15 at 18:42
-
@terdon: Thanks for the explanation and editing my comment :) As my answer has been automatically converted to a comment as a *trivial answer* what would be the preferred way to answer this question, if the provided links already contain this information and more details? Copy & paste the relevant stuff again here, wouldn't that be suboptimal? – doktor5000 May 10 '15 at 18:46
-
@doktor5000 yes, it is suboptimal. Unfortunately, it is also the only choice available. I had actually posted [a meta question](http://meta.unix.stackexchange.com/q/1396/) about this a while back. The best thing to do is to combine the information from the other answers into your own, making sure you give credit to the original authors. – terdon May 10 '15 at 19:07
-
@terdon: Thanks for the link, did it like it was suggested there, including marking the answer as community wiki. – doktor5000 May 10 '15 at 19:44
1 Answers
Here are the relevant excerpts for the same question which have been answered already at How do I choose the right parameters when using badblocks? and Using badblocks on modern disks.
There is a badblocks benchmark script available that should suit your purpose.
With regards to the -b option: this depends on your disk. Modern, large disks have 4KB blocks, in which case you should set -b 4096. You can get the block size from the operating system (e.g. lsblk -o NAME,PHY-SeC /dev/sdX), and it's also usually obtainable by either reading the disk's information off of the label, or by googling the model number of the disk. If -b is set to something larger than your block size, the integrity of badblocks results can be compromised (i.e. you can get false-negatives: no bad blocks found when they may still exist). If -b is set to something smaller than the block size of your drive, the speed of the badblocks run can be compromised. I'm not sure, but there may be other problems with setting -b to something smaller than your block size, since it isn't verifying the integrity of an entire block, it might still be possible to get false-negatives if it's set too small.
The -c option corresponds to how many blocks should be checked at once. Batch reading/writing, basically. This option does not affect the integrity of your results, but it does affect the speed at which badblocks runs. badblocks will (optionally) write, then read, buffer, check, repeat for every N blocks as specified by -c. If -c is set too low, this will make your badblocks runs take much longer than ordinary, as queueing and processing a separate IO request incurs overhead, and the disk might also impose additional overhead per-request. If -c is set too high, badblocks might run out of memory. If this happens, badblocks will fail fairly quickly after it starts. Additional considerations here include parallel badblocks runs: if you're running badblocks against multiple partitions on the same disk (bad idea), or against multiple disks over the same IO channel, you'll probably want to tune -c to something sensibly high given the memory available to badblocks so that the parallel runs don't fight for IO bandwidth and can parallelize in a sane way.
I have this answer as community wiki for further improvement
- 8,772
- 19
- 65
- 129
- 2,689
- 15
- 30
-
I hoped for a universal formula to calculate the value of ``-c``. I will try the benchmark script instead. – May 12 '15 at 12:55
-
Did you read the linked threads? They mention that mostly -c does not make any difference, and in the example benchmark results you can see that the time only increases when you choose nondefault, suboptimal settings. – doktor5000 May 12 '15 at 14:43
-
I don't think so. In my case using the default ``-c`` value (that is, omitting it) is significantly slower than using higher values (32768 or 65536). – May 13 '15 at 17:32
-
Can you add some explanation for the "If -b is set to something larger than your block size, the integrity of badblocks results can be compromised" part? Why can that happen? – Alexandros Sep 15 '22 at 14:00
-
@Alexandros: You may want to ask the author of the original answer from [Using badblocks on modern disks](https://superuser.com/questions/528176/using-badblocks-on-modern-disks) as this one is basically only an excerpt, as noted above. – doktor5000 Sep 17 '22 at 13:57