How to test SSDs or NVMe for badblocks'?

Solution 1:

In general, you shouldn't need to, beyond paying attention to what SMART is already telling you. The reason is that SSDs use wear leveling, so they have an advanced controller that already takes care of detecting and re-mapping bad blocks in the background, so from the OS's perspective, and the perspective of standard utilities like badblocks, any blocks that went bad are invisible because they've already been remapped. If badblocks somehow did find a block that was bad, it would be immediately remapped and thus would be "good" again the next time you read it.

To really get an indication of the health of your drive, what you need to know is how many bad blocks the controller has already remapped, and how much spare capacity remains to allow it to remap further. SMART data should give you this for SATA, or NVMe has equivalent log pages that contain the same information. In particular, the 'Available Spare' attribute will give you a percentage of how much of the drive's total remapping capability has been used up.

This page has some specific command line tools you can use for SATA or NVMe: https://www.percona.com/blog/2017/02/09/using-nvme-command-line-tools-to-check-nvme-flash-health/