mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::allocator: Reinterface for attributed function instrumentation.
This commit is contained in:
parent
96b101cd6f
commit
a600d59367
3 changed files with 30 additions and 33 deletions
|
@ -22,6 +22,7 @@ namespace ircd::allocator
|
|||
struct state;
|
||||
struct scope;
|
||||
struct profile;
|
||||
struct aligned_alloc;
|
||||
template<class T = void> struct callback;
|
||||
template<class T = char> struct dynamic;
|
||||
template<class T = char, size_t = 512> struct fixed;
|
||||
|
@ -57,8 +58,8 @@ namespace ircd::allocator
|
|||
void protect(const const_buffer &, const bool = true);
|
||||
void readonly(const mutable_buffer &, const bool = true);
|
||||
|
||||
std::unique_ptr<char, decltype(&std::free)>
|
||||
aligned_alloc(const size_t &align, const size_t &size);
|
||||
[[using gnu: malloc, alloc_align(1), alloc_size(2), returns_nonnull, warn_unused_result]]
|
||||
char *allocate(const size_t align, const size_t size);
|
||||
}
|
||||
|
||||
/// jemalloc specific suite; note that some of the primary ircd::allocator
|
||||
|
@ -74,6 +75,18 @@ namespace ircd
|
|||
using allocator::incore;
|
||||
}
|
||||
|
||||
struct ircd::allocator::aligned_alloc
|
||||
:std::unique_ptr<char, decltype(&std::free)>
|
||||
{
|
||||
aligned_alloc(const size_t &align, const size_t &size)
|
||||
:std::unique_ptr<char, decltype(&std::free)>
|
||||
{
|
||||
allocate(align?: sizeof(void *), pad_to(size, align?: sizeof(void *))),
|
||||
&std::free
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
/// Profiling counters. The purpose of this device is to gauge whether unwanted
|
||||
/// or non-obvious allocations are taking place for a specific section. This
|
||||
/// profiler has that very specific purpose and is not a replacement for
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
// Fwd decl; circ dep.
|
||||
namespace ircd::allocator
|
||||
{
|
||||
std::unique_ptr<char, decltype(&std::free)>
|
||||
aligned_alloc(const size_t &align, const size_t &size);
|
||||
[[using gnu: malloc, alloc_align(1), alloc_size(2), returns_nonnull, warn_unused_result]]
|
||||
char *allocate(const size_t align, const size_t size);
|
||||
}
|
||||
|
||||
/// Like unique_ptr, this template holds ownership of an allocated buffer
|
||||
|
@ -42,9 +42,9 @@ struct ircd::buffer::unique_buffer
|
|||
template<class buffer_type>
|
||||
inline
|
||||
ircd::buffer::unique_buffer<buffer_type>::unique_buffer(const const_buffer &src)
|
||||
:buffer_type
|
||||
:unique_buffer
|
||||
{
|
||||
allocator::aligned_alloc(0, ircd::buffer::size(src)).release(), ircd::buffer::size(src)
|
||||
ircd::buffer::size(src)
|
||||
}
|
||||
{
|
||||
using ircd::buffer::size;
|
||||
|
@ -63,10 +63,11 @@ ircd::buffer::unique_buffer<buffer_type>::unique_buffer(const const_buffer &src)
|
|||
template<class buffer_type>
|
||||
inline
|
||||
ircd::buffer::unique_buffer<buffer_type>::unique_buffer(const size_t &size,
|
||||
const size_t &align)
|
||||
const size_t &a)
|
||||
:buffer_type
|
||||
{
|
||||
allocator::aligned_alloc(align, size).release(), size
|
||||
allocator::allocate(a?: sizeof(void *), pad_to(size, a?: sizeof(void *))),
|
||||
size
|
||||
}
|
||||
{}
|
||||
|
||||
|
|
|
@ -44,28 +44,14 @@ namespace ircd::allocator
|
|||
static_assert(MADV_DONTNEED == POSIX_MADV_DONTNEED);
|
||||
#endif
|
||||
|
||||
std::unique_ptr<char, decltype(&std::free)>
|
||||
ircd::allocator::aligned_alloc(const size_t &alignment_,
|
||||
const size_t &size_)
|
||||
[[gnu::hot]]
|
||||
char *
|
||||
ircd::allocator::allocate(const size_t alignment,
|
||||
const size_t size)
|
||||
{
|
||||
constexpr auto align_default
|
||||
{
|
||||
sizeof(void *)
|
||||
};
|
||||
|
||||
const auto alignment
|
||||
{
|
||||
alignment_?: align_default
|
||||
};
|
||||
|
||||
const auto size
|
||||
{
|
||||
pad_to(size_, alignment)
|
||||
};
|
||||
|
||||
assert(size % alignment == 0);
|
||||
assert(size < size_ + alignment);
|
||||
assert(alignment % sizeof(void *) == 0);
|
||||
assume(alignment > 0);
|
||||
assume(size % alignment == 0);
|
||||
assume(alignment % sizeof(void *) == 0);
|
||||
|
||||
void *ret;
|
||||
switch(int errc(::posix_memalign(&ret, alignment, size)); errc)
|
||||
|
@ -95,10 +81,7 @@ ircd::allocator::aligned_alloc(const size_t &alignment_,
|
|||
this_thread.alloc_count++;
|
||||
#endif
|
||||
|
||||
return
|
||||
{
|
||||
reinterpret_cast<char *>(ret), &std::free
|
||||
};
|
||||
return reinterpret_cast<char *>(ret);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue