From 83e1167e1a350bd08ac6245f47a5877438408492 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 26 Jul 2021 17:39:23 +0100 Subject: [PATCH] cache, cow: Use a 64K block size by default Based on the results presented in the previous commit, use a 64K block size by default in both the cache and cow filters. For the cache filter you could go back to a 4K block size if you wanted by using the cache-min-block-size=4K parameter. For cow it is compiled in so cannot be adjusted. (cherry picked from commit c1905b0a28677d961babdb16d6f30ae61042c825) --- filters/cache/cache.c | 2 +- filters/cache/nbdkit-cache-filter.pod | 4 ++-- filters/cow/blk.h | 2 +- tests/test-cache-block-size.sh | 2 +- tests/test-cow-extents1.sh | 33 +++++++++++++++------------ 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/filters/cache/cache.c b/filters/cache/cache.c index 109ac89e..c912c5fb 100644 --- a/filters/cache/cache.c +++ b/filters/cache/cache.c @@ -73,7 +73,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; unsigned blksize; /* actual block size (picked by blk.c) */ -unsigned min_block_size = 4096; +unsigned min_block_size = 65536; enum cache_mode cache_mode = CACHE_MODE_WRITEBACK; int64_t max_size = -1; unsigned hi_thresh = 95, lo_thresh = 80; diff --git a/filters/cache/nbdkit-cache-filter.pod b/filters/cache/nbdkit-cache-filter.pod index 6cbd1c08..df9c1f99 100644 --- a/filters/cache/nbdkit-cache-filter.pod +++ b/filters/cache/nbdkit-cache-filter.pod @@ -65,8 +65,8 @@ or can cheaply reconstruct. Set the minimum block size used by the cache. This must be a power of 2 and E 4096. -The default is 4096, or the block size of the filesystem which -contains the temporary file storing the cache (whichever is larger). +The default is 64K, or the block size of the filesystem which contains +the temporary file storing the cache (whichever is larger). =item BSIZE diff --git a/filters/cow/blk.h b/filters/cow/blk.h index b066c602..1bc85283 100644 --- a/filters/cow/blk.h +++ b/filters/cow/blk.h @@ -36,7 +36,7 @@ /* Size of a block in the overlay. A 4K block size means that we need * 64 MB of memory to store the bitmap for a 1 TB underlying image. */ -#define BLKSIZE 4096 +#define BLKSIZE 65536 /* Initialize the overlay and bitmap. */ extern int blk_init (void); diff --git a/tests/test-cache-block-size.sh b/tests/test-cache-block-size.sh index a2a27407..d20cc940 100755 --- a/tests/test-cache-block-size.sh +++ b/tests/test-cache-block-size.sh @@ -47,7 +47,7 @@ truncate -s 128K cache-block-size.img # Run nbdkit with the caching filter. start_nbdkit -P cache-block-size.pid -U $sock --filter=cache \ - file cache-block-size.img cache-min-block-size=64K + file cache-block-size.img cache-min-block-size=4K nbdsh --connect "nbd+unix://?socket=$sock" \ -c ' diff --git a/tests/test-cow-extents1.sh b/tests/test-cow-extents1.sh index 8e0e0383..ebfd83f6 100755 --- a/tests/test-cow-extents1.sh +++ b/tests/test-cow-extents1.sh @@ -65,7 +65,7 @@ cleanup_fn rm -f $files # Create a base file which is half allocated, half sparse. dd if=/dev/urandom of=$base count=128 bs=1K -truncate -s 256K $base +truncate -s 4M $base lastmod="$(stat -c "%y" $base)" # Run nbdkit with a COW overlay. @@ -76,30 +76,33 @@ uri="nbd+unix:///?socket=$sock" nbdinfo --map "$uri" > $out cat $out if [ "$(tr -s ' ' < $out | cut -d' ' -f 1-4)" != " 0 131072 0 - 131072 131072 3" ]; then + 131072 4063232 3" ]; then echo "$0: unexpected initial file map" exit 1 fi # Punch some holes. nbdsh -u "$uri" \ - -c 'h.trim(4096, 4096)' \ - -c 'h.trim(4098, 16383)' \ - -c 'h.pwrite(b"1"*4096, 65536)' \ - -c 'h.trim(8192, 131072)' \ - -c 'h.pwrite(b"2"*8192, 196608)' + -c 'bs = 65536' \ + -c 'h.trim(bs, bs)' \ + -c 'h.trim(bs+2, 4*bs-1)' \ + -c 'h.pwrite(b"1"*bs, 16*bs)' \ + -c 'h.trim(2*bs, 32*bs)' \ + -c 'h.pwrite(b"2"*(2*bs), 48*bs)' # The extents map should be fully allocated. nbdinfo --map "$uri" > $out cat $out -if [ "$(tr -s ' ' < $out | cut -d' ' -f 1-4)" != " 0 4096 0 - 4096 4096 3 - 8192 8192 0 - 16384 4096 3 - 20480 110592 0 - 131072 65536 3 - 196608 8192 0 - 204800 57344 3" ]; then +if [ "$(tr -s ' ' < $out | cut -d' ' -f 1-4)" != " 0 65536 0 + 65536 131072 3 + 196608 65536 0 + 262144 65536 3 + 327680 65536 0 + 393216 655360 3 + 1048576 65536 0 + 1114112 2031616 3 + 3145728 131072 0 + 3276800 917504 3" ]; then echo "$0: unexpected trimmed file map" exit 1 fi -- 2.31.1