Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Using genkernel parameters to enable TRIM on SSD and LUKS
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
paradigm-X
Apprentice
Apprentice


Joined: 19 Sep 2013
Posts: 168

PostPosted: Sat Dec 21, 2013 6:31 am    Post subject: Using genkernel parameters to enable TRIM on SSD and LUKS Reply with quote

I have been doing some research related to maximizing the longevity and performance of SSD drives because I am making use of one of these disks on a system running Gentoo. I have more than one disk on this system, but only one of these is an SSD. I found that one big factor of considerable interest and discussion has to do with the element of disk writes called TRIM, which apparently can be affected by setting certain parameters during boot and by setting specific options in configuration files. One of the elements that complicated my research, or should I say made it more interesting, is caused by the fact that this same SSD drive in question has LUKS encryption on all but the boot partition. Aside from this factor, there is nothing especially complicated about its partitioning.

I am no expert on all the technicalities of TRIM, but I would like to understand enough about it to do what I can reasonably to prolong the disk by following some best practices nonetheless. Unfortunately, this seems to be easier said than done, much easier, because there is a LOT of differing, and sometimes contentious, ideas about this subject matter and various opinions about how to deal with it properly. In the course of my research, chasing down leads, trying out different search terms and whatnot, among the many places I found and the discussions I read, I came across a good explanation of the topic here: http://blog.neutrino.es/2013/howto-properly-activate-trim-for-your-ssd-on-linux-fstrim-lvm-and-dmcrypt/ .

Apparently, SSD drives, fast though they may be, have a price to pay for it in that they need to make additional work deleting unwanted data no longer of use. I learned that one of the options available to utilize TRIM on a Linux OS would be to enable a parameter in fstab called "discard". However, doing this would cause the kernel to make writes to the file system continually to clear away (i.e., discard) the extraneous data so that useful space can be recovered sooner, but this kind of continual activity is bad for the SSD, among other reasons, mainly due to excessive wear and tear incurred. Rather, there is a program called 'fstrim' available for this same purpose, but which can be run periodically instead of continually. It is easier and more efficient apparently, that is to say, measurably better.

Although the program fstrim addresses the problem on the regular file system level, in order to be effective when dm-crypt is in use, there also needs to be enabled an element of TRIM on the encrypted layer of the data so that the benefit can get passed on to the underlying block device. This component is documented in dm-crypt manuals, and it is specified as a parameter called "allow-discards".

Now then, according to the discussion here,

http://askubuntu.com/questions/243518/what-exactly-do-the-allow-discards-and-root-trim-linux-parameters-do

in order to get Gentoo's genkernel to enable the functionality and pass it on to the operating system, i.e., the kernel, there would appear to be some sort of parameter to use with genkernel called "root_trim=yes". The support for this point appears to be referenced in the aforesaid website, to which I just gave the link, in which it clearly pointed out in the code for genkernel relating to the dm-crypt layer that TRIM should be enabled if given the parameter "root_trim=yes". Specifically, the reference to genkernel code was linked here:

http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=blob;f=defaults/initrd.scripts;h=03e61e0955dcd32f18bccbf6d0352a011c817d0c;hb=e779547b728506a933809e4b03c4ed6b329f8e08#l840

And, I could see in the code this relevant part in particular:


839 # Handle keys
840 if [ "x${LUKS_TRIM}" = "xyes" ]
841 then
842 good_msg "Enabling TRIM support for ${LUKS_NAME}." ${CRYPT_SILENT}
843 cryptsetup_options="${cryptsetup_options} --allow-discards"
844 fi
845

At this point, the problem I have is, where or when am I supposed to give this parameter to genkernel so that it will then enable TRIM on the underlying dm-crypt LUKS aspects of the file system? I have not found where this can be done with genkernel, and I would welcome any information in that regard. As it is, when I tried to make use of TRIM with the fstrim program like so:

fstrim -v /

I end up getting an error message:

"fstrim: /: FITRIM ioctl failed: Operation not supported".
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