From 099ad2ce7c48e39f960dc2160efe9b1bf11d7ca6 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sun, 24 Oct 2021 15:17:43 -0400 Subject: [PATCH] fs: add some performance metrics for TREE_SEARCH_V2 calls These give some visibility into how efficiently bees is using the TREE_SEARCH_V2 ioctl. Signed-off-by: Zygo Blaxell --- include/crucible/fs.h | 4 ++++ lib/fs.cc | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/include/crucible/fs.h b/include/crucible/fs.h index 6d1780b..da624e5 100644 --- a/include/crucible/fs.h +++ b/include/crucible/fs.h @@ -197,6 +197,10 @@ namespace crucible { size_t m_buf_size; set m_result; + + static thread_local size_t s_calls; + static thread_local size_t s_loops; + static thread_local size_t s_loops_empty; }; ostream & operator<<(ostream &os, const btrfs_ioctl_search_key &key); diff --git a/lib/fs.cc b/lib/fs.cc index e75a920..dc9a2eb 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -754,6 +754,10 @@ namespace crucible { return offset + len; } + thread_local size_t BtrfsIoctlSearchKey::s_calls = 0; + thread_local size_t BtrfsIoctlSearchKey::s_loops = 0; + thread_local size_t BtrfsIoctlSearchKey::s_loops_empty = 0; + bool BtrfsIoctlSearchKey::do_ioctl_nothrow(int fd) { @@ -774,6 +778,7 @@ namespace crucible { ioctl_ptr->buf_size = buf_size; // Don't bother supporting V1. Kernels that old have other problems. int rv = ioctl(fd, BTRFS_IOC_TREE_SEARCH_V2, ioctl_arg.data()); + ++s_calls; if (rv != 0 && errno == ENOENT) { // If we are searching a tree that is deleted or no longer exists, just return an empty list nr_items = 0; @@ -800,6 +805,10 @@ namespace crucible { buf_size *= 2; } // don't automatically raise the buf size higher than 64K, the largest possible btrfs item + ++s_loops; + if (ioctl_ptr->key.nr_items == 0) { + ++s_loops_empty; + } } while (buf_size < 65536); // ioctl changes nr_items, this has to be copied back