You are not logged in.

#1 2018-04-16 07:19:29

tingdling
Member
Registered: 2017-07-16
Posts: 6

[SOLVED] TRIM in external SSD - USB3 UASP

Hello,

I have an externalized SSD and use it for virtual machine. It sometimes get quite slow and I suspect it might be because of the device can't get trimed.
I've read it isn't really possible to do that, but these entries I found were from 5 years ago which is a lot in OS terms..
So I'd like to ask, is there a known way to make device in external USB3 enclosure trim? (Given the UASP is properly supported and handled.)

I've checked the drive for TRIM capability

sudo hdparm -I /dev/sdb | grep TRIM
           *    Data Set Management TRIM supported (limit 8 blocks)

and for uas module usage

lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=uas, 5000M


lsusb -v -d 174c:1053| grep -i interface
    bNumInterfaces          1
    Interface Descriptor:
      bInterfaceNumber        0
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk-Only
      iInterface              0 
    Interface Descriptor:
      bInterfaceNumber        0
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     98 
      iInterface              0 

So from what I've read the HW setup should be OK and should support trim. Issuing fstrim on mountpoint returns the operation is not supported.

Last edited by tingdling (2018-05-14 16:00:57)

Offline

#2 2018-04-23 12:35:07

tbg
Member
Registered: 2017-06-22
Posts: 72

Re: [SOLVED] TRIM in external SSD - USB3 UASP

There seems to be very little info available on this subject. It would certainly be nice to have some feedback from Archers who have gotten trim working successfully over USB.

Offline

#3 2018-04-27 10:34:45

tbg
Member
Registered: 2017-06-22
Posts: 72

Re: [SOLVED] TRIM in external SSD - USB3 UASP

See this link for some further info:

https://forum.manjaro.org/t/solved-trim … sd/45585/9

Offline

#4 2018-05-14 16:00:24

tingdling
Member
Registered: 2017-07-16
Posts: 6

Re: [SOLVED] TRIM in external SSD - USB3 UASP

Hello again,

I can confirm it is an enclosure chip issue. I bought the one mentioned in the manjaro forum and it is really working with fstrim.
So yes, everything in Arch is ready and OK, the enclosure support is the problem...

Offline

#5 2018-06-27 22:14:50

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: [SOLVED] TRIM in external SSD - USB3 UASP

I know this is marked as solved but I'll add some of the things have been able to figure out on my own.

The usb bridge might support passing the trim commands to the SSD _but_ linux might not make use of it because not all the "magic bits are set. A good starting point is to look at the enclose reviews under windows and see if trim works there, if it does you may be able to coerce linux to use/issue trim commands to the drive behind the bridge chip.

Some spec say that a few of the bits that the bridge returns upon inquiry must be set for trim to be supported/used, linux does this by the book and if any of the right bits are not set linux will not try to make use of trim. The problem here is that windows checks only some of the bits, and as is usual who cares about any spec if it works on windows.

What you want to be looking at is the output of 'sg_readcap -l /dev/sdX' and 'sg_vpd -a /dev/sdX'.

In the output of sg_readcap you want to get 'lbpme=1' and in the output of sg_vpd you want to get which method is supported from 'Unmap command supported (LBPU)', Write same (16) with unmap bit supported (LBWS)' and 'Write same (10) with unmap bit supported (LBWS10)'.

You can write an udev rule to then coerce linux to use trim even if lbpme=0.

One external enclose I have reports lbpme=0 and 'Unmap command supported (LBPU): 1', so the way to issue trim is via an unmap command, the rule that tells the kernel to use unmap for trim goes like this:

ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="1351", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"

If a different method is used for the enclose you are using you will have to dig into the kernel source to see the proper value to write to provisioning_mode.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#6 2018-11-06 17:58:48

aiacobsde
Member
Registered: 2018-11-06
Posts: 1

Re: [SOLVED] TRIM in external SSD - USB3 UASP

Hello,

Your solution worked for me on VIA VL716 chip. Maybe this will help someone else too:

ACTION=="add|change", ATTRS{idVendor}=="2109", ATTRS{idProduct}=="0715", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"

motoko ~ # sg_readcap -l /dev/sdc
Read Capacity results:
   Protection: prot_en=0, p_type=0, p_i_exponent=0
   Logical block provisioning: lbpme=0, lbprz=0
   Last logical block address=1000215215 (0x3b9e12af), Number of logical blocks=1000215216
   Logical block length=512 bytes
   Logical blocks per physical block exponent=0
   Lowest aligned logical block address=0
Hence:
   Device size: 512110190592 bytes, 488386.3 MiB, 512.11 GB
motoko ~ # sg_vpd -a /dev/sdc
Supported VPD pages VPD page:
  Supported VPD pages [sv]
  Unit serial number [sn]
  Device identification [di]
  Block limits (SBC) [bl]
  Logical block provisioning (SBC) [lbpv]
Unit serial number VPD page:
  Unit serial number: 000000123F1D
Device Identification VPD page:
  Addressed logical unit:
    designator type: NAA,  code set: Binary
      0x5002538d00000000
Block limits VPD page (SBC):
  Write same non-zero (WSNZ): 0
  Maximum compare and write length: 0 blocks
  Optimal transfer length granularity: 8 blocks
  Maximum transfer length: 65535 blocks
  Optimal transfer length: 65535 blocks
  Maximum prefetch length: 65535 blocks
  Maximum unmap LBA count: 4194240
  Maximum unmap block descriptor count: 8
  Optimal unmap granularity: 0
  Unmap granularity alignment valid: 0
  Unmap granularity alignment: 0
  Maximum write same length: 0x0 blocks
  Maximum atomic transfer length: 0
  Atomic alignment: 0
  Atomic transfer length granularity: 0
Logical block provisioning VPD page (SBC):
  Unmap command supported (LBPU): 1
  Write same (16) with unmap bit supported (LBWS): 0
  Write same (10) with unmap bit supported (LBWS10): 0
  Logical block provisioning read zeros (LBPRZ): 0
  Anchored LBAs supported (ANC_SUP): 0
  Threshold exponent: 1
  Descriptor present (DP): 0
  Provisioning type: 0

Thanks mate!

Offline

#7 2019-04-14 21:53:03

nkichukov
Member
Registered: 2019-04-14
Posts: 1

Re: [SOLVED] TRIM in external SSD - USB3 UASP

Thanks for the post R00KIE!
This also makes trim work on:
ID 04e8:61f5 Samsung Electronics Co., Ltd Portable SSD T5

Special thanks one more time. Registered into this forum just to say thank you.
Cheers,
-N

Offline

#8 2019-04-14 23:57:40

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: [SOLVED] TRIM in external SSD - USB3 UASP

Closing this old topic.

Offline

Board footer

Powered by FluxBB