From 3430f169983db0f3577c198e9ef8d99e66cac28e Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 21 Feb 2023 00:04:31 -0500 Subject: [PATCH] context: create a Pool of BtrfsIoctlLogicalInoArgs objects Each object contains a 16 MiB buffer, which is very heavy for some malloc implementations. Keep the objects in a Pool so that their buffers are only allocated and deallocated once in the process lifetime. Signed-off-by: Zygo Blaxell --- src/bees-context.cc | 15 ++++++++++++++- src/bees.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bees-context.cc b/src/bees-context.cc index 83edf30..f17212c 100644 --- a/src/bees-context.cc +++ b/src/bees-context.cc @@ -757,6 +757,15 @@ BeesResolveAddrResult::BeesResolveAddrResult() { } +shared_ptr +BeesContext::logical_ino(const uint64_t logical, const bool all_refs) +{ + const auto rv = m_logical_ino_pool(); + rv->set_logical(logical); + rv->set_flags(all_refs ? BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET : 0); + return rv; +} + BeesResolveAddrResult BeesContext::resolve_addr_uncached(BeesAddress addr) { @@ -768,7 +777,8 @@ BeesContext::resolve_addr_uncached(BeesAddress addr) // transaction latency, competing threads, and freeze/SIGSTOP // pausing the bees process. - BtrfsIoctlLogicalInoArgs log_ino(addr.get_physical_or_zero()); + const auto log_ino_ptr = logical_ino(addr.get_physical_or_zero(), false); + auto &log_ino = *log_ino_ptr; // Time how long this takes Timer resolve_timer; @@ -910,6 +920,9 @@ BeesContext::start() m_tmpfile_pool.generator([=]() -> shared_ptr { return make_shared(shared_from_this()); }); + m_logical_ino_pool.generator([]() { + return make_shared(0); + }); m_tmpfile_pool.checkin([](const shared_ptr &btf) { catch_all([&](){ btf->reset(); diff --git a/src/bees.h b/src/bees.h index 30175e4..4dbc005 100644 --- a/src/bees.h +++ b/src/bees.h @@ -714,6 +714,7 @@ class BeesContext : public enable_shared_from_this { shared_ptr m_hash_table; shared_ptr m_roots; Pool m_tmpfile_pool; + Pool m_logical_ino_pool; LRUCache m_resolve_cache; @@ -753,6 +754,8 @@ public: bool scan_forward(const BeesFileRange &bfr); + shared_ptr logical_ino(uint64_t bytenr, bool all_refs); + bool is_root_ro(uint64_t root); BeesRangePair dup_extent(const BeesFileRange &src, const shared_ptr &tmpfile); bool dedup(const BeesRangePair &brp);