文書更新:2017年11月23日(木) 午後6時11分45秒

Home > 備忘録(Fedora) > TRIM を有効にする( 113 )

HDDをSDDに換装しようとして、trimについてしらべてみた。
(Solid State Drives (日本語) - ArchWiki) を参考にしました。

LVM で TRIM を有効にする

LVMというディスク管理機能を利用している場合のみ issue_discards オプションを有効にする
  1. issue_discards オプションを有効にする
  2. # vi /etc/lvm/lvm.conf
        # Issue discards to a logical volumes's underlying physical volume(s) when
        # the logical volume is no longer using the physical volumes' space (e.g.
        # lvremove, lvreduce, etc).  Discards inform the storage that a region is
        # no longer in use.  Storage that supports discards advertise the protocol
        # specific way discards should be issued by the kernel (TRIM, UNMAP, or
        # WRITE SAME with UNMAP bit set).  Not all storage will support or benefit
        # from discards but SSDs and thinly provisioned LUNs generally do.  If set
        # to 1, discards will only be issued if both the storage and kernel provide
        # support.
        # 1 enables; 0 disables.
        issue_discards = 1	←issue_discards = 0 から変更する
    }
  3. 再起動する

fstab で TRIM を有効にする

  1. discard を追加する
  2. # vi /etc/fstab
    /dev/mapper/fedora-root /                       ext4    discard        1 1
    UUID=56e80021-d5c3-3b12-aab2-6d5831877511 /boot ext4    discard        1 2
    /dev/mapper/fedora-home /home                   ext4    defaults        1 2
    /dev/mapper/fedora-swap swap                    swap    defaults        0 0
  3. swap 領域への書き込みを減らす
  4. # vi /etc/sysctl.conf
    vm.swappiness=1
    vm.vfs_cache_pressure=50
  5. 再起動する

cron で TRIM を適用する

  1. scriptを作成
  2. # vi /etc/cron.daily/trim.sh
    #!/bin/sh
    LOG=/var/log/trim.log
    echo "*** $(date) ***" >> $LOG
    fstrim -v / >> $LOG
  3. scriptに実行権限を与える
  4. # chmod +x /etc/cron.daily/trim.sh