mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::db::database::allocator: Support aligned allocations.
ircd::db::database::allocator: Implement callback for true allocated size hint.
This commit is contained in:
parent
52831893da
commit
516d7e8ad7
2 changed files with 52 additions and 6 deletions
50
ircd/db.cc
50
ircd/db.cc
|
@ -3490,10 +3490,24 @@ const noexcept
|
|||
//
|
||||
#ifdef IRCD_DB_HAS_ALLOCATOR
|
||||
|
||||
decltype(ircd::db::database::allocator::ALIGN_DEFAULT)
|
||||
ircd::db::database::allocator::ALIGN_DEFAULT
|
||||
{
|
||||
#if defined(__AVX__)
|
||||
32
|
||||
#elif defined(__SSE__)
|
||||
16
|
||||
#else
|
||||
sizeof(void *)
|
||||
#endif
|
||||
};
|
||||
|
||||
ircd::db::database::allocator::allocator(database *const &d,
|
||||
database::column *const &c)
|
||||
database::column *const &c,
|
||||
const size_t &alignment)
|
||||
:d{d}
|
||||
,c{c}
|
||||
,alignment{alignment}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -3504,10 +3518,20 @@ noexcept
|
|||
|
||||
size_t
|
||||
ircd::db::database::allocator::UsableSize(void *const ptr,
|
||||
size_t allocation_size)
|
||||
size_t size)
|
||||
const noexcept
|
||||
{
|
||||
return allocation_size;
|
||||
const size_t ret
|
||||
{
|
||||
size % alignment != 0?
|
||||
size + (alignment - (size % alignment)):
|
||||
size
|
||||
};
|
||||
|
||||
assert(ret % alignment == 0);
|
||||
assert(ret < size + alignment);
|
||||
assert(alignment % sizeof(void *) == 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3521,7 +3545,25 @@ void *
|
|||
ircd::db::database::allocator::Allocate(size_t size)
|
||||
noexcept
|
||||
{
|
||||
return std::malloc(size);
|
||||
auto ptr
|
||||
{
|
||||
ircd::allocator::aligned_alloc(alignment, size)
|
||||
};
|
||||
|
||||
#ifdef RB_DEBUG_DB_ENV
|
||||
assert(d);
|
||||
log::debug
|
||||
{
|
||||
log, "[%s]'%s' allocate:%zu alignment:%zu %p",
|
||||
db::name(*d),
|
||||
c? string_view(db::name(*c)): string_view{},
|
||||
size,
|
||||
alignment,
|
||||
ptr.get(),
|
||||
};
|
||||
#endif
|
||||
|
||||
return ptr.release();
|
||||
}
|
||||
|
||||
const char *
|
||||
|
|
|
@ -295,8 +295,11 @@ struct ircd::db::database::wal_filter
|
|||
struct ircd::db::database::allocator final
|
||||
:rocksdb::MemoryAllocator
|
||||
{
|
||||
static const size_t ALIGN_DEFAULT;
|
||||
|
||||
database *d {nullptr};
|
||||
database::column *c {nullptr};
|
||||
size_t alignment {ALIGN_DEFAULT};
|
||||
|
||||
const char *Name() const noexcept override;
|
||||
void *Allocate(size_t) noexcept override;
|
||||
|
@ -304,7 +307,8 @@ struct ircd::db::database::allocator final
|
|||
size_t UsableSize(void *, size_t) const noexcept override;
|
||||
|
||||
allocator(database *const &,
|
||||
database::column *const & = nullptr);
|
||||
database::column *const & = nullptr,
|
||||
const size_t &alignment = ALIGN_DEFAULT);
|
||||
|
||||
~allocator() noexcept;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue