From 827b7b903abc07d5fb04591bbae5587e6dc44993 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 12 Aug 2015 12:51:39 -0400 Subject: swap: create swap with fallocate if possible fallocate is much faster than 'dd' for creating and initializing a swap file. LP: #1482994 --- cloudinit/config/cc_mounts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cloudinit') diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py index 73b42f91..47b63dfc 100644 --- a/cloudinit/config/cc_mounts.py +++ b/cloudinit/config/cc_mounts.py @@ -206,7 +206,8 @@ def setup_swapfile(fname, size=None, maxsize=None): util.log_time(LOG.debug, msg, func=util.subp, args=[['sh', '-c', ('rm -f "$1" && umask 0066 && ' - 'dd if=/dev/zero "of=$1" bs=1M "count=$2" && ' + '{ fallocate -l "${2}M" "$1" || ' + ' dd if=/dev/zero "of=$1" bs=1M "count=$2"; } && ' 'mkswap "$1" || { r=$?; rm -f "$1"; exit $r; }'), 'setup_swap', fname, mbsize]]) -- cgit v1.2.3