The empty values for the queue mean that UNMAP was not properly applied to the device, even though the mode is set by the unmap script. I think it's either the enclosure or the SSD that isn't supported. I'll probably add an explicit error message for such cases to the script by checking these values.File systemp is ext4:
/dev/sda1 ext4 57431276 2203612 52280544 4% /tmp/mnt/SSD
cat /sys/block/sda/queue/discard_max_bytes
0
cat /sys/block/sda/queue/discard_granularity
0
Your drive reports proper values. What file system are you using? ext4?I have other values:
Code:➜ cat /sys/block/sda/queue/discard_max_bytes 4294966784 ➜ cat /sys/block/sda/queue/discard_granularity 4096
ssd_trim: ERROR: fstrim: FITRIM: Inappropriate ioctl for device
Yes:What file system are you using? ext4?
➜ mount | grep ssd
/dev/sda1 on /tmp/mnt/ssd type ext4 (rw,nodev,relatime)
➜ lsblk -D /dev/sda1
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda1 0 4K 4G 0
This is the same as readingAccording to the link below a value greater than zero for DISC-MAX would mean that TRIM might be enabled?
discard_max_bytes
directly from /sys/block
, which we have already done.unmap
, and you have discard_max_bytes > 0
, but fstrim
fails with FITRIM: Remote I/O error
, which is different from FITRIM: Operation not supported
. Basically, that means the discard command reaches the device, but the device or bridge fails while executing it. This looks like a buggy USB bridge (or firmware) that claims unmap
but doesn't handle it correctly.discard_max_bytes = 0
simply indicate that TRIM is not supported.fstrim -v -o 4096 -l $((1024*1024)) /tmp/mnt/ssd
Result:I have one more idea for you to check - try trimming just 1 MB:
Code:fstrim -v -o 4096 -l $((1024*1024)) /tmp/mnt/ssd
➜ fstrim -v -o 4096 -l $((1024*1024)) /tmp/mnt/ssd
/tmp/mnt/ssd: 0 bytes trimmed
What did you change to make it start working? Did you modifyTRIM initially did not work for the same HW combo on my Raspberry Pi 4 B either, but using these instructions I got it to work on that platform:
Enabling TRIM on an external SSD on a Raspberry Pi | Jeff Geerling
www.jeffgeerling.com
Do we have similar tools for our ASUS routers?
discard_max_bytes
to a custom value? Based on the output of the fstrim
command set to 1 MB, TRIM reaches your disk, but it probably doesn’t know the correct number of bytes (the default may be wrong) and fails.fstrim
, similar to the "Enabling TRIM" section in the tutorial.I first had to change the provisioning mode fromWhat did you change to make it start working? Did you modifydiscard_max_bytes
to a custom value?
full
to unmap
, but I indeed also had to modify discard_max_bytes
to a non-default value. I had to set discard_max_bytes
to a multiple of discard_granularity
, as Tom suggested in the comments. Using a corrected version of his script, the value for my HW combo apparently is 33550336
, but I don't know how to try/set it on the router as well.Duplicate thisHow to set up the SSD trim for multiple drives?
pre-mount
block per device for unmap, specifying a different per-drive SSD_VOLUME_LABEL
each time:SSD_VOLUME_LABEL_1='ssd1'
SSD_VOLUME_LABEL_1='ssd2'
if tune2fs -l "$1" 2>/dev/null |
grep -q "Filesystem volume name: *$SSD_VOLUME_LABEL_1$";
then
/jffs/scripts/ssd/ssd_unmap.sh # specify your Vendor ID here
fi
if tune2fs -l "$1" 2>/dev/null |
grep -q "Filesystem volume name: *$SSD_VOLUME_LABEL_2$";
then
/jffs/scripts/ssd/ssd_unmap.sh # specify your Vendor ID here
fi
services-start
per every device:cru a trim_ssd_1 "0 4 * * 0 /jffs/scripts/ssd/ssd_trim.sh ssd1"
cru a trim_ssd_2 "0 4 * * 0 /jffs/scripts/ssd/ssd_trim.sh ssd2"
Simply add these lines to yourI first had to change the provisioning mode from full to unmap, but I indeed also had to modify discard_max_bytes to a non-default value. I had to set discard_max_bytes to a multiple of discard_granularity, as Tom suggested in the comments. Using a corrected version of his script, the value for my HW combo apparently is 33550336, but I don't know how to try/set it on the router as well.
ssd_unmap.sh
:echo <YOUR_VALUE> > /sys/block/sda/queue/discard_max_bytes
echo <YOUR_VALUE> > /sys/block/sda/queue/discard_granularity
sda
is not guaranteed if you have multiple USB devices attached, in that case you need to figure it out dynamically./sys/block/sda/queue/discard_max_bytes
and now it seems to work?! ➜ echo 33550336 > /sys/block/sda/queue/discard_max_bytes
➜ ./ssd_trim.sh ssd
ssd_trim: Running fstrim on /tmp/mnt/ssd...
ssd_trim: /opt/sbin/fstrim succeeded: /tmp/mnt/ssd: 243424014336 bytes trimmed
➜ ./ssd_trim.sh ssd
ssd_trim: Running fstrim on /tmp/mnt/ssd...
ssd_trim: /opt/sbin/fstrim succeeded: /tmp/mnt/ssd: 0 bytes trimmed
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!