How should I configure TRIM Support for LVM logical volumes?

10,731

Solution 1

For googlers - the issue_discards option is not needed for getting TRIM working when we speak about deleting files. The only effect is has is when you actually modify your LVM (e.g. shrinking or removing logical volumes). But regular users usually do not do this at all.

This setting is recommended for those who are for example provisioning virtual machines on LVM volume groups and delete them often. Otherwise you do not need that. For more info go to lvm.conf man page. This is from RHEL 6.2 LVM Administration Guide:

The Red Hat Enterprise Linux 6.2 release supports the issue_discards parameter in the lvm.conf configuration file. When this parameter is set, LVM will issue discards to a logical volume's underlying physical volumes when the logical volume is no longer using the space on the physical volumes. For information on this parameter, refer to the inline documentation for the /etc/lvm/lvm.conf file, which is also documented in Appendix B, The LVM Configuration Files.

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/LVM_overview.html

I wrote a blog about this: http://lukas.zapletalovi.com/2013/11/how-to-trim-your-ssd-in-fedora-19.html

Solution 2

I backported LVM 2.02.95 to Ubuntu 12.04 and put it in a ppa. To use it, issue the following commands:

sudo apt-add-repository ppa:kalakris/lvm
sudo apt-get update
sudo apt-get install lvm2

After this upgrade, the issue_discards command in /etc/lvm/lvm.conf will be recognized as expected.

Solution 3

The option issue_discards is currently not supported on the version of LVM shipped with 12.04.

From the LVM Changelog:

Version 2.02.85 - 29th April 2011

Add new obtain_device_list_from_udev setting to lvm.conf.
Obtain device list from udev by default if LVM2 is compiled with udev support.
Add test for vgimportclone and querying of vgnames with duplicate pvs.
Avoid use of released memory when duplicate PV is found.
Add "devices/issue_discards" to lvm.conf.
...

In 12.04 the LVM version is 2.02.66 (12.10 comes with 2.02.95).

To set this option already now makes no harm, because it is silently ignored.
See Red Hat Bugzilla 820203

Share:
10,731

Related videos on Youtube

Zack Perry
Author by

Zack Perry

Updated on September 18, 2022

Comments

  • Zack Perry
    Zack Perry over 1 year

    I am setting up a notebook for software demo purpose. The machine has a Intel Core i7 CPU, 8GB RAM, a 128GB SSD, and runs Ubuntu 12.04 LTS 64bit desktop. As it is, the SSD is configured to have a single volume group, with /boot, /swap, and / all in their respective logical volume. They collectively consume 30GB space. I plan to use the remaining for logical volumes for KVM guests, all run Ubuntu 12.04 Server

    I would like to ensure that the SSD is utilized optimally. Although on this site, there are some great info about setting up TRIM support for file system setups that do not involve LVM, I have not found explicit guide regarding my planned setup.

    I did found this page which talks about adding issue_discards in /etc/lvm/lvm.conf. But in said file on my machine, I didn't find the cited content. I double-checked man lvm.conf(5), didn't see any mentioning of this option either.

    Thus, I'm not sure what to do. Furthermore, even say adding the option is the right thing to do, should I in my machine's /etc/fstab still add mount options such as noatime etc?

    Any tips, pointers, and/or further guidance are greatly appreciated.

    • lzap
      lzap over 10 years
      If you do not plan to modify your LVM configuration everyday (and this is expected), you do NOT need to set this at all. See my answer.
  • Zack Perry
    Zack Perry over 11 years
    Thanks for the info! Does it mean that with 12.04 LTS, and how I plan setup these KVM guests (each in a separate logical volume), I don't have a way to optimize the usages of the SSD? --Zack
  • gertvdijk
    gertvdijk over 11 years
    However, these 'discards' will only trigger on remove or reduce operations on LVs. Discards on the filesystem on top of a LV will not propagate! From the same LVM changelog: "Issue discards on lvremove and lvreduce etc. if enabled and supported."
  • Zack Perry
    Zack Perry over 11 years
    Thanks again for chipping in with more info. It seems to me that given what we have collectively seen so far, there is no good way for me to configure my KVM setup to use the computer's SSD with TRIM :-( At this stage, it seems to me that we either forget about LVM, use image based KVM guests, and be able to use TRIM, or use LVM (perhaps nested), and forget about "trimming" the SSD. Oh, well!
  • Rob H
    Rob H over 10 years
    Thank you for this! Installed it and nothing broke, which is always a good thing. :-) Is there a way to tell that discards are working?
  • MountainX
    MountainX about 8 years
    upvoted - exactly the explanation I needed. Thanks