tag 732054 patch
User: [email protected]
Usertags: origin-ubuntu ubuntu-patch trusty

Martin Pitt [2013-12-13 11:11 +0100]:
> I propose to add a cron.d job to util-linux by default which regularly
> trims SSD partitions if they support it and don't already have the
> "discard" mount option set.

That's the debdiff I uploaded to Ubuntu for this.

Martin
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
diff -u util-linux-2.20.1/debian/changelog util-linux-2.20.1/debian/changelog
--- util-linux-2.20.1/debian/changelog
+++ util-linux-2.20.1/debian/changelog
@@ -1,3 +1,18 @@
+util-linux (2.20.1-5.1ubuntu11) trusty; urgency=medium
+
+  * Regularly trim SSDs automatically:
+    - Add debian/fstrim-all: Script to detect which mounted partitions
+      need/support trimming, and call fstrim(8) on all of them. Installed into
+      /usr/sbin/.
+    - Add debian/fstrim-all.8: Manpage for the above.
+    - Add debian/fstrim-all.cron: Trivial shell script to call fstrim-all,
+      so that admins can easily adjust/disable it. Installed as
+      /etc/cron.weekly/fstrim.
+    - See https://blueprints.launchpad.net/ubuntu/+spec/core-1311-ssd-trimming
+    - Closes: #732054
+
+ -- Martin Pitt <[email protected]>  Mon, 16 Dec 2013 08:59:40 +0100
+
 util-linux (2.20.1-5.1ubuntu10) trusty; urgency=low
 
   * Fix memory leak on configure.ac for autopoint. Closes: #724255.
diff -u util-linux-2.20.1/debian/rules util-linux-2.20.1/debian/rules
--- util-linux-2.20.1/debian/rules
+++ util-linux-2.20.1/debian/rules
@@ -179,6 +179,12 @@
        cd debian/util-linux/sbin ; mv mkswap mkswap.linux
        cd debian/util-linux/usr/share/man/man8 ; mv mkswap.8 mkswap.linux.8
 endif
+       # automatically trim SSD drives
+       if [ -f debian/util-linux/sbin/fstrim ] ; then \
+           install -m 755 debian/fstrim-all debian/util-linux/sbin; \
+           install -m 644 debian/fstrim-all.8 
debian/util-linux/usr/share/man/man8; \
+           install -D -m 755 debian/fstrim-all.cron 
debian/util-linux/etc/cron.weekly/fstrim; \
+       fi
        dh_compress -i -s
        dh_fixperms -i -s -Xusr/bin/wall -Xbin/mount -Xbin/umount
        rm -rf debian/*-udeb/usr/share/doc
only in patch2:
unchanged:
--- util-linux-2.20.1.orig/debian/fstrim-all
+++ util-linux-2.20.1/debian/fstrim-all
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Call fstrim on mounted partitions to maintain write performance.
+# This is only relevant for SSD drives, see
+# http://wiki.ubuntuusers.de/SSD/TRIM
+set -e
+
+# needs /proc
+[ -r /proc/mounts ] || exit 0
+
+# these file systems support trimming
+SUPPORTED_FS="ext3 ext4 xfs btrfs"
+
+# arguments: <haystack> <needle>
+contains() {
+    [ "${1#*$2}" != "$1" ]
+}
+
+DONE=''
+while read DEV MOUNT FSTYPE OPTIONS REST; do
+    # only consider /dev/*
+    [ "${DEV#/dev}" != "$DEV" ] || continue
+    # ignore mounts with "discard", they TRIM already
+    if contains "$OPTIONS" discard; then continue; fi
+    # only consider supported file systems
+    if ! contains "$SUPPORTED_FS" "$FSTYPE"; then continue; fi
+
+    # did we see this already? we need to resolve symlinks
+    # for/dev/disks/by-{label,uuid}, etc.
+    REALDEV=`readlink -f $DEV`
+    if contains "$DONE" " $REALDEV "; then continue; fi
+    DONE="$DONE $REALDEV "
+
+    #echo "device $DEV real $REALDEV mountpoint $MOUNT fstype $FSTYPE"
+
+    # check if that device supports trim; this does not work for devmapper,
+    # though, so just call fstrim on those without the extra check and ignore
+    # errors; for cryptsetup and LVM you also need extra configuration options
+    # to propagate discards, which the admin might have turned off
+    unset SILENT_FAILURE
+    if [ "${REALDEV#/dev/dm-}" != "$REALDEV" ]; then
+        #echo "device $DEV is on devmapper, skipping TRIM feature check"
+        SILENT_FAILURE=1
+    else
+        if ! contains "`hdparm -I $REALDEV`" "TRIM"; then
+            #echo "device $DEV does not support trimming"
+            continue
+        fi
+    fi
+
+    if [ -n "$SILENT_FAILURE" ]; then
+        fstrim $MOUNT 2>/dev/null || true
+    else
+        fstrim $MOUNT
+    fi
+done < /proc/mounts
only in patch2:
unchanged:
--- util-linux-2.20.1.orig/debian/fstrim-all.8
+++ util-linux-2.20.1/debian/fstrim-all.8
@@ -0,0 +1,24 @@
+.TH fstrim-all 8 "Dec 2013" "" "Debian Administrator's Manual"
+
+.SH NAME
+fstrim-all \- call fstrim on all mounted file systems which support it
+
+.SH DESCRIPTION
+
+SSD drives need to be TRIMed, i. e. they need to be told which blocks the OS
+considers as "unused" (i. e. from deleted files). Withouth this, the write
+speed on SSDs becomes slower over time.
+
+.B fstrim\-all
+detects which mounted partitions belong to drives that need/support trimming,
+and calls
+.BR fstrim (1)
+on them.
+
+It is meant to be called from cron. There is no output on success.
+
+.SH AUTHOR
+Martin Pitt <[email protected]>
+
+.SH SEE ALSO
+.BR fstrim (8)
only in patch2:
unchanged:
--- util-linux-2.20.1.orig/debian/fstrim-all.cron
+++ util-linux-2.20.1/debian/fstrim-all.cron
@@ -0,0 +1,4 @@
+#!/bin/sh
+# call fstrim-all to trim all mounted file systems which support it
+set -e
+exec fstrim-all

Attachment: signature.asc
Description: Digital signature

Reply via email to