From 7782b79e4bde7238ef4a4a1c9dc403c795a1531d Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 13 Dec 2016 21:29:41 -0500 Subject: [PATCH] crucible: reduce buffer size and CPU overhead for BtrfsIoctlSearchKey We really do need some large buffers for BtrfsIoctlSearchKey in some cases, but we don't need to zero them out first. Don't do that so we save some CPU. Reduce the default buffer size to 4K because most BISK users don't get need much more than 1K. Set the buffer size explicitly to the product of the number of items and the desired item size in the places that really need a lot of items. --- include/crucible/fs.h | 2 +- lib/extentwalker.cc | 2 +- lib/fs.cc | 4 +++- src/bees-roots.cc | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/crucible/fs.h b/include/crucible/fs.h index 73defe4..c0bfef5 100644 --- a/include/crucible/fs.h +++ b/include/crucible/fs.h @@ -156,7 +156,7 @@ namespace crucible { ostream & operator<<(ostream &os, const BtrfsIoctlSearchHeader &hdr); struct BtrfsIoctlSearchKey : public btrfs_ioctl_search_key { - BtrfsIoctlSearchKey(size_t buf_size = 16 * 1024); + BtrfsIoctlSearchKey(size_t buf_size = 4096); virtual bool do_ioctl_nothrow(int fd); virtual void do_ioctl(int fd); diff --git a/lib/extentwalker.cc b/lib/extentwalker.cc index dd7dacd..999f097 100644 --- a/lib/extentwalker.cc +++ b/lib/extentwalker.cc @@ -468,7 +468,7 @@ namespace crucible { BtrfsExtentWalker::Vec BtrfsExtentWalker::get_extent_map(off_t pos) { - BtrfsIoctlSearchKey sk; + BtrfsIoctlSearchKey sk(sc_extent_fetch_max * (sizeof(btrfs_file_extent_item) + sizeof(btrfs_ioctl_search_header))); if (!m_root_fd) { m_root_fd = m_fd; } diff --git a/lib/fs.cc b/lib/fs.cc index 7078fe3..16e5649 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -711,7 +711,9 @@ namespace crucible { BtrfsIoctlSearchKey::do_ioctl_nothrow(int fd) { vector ioctl_arg = vector_copy_struct(this); - ioctl_arg.resize(sizeof(btrfs_ioctl_search_args_v2) + m_buf_size, 0); + // Normally we like to be paranoid and fill empty bytes with zero, + // but these buffers can be huge. 80% of a 4GHz CPU huge. + ioctl_arg.resize(sizeof(btrfs_ioctl_search_args_v2) + m_buf_size); btrfs_ioctl_search_args_v2 *ioctl_ptr = reinterpret_cast(ioctl_arg.data()); ioctl_ptr->buf_size = m_buf_size; diff --git a/src/bees-roots.cc b/src/bees-roots.cc index 251374c..4bb19eb 100644 --- a/src/bees-roots.cc +++ b/src/bees-roots.cc @@ -644,7 +644,7 @@ BeesCrawl::fetch_extents() Timer crawl_timer; - BtrfsIoctlSearchKey sk; + BtrfsIoctlSearchKey sk(BEES_MAX_CRAWL_SIZE * (sizeof(btrfs_file_extent_item) + sizeof(btrfs_ioctl_search_header))); sk.tree_id = old_state.m_root; sk.min_objectid = old_state.m_objectid; sk.min_type = sk.max_type = BTRFS_EXTENT_DATA_KEY;