Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Discard over USB
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1810
Location: PB, Germany

PostPosted: Sun Mar 31, 2024 5:22 pm    Post subject: Discard over USB Reply with quote

Hello,

this is the discussion thread about https://wiki.gentoo.org/wiki/Discard_over_USB ...
_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1810
Location: PB, Germany

PostPosted: Sun Mar 31, 2024 5:54 pm    Post subject: Reply with quote

From this wiki I learned, that trim via USB bridges is not trivial.
I'm using btrfs on LUKS on all my devices that are HDDs, SATA SSDs and NVMe SSDs.
I came to investigate trim and discard further as sometimes by BTRFS is blocking all IO right after booting:
https://lore.kernel.org/linux-btrfs/238dc2b36f27838baf02425b364705c58fcc5de5.camel@gmx.net
The mount option discard maybe envolved in this issue so I disabled that on all devices...

What happens if an USB bridge does not support trim? Someday the SSD can't write anymore without moving to another controler to get the trim done?

I have a Ugreen SSD M.2 NVMe enclosure with USB 3.1 Gen2. Following the Wiki it first looks like supporting trim but then it fails:
Code:
# lsusb.py |grep Ugreen
  4-6               0bda:9210 00 1IF  [USB 3.20,  5000 Mbps, 896mA] (Ugreen Ugreen Storage Device 0129380014F4)

# lsusb |grep 9210
Bus 004 Device 004: ID 0bda:9210 Realtek Semiconductor Corp. RTL9210 M.2 NVME Adapter

# eix -Ic usbutils
[I] sys-apps/usbutils (017@19.01.2024): USB enumeration utilities

Code:
# find /sys/ -name provisioning_mode -exec grep -H . {} + | sort
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-14/2-14:1.0/host6/target6:0:0/6:0:0:0/scsi_disk/6:0:0:0/provisioning_mode:full
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-14/2-14:1.0/host6/target6:0:0/6:0:0:1/scsi_disk/6:0:0:1/provisioning_mode:full
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-14/2-14:1.0/host6/target6:0:0/6:0:0:2/scsi_disk/6:0:0:2/provisioning_mode:full
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-14/2-14:1.0/host6/target6:0:0/6:0:0:3/scsi_disk/6:0:0:3/provisioning_mode:full
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-14/2-14:1.0/host6/target6:0:0/6:0:0:4/scsi_disk/6:0:0:4/provisioning_mode:full
/sys/devices/pci0000:00/0000:00:14.0/usb2/2-7/2-7:1.0/host7/target7:0:0/7:0:0:0/scsi_disk/7:0:0:0/provisioning_mode:full
/sys/devices/pci0000:00/0000:00:14.0/usb4/4-6/4-6:1.0/host5/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0/provisioning_mode:unmap
/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/provisioning_mode:writesame_16
/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/scsi_disk/1:0:0:0/provisioning_mode:full

I guess this is my device:
Code:
# find /sys/ -name provisioning_mode -exec grep -H . {} + | sort |grep 4-6
/sys/devices/pci0000:00/0000:00:14.0/usb4/4-6/4-6:1.0/host5/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0/provisioning_mode:unmap

Code:
# fdisk -l /dev/sdh
Disk /dev/sdh: 3,64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model:  SN850X 4000GB 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: gpt
Disk identifier: ...

Device      Start        End    Sectors  Size Type
/dev/sdh1    2048      73727      71680   35M EFI System
/dev/sdh2   73728     598015     524288  256M Linux filesystem
/dev/sdh3  598016 7814035455 7813437440  3,6T Linux filesystem

Code:
# sg_vpd -p bl /dev/sdh
Block limits VPD page (SBC):
  Write same non-zero (WSNZ): 0
  Maximum compare and write length: 0 blocks [Command not implemented]
  Optimal transfer length granularity: 1 blocks
  Maximum transfer length: 65535 blocks
  Optimal transfer length: 65535 blocks
  Maximum prefetch transfer length: 0 blocks [ignored]
  Maximum unmap LBA count: 20971520
  Maximum unmap block descriptor count: 1
  Optimal unmap granularity: 1 blocks
  Unmap granularity alignment valid: false
  Unmap granularity alignment: 0 [invalid]
  Maximum write same length: 0 blocks [not reported]
  Maximum atomic transfer length: 0 blocks [not reported]
  Atomic alignment: 0 [unaligned atomic writes permitted]
  Atomic transfer length granularity: 0 [no granularity requirement
  Maximum atomic transfer length with atomic boundary: 0 blocks [not reported]
  Maximum atomic boundary size: 0 blocks [can only write atomic 1 block]

# sg_vpd -p bl /dev/sdh |grep "Maximum unmap LBA"
  Maximum unmap LBA count: 20971520


Up to here, it looks like trim might be supported.

Unmap was already set because I ran the steps already before this post. Anyway, setting again:

Code:
# echo unmap > /sys/devices/pci0000:00/0000:00:14.0/usb4/4-6/4-6:1.0/host5/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0/provisioning_mode

# echo '20971520*512' | bc
10737418240

# echo $(echo '20971520*512' | bc) > /sys/block/sdh/queue/discard_max_bytes
-bash: echo: write error: Invalid argument

... and failing here. What can I do? What does this mean?
_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54577
Location: 56N 3W

PostPosted: Sun Mar 31, 2024 6:13 pm    Post subject: Reply with quote

Massimo B.

So far so good.

Is using
Code:
echo 10737418240  >  /sys/block/sdh/queue/discard_max_bytes
any help?

If trim cannot be enabled, the drive will do some clean up, when a write is commanded. It will have to do an erase first.
Trim allows the drive to do the clean up in advance of the write that would force it, thus avoiding the slow erase cycle slowing writes.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1810
Location: PB, Germany

PostPosted: Sun Mar 31, 2024 6:19 pm    Post subject: Reply with quote

Does that mean, if trim is not supported, that the device is getting slower when getting more bytes written over time, or that every write is just always slower on this USB bridge?

That echo is failing as mentioned above:
Code:
# echo 10737418240  >  /sys/block/sdh/queue/discard_max_bytes
-bash: echo: write error: Invalid argument

_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54577
Location: 56N 3W

PostPosted: Sun Mar 31, 2024 6:29 pm    Post subject: Reply with quote

Massimo B.

What does
Code:
cat /sys/block/sdh/queue/discard_max_hw_bytes
tell?
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1810
Location: PB, Germany

PostPosted: Tue Apr 02, 2024 6:40 am    Post subject: Reply with quote

Code:
# echo 10737418240  >  /sys/block/sdh/queue/discard_max_bytes
-bash: echo: write error: Invalid argument

# cat /sys/block/sdh/queue/discard_max_bytes
4294966784

Does that discard_max_bytes need to know anything about the partitioning and the LUKS device, or does it only see the block device? Why is that set size smaller than expected?
_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1810
Location: PB, Germany

PostPosted: Thu Jun 27, 2024 11:52 am    Post subject: Reply with quote

Any idea how to enable discard on that USB-NVMe bridge?
_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum