Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to enable TRIM for logical volumes on USB device?
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
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1472
Location: Richmond Hill, Canada

PostPosted: Sun Mar 27, 2022 1:53 am    Post subject: How to enable TRIM for logical volumes on USB device? Reply with quote

Hi,

I have a SAMSUNG T5 1TB, it is connected over USB-3 port, I use lvm created several logical volumes (lv).

Initially I was not able to use fstrim for file system for any lv. then I learn I need to enable device's provisioning_mode by change its value to unmap. Also change /sys/block/sda/queue/discard_max_bytes to 2147450880.

After above I see lsblk -D changed to allow TRIM,
Code:
NAME            DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                    0      512B       4G         0
├─vg0-swapvol          0        0B       0B         0
├─vg0-dockervol        0        0B       0B         0
├─vg0-uvol             0        0B       0B         0
├─vg0-s2               0        0B       0B         0
└─vg0-pi--3            0        0B       0B         0


However those lv remain no DISCARD setting (as in they are all zero).

So my question, is there a way to change them?


I tested by create new lv which did inherit the DISCARD setting from /dev/sda
Code:
NAME            DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                    0      512B       4G         0
├─vg0-swapvol          0        0B       0B         0
├─vg0-dockervol        0        0B       0B         0
├─vg0-uvol             0        0B       0B         0
├─vg0-s2               0        0B       0B         0
├─vg0-pi--3            0        0B       0B         0
└─vg0-testlv           0      512B       4G         0
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3948

PostPosted: Sun Mar 27, 2022 5:56 pm    Post subject: Reply with quote

For me this udev rule works
Code:

ACTION=="add|change", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="61f5", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"

with T5.
You might get the ids by running
Code:

lsusb

I am not sure it will work for lv also.
You might try it.
_________________
:)


Last edited by alamahant on Sun Mar 27, 2022 6:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Sun Mar 27, 2022 5:59 pm    Post subject: Reply with quote

pingtoo,

Discard_over_USB
I found that logical volumes needed a reboot. See the note.
_________________
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
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1472
Location: Richmond Hill, Canada

PostPosted: Sun Mar 27, 2022 7:48 pm    Post subject: Reply with quote

Hi,

Thanks for taking time review my question and give answers.

My problem is that logical volumes on the USB disk NOT having the TRIM enabled. I successful enable the USB disk by follow the Discard_over_USB.

So for example, under this condition,
Code:
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT  DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda               8:0    0 931.5G  0 disk                    0      512B       4G         0
├─vg0-swapvol   254:0    0     4G  0 lvm  [SWAP]             0      512B       4G         0
├─vg0-dockervol 254:1    0    50G  0 lvm  /opt/docker        0        0B       0B         0
├─vg0-uvol      254:2    0   100G  0 lvm  /u                 0        0B       0B         0
├─vg0-s2        254:3    0     6G  0 lvm  [SWAP]             0      512B       4G         0
├─vg0-pi--3     254:4    0    10G  0 lvm                     0        0B       0B         0
└─vg0-testlv    254:5    0   100M  0 lvm  /tmp/mnt           0      512B       4G         0


fstrim failed for vg0/dockervol
Code:
root@fatman:~# fstrim -v /opt/docker/
fstrim: /opt/docker/: the discard operation is not supported


However it work for vg0/testlv
Code:
root@fatman:~# fstrim -v /tmp/mnt
/tmp/mnt: 91.3 MiB (95748096 bytes) trimmed


vg0/testlv was created after the USB disk enable TRIM setting.

vg0/swapvol and vg0/s2 got enabled after I did a lvreduce. However all LVs will get reset back to 0 after reboot. Only the USB disk remain enabled.
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