Jump to content
potatows

SSD Trim Not Working?

14 posts in this topic Last Reply

Recommended Posts

Wanted to make sure trim was working, SSD seems to be acting a bit odd at times. For example, copied a large file to it copying maxed out around 20 MB/s and the system ui locked up, dockers lagged out, etc.

 

I have the trim plugin installed which is set to run every day, i also have tried running the trim command manually which results in:

 

root@XXXXXXXX:~# fstrim -v /mnt/cache
/mnt/cache: 56 KiB (57344 bytes) trimmed

 

The automatically run trim outputs the following:

Sep 10 05:00:01 Potato root: /etc/libvirt: 911 MiB (955297792 bytes) trimmed
Sep 10 05:00:01 Potato root: /var/lib/docker: 12.9 GiB (13865934848 bytes) trimmed
Sep 10 05:00:01 Potato root: /mnt/cache: 56 KiB (57344 bytes) trimmed

 

I read from https://forums.lime-technology.com/topic/35921-how-to-implement-trim-on-ssd-drives/ that the bytes shown is available space on the ssd.

56kb is obviously not the free space on the ssd, it is a sandisk ultra II 480GB, with ~240 free.

 

So is trim working correctly? Did I set something up wrong?

Share this post


Link to post

Do you have the ssd plugged into a HBA or directly into the motherboard? There is a thread in the limetech forums where the ssd wouldn't trim if plugged into a HBA. 

Other than this hint, my expertise ends. Hope this helps. 

Share this post


Link to post
6 minutes ago, BillClinton said:

Do you have the ssd plugged into a HBA or directly into the motherboard? There is a thread in the limetech forums where the ssd wouldn't trim if plugged into a HBA. 

Other than this hint, my expertise ends. Hope this helps. 

 

Plugged into an P8B WS Asus motherboard, into the one of the two intel 6GB/s ports. Latest bios, set to ahci in bios.

Share this post


Link to post

Is your cache btrfs? IIRC correctly with btrfs only the unallocated space is trimmed, if it is post the output of:

 

btrfs dev usage /mnt/cache

 

Edited by johnnie.black

Share this post


Link to post
14 hours ago, johnnie.black said:

Is your cache btrfs? IIRC correctly with btrfs only the unallocated space is trimmed, if it is post the output of:

 


btrfs dev usage /mnt/cache

 

/dev/sdc1, ID: 1
   Device size:           447.13GiB
   Device slack:              0.00B
   Data,single:           445.10GiB
   Metadata,single:         2.00GiB
   System,single:          32.00MiB
   Unallocated:             1.05MiB

 

 

So unallocated is different than space being used by data then? cause that output shows 445.10 data usage, yet the drive has 343GB free right now.

Share this post


Link to post
5 hours ago, potatows said:

yet the drive has 343GB free right now.

 

Strange, not according to dev usage, please post your diagnostics and also the output of:

 

btrfs fi usage /mnt/cache

 

Edited by johnnie.black

Share this post


Link to post
On 9/13/2017 at 2:41 AM, johnnie.black said:

 

Strange, not according to dev usage, please post your diagnostics and also the output of:

 


btrfs fi usage /mnt/cache

 

root@Potato:~# btrfs fi usage /mnt/cache
Overall:
    Device size:                 447.13GiB
    Device allocated:            447.13GiB
    Device unallocated:            1.05MiB
    Device missing:                  0.00B
    Used:                        144.76GiB
    Free (estimated):            300.98GiB      (min: 300.98GiB)
    Data ratio:                       1.00
    Metadata ratio:                   1.00
    Global reserve:              185.56MiB      (used: 0.00B)

Data,single: Size:445.10GiB, Used:144.11GiB
   /dev/sdc1     445.10GiB

Metadata,single: Size:2.00GiB, Used:658.38MiB
   /dev/sdc1       2.00GiB

System,single: Size:32.00MiB, Used:64.00KiB
   /dev/sdc1      32.00MiB

Unallocated:
   /dev/sdc1       1.05MiB

 

 

 

Ah so unallocated is different from free space. I was getting confused between the two terms.

 

So i guess trim is being used correctly then?

Share this post


Link to post
Just now, potatows said:

So i guess trim is being used correctly then?

 

Yes and no, there's a bug for some time that only unallocated space is trimmed, so since your filesystem is almost fully allocated most of the free space is not being trimmed, see here for more info:

 

 

Share this post


Link to post
2 hours ago, johnnie.black said:

 

Yes and no, there's a bug for some time that only unallocated space is trimmed, so since your filesystem is almost fully allocated most of the free space is not being trimmed, see here for more info:

 

 

 

WOW, thanks for linking me that.

 

I followed the instructions and this fixed all of my problems.

 

Copied a 35gb file to the ssd and the web ui, dockers, everything didn't even slow down or freeze.

 

I felt like something was wrong for a long time but no matter how much i googled I couldn't find a solution. Had started to wonder if the ssd had issues.

Share this post


Link to post
On 9/17/2017 at 7:20 PM, potatows said:

 

WOW, thanks for linking me that.

 

I followed the instructions and this fixed all of my problems.

 

Copied a 35gb file to the ssd and the web ui, dockers, everything didn't even slow down or freeze.

 

I felt like something was wrong for a long time but no matter how much i googled I couldn't find a solution. Had started to wonder if the ssd had issues.

 

It's a thread with 4 pages. Which instructions are you talking about>

Share this post


Link to post
On 6/16/2018 at 5:55 PM, potatows said:

There are at least a dozen different "try this" in the thread. which post actually has the answer? You posted page 1

 

Share this post


Link to post
On 6/18/2018 at 8:09 PM, elmetal said:

 

 

I should mention I have not needed to do this in a long time.

I moved all my downloading and extracting operations to a second ssd mounted with unnassigned devices and I no longer have this problem.

 

In case you still are trying to find it:

From johnnie.black

Quote

 

I have a theory on why some users may be having this issue, if anyone wants to try and post if there was an improvement please do.

 

Currently fstrim on btrfs is only trimming the unallocated space, this is apparently a bug but it's been like this for some time, for some users with a large slack on the filesystem this will be a very small area of the SSD leaving all unused but allocated space untrimmed, this can lead to very poor performance, so first check for slack on the filesystem, i.e., the difference between the allocated and used space, on the main page click on cache and look at the "btrfs filesystem show" section, e.g.,:

 


Label: none  uuid: cea535d2-33f9-4cf2-9ff0-0b51826d48a1
	Total devices 1 FS bytes used 265.61GiB
	devid    1 size 476.94GiB used 427.03GiB path /dev/nvme0n1p1

In this case there's about 161GiB of slack, 476.94GiB is the total device size, 427.03GiB are allocated but only 265.61GiB are in use, since only unallocated space is trimmed, fstrim will only trim 49.9GiB (476.94-427.03) so most free space will remain untrimmed, to fix this run a full balance to reclaim all allocated but unused space, on the console type:


btrfs balance start --full-balance /mnt/cache

This will take some time, in the end it should look like this:


Label: none  uuid: cea535d2-33f9-4cf2-9ff0-0b51826d48a1
	Total devices 1 FS bytes used 265.68GiB
	devid    1 size 476.94GiB used 266.03GiB path /dev/nvme0n1p1

Now slack space is less than 1GiB, so fstrim will work on practically all unused space, trim you pool:


fstrim -v /mnt/cache

And check if performance improves.

 

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.