1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 13:25:45 +02:00

context: get rid of shared_ptr<BeesContext> in every single cached Fd object

Support for multiple BeesContext objects sharing a FdCache was wasting
significant space and atomic inc/dec memory cycles for no good reason
since the shared-FdCache feature was deprecated.

open_root and open_root_ino still need a BeesContext to work.  Pass the
BeesContext pointer through the function object instead of the cache
key arguments.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2021-04-28 21:54:00 -04:00
parent db65031c2b
commit 80c69f1ce4
3 changed files with 21 additions and 19 deletions

View File

@ -21,18 +21,19 @@ using namespace crucible;
using namespace std;
BeesFdCache::BeesFdCache()
BeesFdCache::BeesFdCache(shared_ptr<BeesContext> ctx) :
m_ctx(ctx)
{
m_root_cache.func([&](shared_ptr<BeesContext> ctx, uint64_t root) -> Fd {
m_root_cache.func([&](uint64_t root) -> Fd {
Timer open_timer;
auto rv = ctx->roots()->open_root_nocache(root);
auto rv = m_ctx->roots()->open_root_nocache(root);
BEESCOUNTADD(open_root_ms, open_timer.age() * 1000);
return rv;
});
m_root_cache.max_size(BEES_ROOT_FD_CACHE_SIZE);
m_file_cache.func([&](shared_ptr<BeesContext> ctx, uint64_t root, uint64_t ino) -> Fd {
m_file_cache.func([&](uint64_t root, uint64_t ino) -> Fd {
Timer open_timer;
auto rv = ctx->roots()->open_root_ino_nocache(root, ino);
auto rv = m_ctx->roots()->open_root_ino_nocache(root, ino);
BEESCOUNTADD(open_ino_ms, open_timer.age() * 1000);
return rv;
});
@ -51,15 +52,15 @@ BeesFdCache::clear()
}
Fd
BeesFdCache::open_root(shared_ptr<BeesContext> ctx, uint64_t root)
BeesFdCache::open_root(uint64_t root)
{
return m_root_cache(ctx, root);
return m_root_cache(root);
}
Fd
BeesFdCache::open_root_ino(shared_ptr<BeesContext> ctx, uint64_t root, uint64_t ino)
BeesFdCache::open_root_ino(uint64_t root, uint64_t ino)
{
return m_file_cache(ctx, root, ino);
return m_file_cache(root, ino);
}
void
@ -1107,7 +1108,7 @@ BeesContext::fd_cache()
throw BeesHalt();
}
if (!m_fd_cache) {
m_fd_cache = make_shared<BeesFdCache>();
m_fd_cache = make_shared<BeesFdCache>(shared_from_this());
}
auto rv = m_fd_cache;
return rv;

View File

@ -709,7 +709,7 @@ BeesRoots::open_root(uint64_t rootid)
return Fd();
}
return m_ctx->fd_cache()->open_root(m_ctx, rootid);
return m_ctx->fd_cache()->open_root(rootid);
}
bool
@ -906,7 +906,7 @@ BeesRoots::open_root_ino_nocache(uint64_t root, uint64_t ino)
Fd
BeesRoots::open_root_ino(uint64_t root, uint64_t ino)
{
return m_ctx->fd_cache()->open_root_ino(m_ctx, root, ino);
return m_ctx->fd_cache()->open_root_ino(root, ino);
}
RateEstimator &

View File

@ -697,15 +697,16 @@ public:
};
class BeesFdCache {
LRUCache<Fd, shared_ptr<BeesContext>, uint64_t> m_root_cache;
LRUCache<Fd, shared_ptr<BeesContext>, uint64_t, uint64_t> m_file_cache;
Timer m_root_cache_timer;
Timer m_file_cache_timer;
shared_ptr<BeesContext> m_ctx;
LRUCache<Fd, uint64_t> m_root_cache;
LRUCache<Fd, uint64_t, uint64_t> m_file_cache;
Timer m_root_cache_timer;
Timer m_file_cache_timer;
public:
BeesFdCache();
Fd open_root(shared_ptr<BeesContext> ctx, uint64_t root);
Fd open_root_ino(shared_ptr<BeesContext> ctx, uint64_t root, uint64_t ino);
BeesFdCache(shared_ptr<BeesContext> ctx);
Fd open_root(uint64_t root);
Fd open_root_ino(uint64_t root, uint64_t ino);
void clear();
};