Solved [SOLVED] How activate Trim for an SSD (MerlinWRT)?

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

RAH-66

Regular Contributor
[email protected]:/tmp/home/root# hdparm -I /dev/sda | grep TRIM
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIM

May 5 10:05:17 kernel: usbcore: registered new interface driver usb-storage
May 5 10:05:17 kernel: scsi host0: uas
May 5 10:05:17 kernel: scsi 0:0:0:0: Direct-Access CT240BX5 00SSD1 4101 PQ: 0 ANSI: 6
May 5 10:05:17 kernel: sd 0:0:0:0: Attached scsi generic sg0 type 0
May 5 10:05:17 kernel: sd 0:0:0:0: [sda] 468862128 512-byte logical blocks: (240 GB/224 GiB)
May 5 10:05:17 kernel: sd 0:0:0:0: [sda] 4096-byte physical blocks
May 5 10:05:17 kernel: usbcore: registered new interface driver uas
May 5 10:05:17 kernel: sd 0:0:0:0: [sda] Write Protect is off
May 5 10:05:17 kernel: sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
May 5 10:05:17 kernel: sda: sda1 sda2
May 5 10:05:17 kernel: sd 0:0:0:0: [sda] Attached SCSI disk

Code:
[email protected]:/tmp/home/root# mount | grep sda
/dev/sda1 on /tmp/mnt/opt type ext4 (rw,nodev,relatime,data=ordered)
/dev/sda2 on /tmp/mnt/TDDOWNLOAD type ext4 (rw,nodev,relatime,data=ordered)

Created /jiffs/config/fstab
Code:
/dev/sda1 /tmp/mnt/opt ext4 rw,nodev,relatime,discard,data=ordered 0 0
/dev/sda2 /tmp/mnt/TDDOWNLOAD ext4 rw,nodev,relatime,discard,data=ordered 0 0
/jiffs/scripts/init-start
Code:
#!/bin/sh
mkdir -p /tmp/mnt/opt
mkdir -p /tmp/mnt/TDDOWNLOAD

After reboot
[email protected]:/tmp/home/root# mount | grep sda
/dev/sda1 on /tmp/mnt/opt type ext4 (rw,nodev,relatime,discard,data=ordered)
/dev/sda2 on /tmp/mnt/TDDOWNLOAD type ext4 (rw,nodev,relatime,data=ordered)

Code:
[email protected]:/tmp/home/root# lsblk --discard | grep sd
sda               0        0B       0B         0
├─sda1            0        0B       0B         0
└─sda2            0        0B       0B         0

The first partition is mounted with the disсard option, while the second is not. Is it generally possible to run a Trim on MerlinWRT?
 

L&LD

Part of the Furniture
I would be shocked if this is possible on any current router.
 

kernol

Very Senior Member

L&LD

Part of the Furniture

RAH-66

Regular Contributor
An SSD aware OS.
What is missing from this OS (MerlinWRT)?
I used this SSD on this router for half a year without trim, the speeds did not drop much, but the recording gain was 4x.
According to the indicators of SMART, 2.7 TB was recorded, while the number of cell rewrites was 43, from here we have 43 * 240 GB = 10.3 TB

If the problem is in defining the bridge JMS580, I can change the vid/pid to any, for experiment (tell me which one).
 
Last edited:

L&LD

Part of the Furniture
I do not know what is missing specifically/technically. But having an SSD run without TRIM is different from having it run with it (the topic of this thread).

Maybe it is possible to do this? But again, I would be shocked if this were possible today.

And if it is possible, this is something that RMerlin and Asus should be compiling the firmware to support internally, in some near-future timeframe.
 

RAH-66

Regular Contributor
And if it is possible, this is something that RMerlin and Asus should be compiling the firmware to support internally, in some near-future timeframe.
RT-AС86U 3.0.0.4.384_82072 (last stock Asus) supports fstrim now?
Code:
[email protected]:/tmp/home/root# fstrim
BusyBox v1.24.1 (2020-08-08 01:33:36 CST) multi-call binary.

Usage: fstrim [OPTIONS] MOUNTPOINT

-o,--offset=OFFSET Offset in bytes to discard from
-l,--length=LEN Bytes to discard
-m,--minimum=MIN Minimum extent length
-v,--verbose Print number of discarded bytes
[email protected]:/tmp/home/root#
The owners of this model check the functionality.
 
Last edited:

RAH-66

Regular Contributor
@L&LD I found a solution to how to turn on the trim, working fine. From here.

