From 57dd4029c8b5dfdf7cc8a88be27a316aec79127d Mon Sep 17 00:00:00 2001 From: David Scott Date: Fri, 22 Nov 2019 20:31:27 +0000 Subject: [PATCH] swap: speed up preferring a 1MiB blocksize If the swap disk is larger than 1MiB, then use a 1MiB blocksize in `dd` On my machine using a large block size speeds up swap file creation: ``` / # time dd if=/dev/zero of=output bs=1024 count=1048576 1048576+0 records in 1048576+0 records out real 0m 4.61s user 0m 0.79s sys 0m 3.77s / # time dd if=/dev/zero of=output bs=1048576 count=1024 1024+0 records in 1024+0 records out real 0m 1.06s user 0m 0.00s sys 0m 1.04s ``` Signed-off-by: David Scott --- pkg/swap/swap.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/swap/swap.sh b/pkg/swap/swap.sh index fe8718469..1bf9dc458 100755 --- a/pkg/swap/swap.sh +++ b/pkg/swap/swap.sh @@ -123,7 +123,12 @@ fi if [ ! -f $path ] || ! [ $(stat -c "%s" $path) == $(disksize_to_count 1 $size) ]; then ## Allocate the file - dd if=/dev/zero of=$path bs=1024 count=$(disksize_to_count 1024 $size) + ## If possible use a large blocksize: + bs=1048576 # 1 MiB + if [ "$size" -lt "$bs" ]; then + bs=1024 # fall back to 1KiB + fi + dd if=/dev/zero of=$path bs=$bs count=$(disksize_to_count $bs $size) chmod 0600 $path ## was it encrypted? use cryptsetup and get the mapped device