From time to time I had hiccups with my USB 3 SSD when run Raspberry Pi diagnostics (agnostics). Occasionally it did not reach the 160MB/s advertised write speed. They were a bargain on amazon so I thought I have to live with this. 64GB SSD drive was 10 GBP while the USB 3 enclosure was 20 GBP.
This article from Jeff Geerling explains how to configure TRIM on SSD:
Enabling TRIM on an external SSD on a Raspberry Pi
Initially I observed that TRIM was not configured on my boot drive:
jordana@pi4g:~ $ sudo fstrim -v /
fstrim: /: the discard operation is not supported
jordana@pi4g:~ $ lsblk -D
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda 0 0B 0B 0
├─sda1 0 0B 0B 0
└─sda2 0 0B 0B 0
jordana@pi4g:~ $ sudo apt-get install -y sg3-utils lsscsi
jordana@pi4g:~ $ sudo sg_vpd -p bl /dev/sda
Block limits VPD page (SBC):
Maximum unmap LBA count: 4194240
Maximum unmap block descriptor count: 8
jordana@pi4g:~ $ sudo sg_vpd -p lbpv /dev/sda
Logical block provisioning VPD page (SBC):
Unmap command supported (LBPU): 1
I checked that the provisioning mode is full and changed it to unmap:
jordana@pi4g:~ $ sudo find /sys/ -name provisioning_mode -exec grep -H . {} + | sort
/sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/provisioning_mode:full
jordana@pi4g:~ $ sudo su
root@pi4g:/home/jordana# echo unmap > /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/provisioning_mode
This enabled TRIM and made my write speed consistent:
jordana@pi4g:~ $ sudo find /sys/ -name provisioning_mode -exec grep -H . {} + | sort
/sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/provisioning_mode:unmap
jordana@pi4g:~ $ lsblk -D
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda 0 512B 4G 0
├─sda1 0 512B 4G 0
└─sda2 0 512B 4G 0
jordana@pi4g:~ $ sudo fstrim -v /
/: 42.3 GiB (45465530368 bytes) trimmed
jordana@pi4g:~ $ sh /usr/share/agnostics/sdtest.sh
Run 1
prepare-file;0;0;164663;321
seq-write;0;0;163840;320
rand-4k-write;0;0;60179;15044
rand-4k-read;53108;13277;0;0
Sequential write speed 163840 KB/sec (target 10000) - PASS
Random write speed 15044 IOPS (target 500) - PASS
Random read speed 13277 IOPS (target 1500) - PASS
jordana@pi4g:~ $ systemd-analyze
Startup finished in 2.275s (kernel) + 14.610s (userspace) = 16.885s
graphical.target reached after 10.126s in userspace
To make this setting persistent I had to find out my idVendor:idProduct with lsusb and configure udev rule as follows:
No comments:
Post a Comment