The solution is to switch the SCSI driver from the UAS mode to the UNMAP mode.
Code:
[email protected]:/tmp/home/root# cat /sys/block/sda/device/scsi_disk/0\:0\:0\:0/provisioning_mode
full
[email protected]:/tmp/home/root# echo -n unmap > /sys/block/sda/device/scsi_disk/0\:0\:0\:0/provisioning_mode
[email protected]:/tmp/home/root# cat /sys/block/sda/device/scsi_disk/0\:0\:0\:0/provisioning_mode
unmap
[email protected]:/tmp/home/root# lsblk --discard /dev/sda
NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda           0        4K       4G         0
├─sda1        0        4K       4G         0
└─sda2        0        4K       4G         0
[email protected]:/tmp/home/root# opkg install fstrim
Installing fstrim (2.35.1-2) to root...
Downloading http://bin.entware.net/aarch64-k3.10/fstrim_2.35.1-2_aarch64-3.10.ipk                                               k
Configuring fstrim.
[email protected]:/tmp/home/root# fstrim -v /tmp/mnt/TDDOWNLOAD
/tmp/mnt/TDDOWNLOAD: 156.2 GiB (167684620288 bytes) trimmed
[email protected]:/tmp/home/root#
 
Last edited:

Elmer

Regular Contributor
Traveling into darkness here, but on my ax88 with attached sata drive ...

I think before setting the provisioning mode you need to download sg3_utils ('opkg install sg3_utils' and you may also want 'opkg install lsblk'). Now you can run the command:

sg_vpd --page=0xb2 /dev/sda

You'll get a response like this:

Logical block provisioning VPD page (SBC):
Unmap command supported (LBUP): 1
Write same (16) with unmap bit supported (LBPWS): 0
Write same (10) with unmap bit supported (LBPWS10): 0
Logical block provisioning read zeros (LBPRZ): 0
Anchored LBAs supported (ANC_SUP): 0
Threshold exponent: 1
Descriptor present (DP): 0
Minimum percentage: 0 [not reported]
Provisioning type: 0 (not known or fully provisioned)
Threshold percentage: 0 [percentages not supported]

Here are the options (more info at https://gist.github.com/cathay4t/e80e02a737242a5f3824606543631bfe):

  • If LBP VPD is not supported:
    • Use UNMAP command if BL VPD says MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT bigger than 1.
    • Use Write same 16 command otherwise.
  • If LBP VPD is supported:
    • Use UNMAP 0x42 command if LBP VPD says LBUP is 1.
    • Use WRITE SAME (16) 0x93 command if LBP VPD says LBPWS is 1.
    • Use WRITE SAME (10) 0x41 command if LBP VPD says LBPWS10 is 1.
    • Disable unmap support otherwise.

Even after provisioning to unmap, I got the following output from fstrim:

FITRIM ioctl failed: Input/output error
 

RAH-66

Regular Contributor
it's "paper" rubbish, its controller does not support unmap, only writesame_16
$ sudo sg_vpd --page=0xb2 /dev/sda
Logical block provisioning VPD page (SBC):
Unmap command supported (LBPU): 0
Write same (16) with unmap bit supported (LBWS): 1
Write same (10) with unmap bit supported (LBWS10): 0
Logical block provisioning read zeros (LBPRZ): 0
everything is here https://wiki.archlinux.org/index.php/Solid_state_drive#External_SSD_with_TRIM_support
the only difference command:
echo "unmap" >/sys/block/sdX/device/scsi_disk/*/provisioning_mode
echo -n unmap > /sys/block/sdX/device/scsi_disk/*/provisioning_mode
verification:
cat /sys/block/sdX/device/scsi_disk/*/provisioning_mode
lsblk --discard /dev/sdX

What is the model of your USB-SATA controller and what is the command output hdparm -I /dev/sdX | grep TRIM
 
Last edited:

thecheapseats

Regular Contributor

Elmer

Regular Contributor
it's "paper" rubbish, its controller does not support unmap, only writesame_16

everything is here https://wiki.archlinux.org/index.php/Solid_state_drive#External_SSD_with_TRIM_support
the only difference command:

verification:


What is the model of your USB-SATA controller and what is the command output hdparm -I /dev/sdX | grep TRIM
The controller the author was looking at did not support unmap. The method to query the drive (sg_vpd --page=0xb2 /dev/sda) is valid
My drive is a Sabrent 120GB usb-sata (120GB)
output from: hdparm -I /dev/sda | grep TRIM
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIM
 

Elmer

Regular Contributor
lsusb on the router doesn't seem to accept any flags. the only output i can get is:

Bus 002 Device 002: ID 152d:1561
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0003
Bus 003 Device 001: ID 1d6b:0002
Bus 004 Device 001: ID 1d6b:0001
 

RAH-66

Regular Contributor
Bus 002 Device 002: ID 152d:1561

It`s JMicron, most likely model JMS578, but you must make sure of this by disassembling the case and reading the markings on the chip.
There were a lot of firmware patches for this model, visit the container manufacturer's website and read this.
 
Last edited:

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top