From 9f2b747ffaa1d9e39e60238ceb56b3771532c933 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 1 Jun 2020 11:13:51 +0100 Subject: [PATCH] [thin_metadata_pack] Prefetch blocks. Doubles performance --- thin-provisioning/thin_metadata_pack.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/thin-provisioning/thin_metadata_pack.cc b/thin-provisioning/thin_metadata_pack.cc index f933cf3..91ed124 100644 --- a/thin-provisioning/thin_metadata_pack.cc +++ b/thin-provisioning/thin_metadata_pack.cc @@ -42,6 +42,7 @@ namespace { using namespace std; constexpr uint64_t MAGIC = 0xa537a0aa6309ef77; constexpr uint64_t PACK_VERSION = 1; + constexpr uint64_t PREFETCH_COUNT = 1024; uint32_t const SUPERBLOCK_CSUM_SEED = 160774; uint32_t const BITMAP_CSUM_XOR = 240779; @@ -132,6 +133,10 @@ namespace { write_u64(out, block_size); write_u64(out, nr_blocks); + // prefetch + for (block_address b = 0; b < PREFETCH_COUNT; b++) + bm->prefetch(b); + is_metadata_functor is_metadata; for (block_address b = 0; b < nr_blocks; b++) { auto rr = bm->read_lock(b); @@ -140,6 +145,10 @@ namespace { write_u64(out, b); out.write(reinterpret_cast(rr.data()), block_size); } + + auto prefetch_b = b + PREFETCH_COUNT; + if (prefetch_b < nr_blocks) + bm->prefetch(prefetch_b); } return 0;