Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
No Fstrim
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
BWStevens
n00b
n00b


Joined: 10 Jun 2015
Posts: 61
Location: Hobart

PostPosted: Thu Mar 03, 2016 12:16 pm    Post subject: No Fstrim Reply with quote

Hi community,

I've got a 250gig Kingston SSD. I don't enable discard in my fstab as I like to just do a fstrim -v /
but I'm getting the discard option is not supported.
Am I missing something in my install? I've checked in /sbin and fstrim is there I just can't use it.
It's always worked before on Arch but I can't get it to work on Gentoo.

Thanks
Respectfully

Brett Stevens
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Thu Mar 03, 2016 12:19 pm    Post subject: Reply with quote

Which filesystem are you using?

Is it LUKS encrypted? With LUKS you need to explicitely --allow-discards.
Back to top
View user's profile Send private message
BWStevens
n00b
n00b


Joined: 10 Jun 2015
Posts: 61
Location: Hobart

PostPosted: Thu Mar 03, 2016 12:23 pm    Post subject: frostschutz Reply with quote

Hi there I'm just using ext4. I've got 2 partitions /dev/sda1 is 128M /boot with ext2
and /dev/sda2 is / with ext4.
I don't run a swap file as I have 32 gigs of ram..
Back to top
View user's profile Send private message
Roman_Gruber
Advocate
Advocate


Joined: 03 Oct 2006
Posts: 3846
Location: Austro Bavaria

PostPosted: Thu Mar 03, 2016 1:52 pm    Post subject: Reply with quote

check those fstab options (i use that with ssd)

or you can run trim by hand
Back to top
View user's profile Send private message
BWStevens
n00b
n00b


Joined: 10 Jun 2015
Posts: 61
Location: Hobart

PostPosted: Thu Mar 03, 2016 2:06 pm    Post subject: tw04l124 Reply with quote

Hi thanks for the reply.
My options for my root drive is noatime thats all I've got.
I tried adding defaults and discard but my computer wouldn't boot into the desktop and it mounted my drive as read only.
I've never had fstrim not work before.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Thu Mar 03, 2016 2:25 pm    Post subject: Reply with quote

Strange... it's not an USB disk, is it?

hdparm -I /dev/sda?

Example:

Code:

      *   Data Set Management TRIM supported (limit 8 blocks)
      *   Deterministic read data after TRIM


If it works on Arch or even a Live CD on the same machine, it would be a misconfiguration in the kernel although I'm not sure which kernel option would be responsible...
Back to top
View user's profile Send private message
BWStevens
n00b
n00b


Joined: 10 Jun 2015
Posts: 61
Location: Hobart

PostPosted: Thu Mar 03, 2016 2:30 pm    Post subject: frostschutz Reply with quote

Hi
No its not a usb drive. I did hdparm -I /dev/sda and this was in the list.
Data Set Management TRIM supported (limit 1 block)
So I know it supports trim. I just can't get it to work.
I might check the kernel and see if I've missed something. Other than that everything is working fine.

Thanks..
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Thu Mar 03, 2016 2:39 pm    Post subject: Reply with quote

Does blkdiscard work? Be careful, it's a very dangerous command that trims an entire device.

You could test with your boot partition. Create a backup image, blkdiscard, see if it's gone, restore the backup image.

Example:

Code:

umount /boot
dd bs=1M if=/dev/sda1 of=/boot.img
blkdiscard /dev/sda1
echo 3 > /proc/sys/vm/drop_caches
hexdump -C /dev/sda1 | head
dd bs=1M if=/boot.img of=/dev/sda1
mount /boot


Just to find out whether it already fails at the hardware level or, if it's just the filesystem itself refusing to trim for some reason.

Expected output for the hexdump in case trim succeeded and device returns zero after trim:

Code:

00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
08000000
Back to top
View user's profile Send private message
BWStevens
n00b
n00b


Joined: 10 Jun 2015
Posts: 61
Location: Hobart

