]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dmsquash: Add rd.live.overlay.thin
authorFabian Deutsch <fabiand@fedoraproject.org>
Wed, 18 Feb 2015 13:31:40 +0000 (14:31 +0100)
committerHarald Hoyer <harald@redhat.com>
Thu, 2 Jul 2015 17:47:46 +0000 (19:47 +0200)
This option changes the underlying mechanism for the overlay in the
dmsquash module.
Instead of a plain dm snapshot a dm thin snapshot is used. The advantage
of the thin snapshot is, that the TRIM command is recognized, which
means that at runtime, only the occupied blocks will be claimed from
memory, and freed blocks will really be freed in ram.

Signed-off-by: Fabian Deutsch <fabiand@fedoraproject.org>
(cherry picked from commit d6e34d362a05cda61baaf8e231ad3f0e8665a9cc)

dracut.cmdline.7.asc
modules.d/90dmsquash-live/dmsquash-live-root.sh

index 0493dcd8c5997405099f5531a66fe647e84eee43..0c3bc29576ac02cf9cbdffc0f23b6e41e2aea363 100644 (file)
@@ -802,6 +802,13 @@ Enables debug output from the live boot process.
 Specifies the directory within the squashfs where the ext3fs.img or rootfs.img
 can be found.  By default, this is __LiveOS__.
 
+**rd.live.overlay.thin=**1::
+Enables the usage of thin snapshots instead of classic dm snapshots.
+The advantage of thin snapshots is, that they support discards, and will free
+blocks which are not claimed by the filesystem. In this use case this means,
+that memory is given back to the kernel, when the filesystem does not claim it
+anymore.
+
 **rd.writable.fsimg=**1::
 Enables writable filesystem support.  The system will boot with a fully 
 writable filesystem without snapshots __(see notes above about available live boot options)__.
index c6c02c742f6ba02b3a78aae2670f2b965da340bb..0645a0bdc514404f1d38626e0601f28c1e3aca55 100755 (executable)
@@ -30,6 +30,8 @@ getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay
 overlay=$(getarg rd.live.overlay -d overlay)
 getargbool 0 rd.writable.fsimg -d -y writable_fsimg && writable_fsimg="yes"
 
+getargbool 0 rd.live.overlay.thin && thin_snapshot="yes"
+
 # CD/DVD media check
 [ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev)
 if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then
@@ -146,7 +148,30 @@ do_live_overlay() {
         base=$BASE_LOOPDEV
         over=$OVERLAY_LOOPDEV
     fi
-    echo 0 $sz snapshot $base $over p 8 | dmsetup create live-rw
+    if [ -n "$thin_snapshot" ]; then
+        modprobe dm_thin_pool
+        mkdir /run/initramfs/thin-overlay
+
+        # In block units (512b)
+        thin_data_sz=$(( $overlay_size * 1024 * 1024 / 512 ))
+        thin_meta_sz=$(( $thin_data_sz / 10 ))
+
+        # It is important to have the backing file on a tmpfs
+        # this is needed to let the loopdevice support TRIM
+        dd if=/dev/null of=/run/initramfs/thin-overlay/meta bs=1b count=1 seek=$((thin_meta_sz)) 2> /dev/null
+        dd if=/dev/null of=/run/initramfs/thin-overlay/data bs=1b count=1 seek=$((thin_data_sz)) 2> /dev/null
+
+        THIN_META_LOOPDEV=$( losetup --show -f /run/initramfs/thin-overlay/meta )
+        THIN_DATA_LOOPDEV=$( losetup --show -f /run/initramfs/thin-overlay/data )
+
+        echo 0 $thin_data_sz thin-pool $THIN_META_LOOPDEV $THIN_DATA_LOOPDEV 1024 1024 | dmsetup create live-overlay-pool
+        dmsetup message /dev/mapper/live-overlay-pool 0 "create_thin 0"
+
+        # Create a snapshot of the base image
+        echo 0 $sz thin /dev/mapper/live-overlay-pool 0 $base | dmsetup create live-rw
+    else
+        echo 0 $sz snapshot $base $over p 8 | dmsetup create live-rw
+    fi
 
     # Create a device that always points to a ro base image
     echo 0 $sz linear $base 0 | dmsetup create --readonly live-base