PostPosted: Thu Mar 03, 2016 3:05 pm    Post subject: frostschutz Reply with quote

Here is my hexdump mate.
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
02000400 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
02000420 03 00 00 00 00 00 ff 01 00 00 00 00 00 00 00 00 |................|
02000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
02000460 fc ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
02000470 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Thu Mar 03, 2016 5:46 pm    Post subject: Reply with quote

While that doesn't look like it's been completely zeroed, it does not look like a filesystem either.

So I take it the blkdiscard command did not yield an error message?

Strange.

Maybe it's something silly like / being mounted read-only? I'm really running out of ideas here. If you ever find out what caused this problem, let us know...
Back to top
View user's profile Send private message
Petross404
n00b
n00b


Joined: 27 Sep 2016
Posts: 55

PostPosted: Mon Jun 18, 2018 7:51 pm    Post subject: Re: No Fstrim Reply with quote

BWStevens wrote:
Hi community,

I've got a 250gig Kingston SSD. I don't enable discard in my fstab as I like to just do a fstrim -v /
but I'm getting the discard option is not supported.
Am I missing something in my install? I've checked in /sbin and fstrim is there I just can't use it.
It's always worked before on Arch but I can't get it to work on Gentoo.

Thanks
Respectfully

Brett Stevens


I get that this thread is old, but someone might find it usefull in the future. I used to get errors when I tried to fstrim my SSD but this article saved my day.

Quote:
How to active TRIM on Linux? The first thing to know is that TRIM should be enabled on all I/O abstraction layers. This means that if you have an ext4 partition on top of LVM, which in turn is on top of an encrypted volume with LUKS/dm-crypt, then you must enable support for TRIM in these three layers: The filesystem, LVM and dm-crypt. There is no point in enabling it at the filesystem level if you don’t enable it also on the other layers. The TRIM command should be translated from one layer to another until reaching the SSD.


1. Enabling TRIM support on dm-crypt

Simply add the option discard inside our crypttab:
Code:

#/etc/crypttab
# <target name>    <source device>    <key file>       <options>
sda2_crypt         /dev/sda2          none             luks,discard


In case we are talking about the rootfs, then add this and update grub configuration before reboot:
Code:

#/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="root_trim=yes"


2.So far so good, we have enabled trim support for the LUKS container. Let's move on to the LVM:

We have to enable the option issue_discards in the LVM configuration.
Code:

# /etc/lvm/lvm.conf
# [...]
devices {
   # [...]
   issue_discards = 1
   # [...]
}
# [...]


3. Finally, the most the most interesting part is the filesystem. Most people simply add the option “discard” in the mounting options at /etc/fstab. However, this means that every time you delete a file, the OS will be reporting in real-time to the SSD which blocks were occupied by that file and are not longer in use, and then the SSD will have to perform a defragmentation and deletion of those internal blocks, operation which will take an amount of time higher than desired.

Instead of putting an unnecessary extra amount of work over the SSD, one can run periodically a script with fstrim.

Other advantages of the fstrim way are:

* If you didn’t enabled correctly the TRIM support in the above layers of your setup, you will receive an error when executing fstrim. On the other hand, if you were using the discard option at fstab you wouldn’t have received any error and you would end thinking that you managed to get TRIM working properly when you didn’t.
* If you delete a file by mistake (you know it happens), you can recover it before anacron runs your script fstrim. On the other hand, if you were using the discard-at-fstab option you wouldn’t have any chance of recovering the file, because the OS would have told the SSD to TRIM that blocks as soon as you deleted the file, and consequently the SSD has irreversibly destroyed such blocks.

Here you have simple script to run fstrim on the /, /boot and /home partitions, which can be programmed to be executed periodically by anacron :
Code:

#/etc/cron.weekly/dofstrim
#! /bin/sh
for mount in / /boot /home; do
   fstrim $mount
done


Hope this will help someone.
http://blog.neutrino.es/2013/howto-properly-activate-trim-for-your-ssd-on-linux-fstrim-lvm-and-dmcrypt/
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