xo-alloc2: + guard bytes at beginning of arena + refactoring
This commit is contained in:
parent
6cf535eaef
commit
c6b57232e8
8 changed files with 210 additions and 89 deletions
59
xo-alloc2/include/xo/alloc2/ArenaConfig.hpp
Normal file
59
xo-alloc2/include/xo/alloc2/ArenaConfig.hpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/** @file ArenaConfig.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @class ArenaConfig
|
||||
*
|
||||
* @brief configuration for a @ref DArena instance
|
||||
**/
|
||||
struct ArenaConfig {
|
||||
/** @defgroup mm-arenaconfig-instance-vars ArenaConfig members **/
|
||||
///@{
|
||||
|
||||
/** optional name, for diagnostics **/
|
||||
std::string name_;
|
||||
/** desired arena size -- hard max = reserved virtual memory **/
|
||||
std::size_t size_;
|
||||
/** hugepage size -- using huge pages relieves some TLB pressure
|
||||
* (provided you use their full extent :)
|
||||
**/
|
||||
std::size_t hugepage_z_ = 2 * 1024 * 1024;
|
||||
/** if non-zero, allocate extra space between allocs, and fill
|
||||
* with fixed test-pattern contents. Allows for simple
|
||||
* runtime arena sanitizing checks.
|
||||
* Will be rounded up to multiple of @ref padding::c_alloc_alignment
|
||||
**/
|
||||
std::size_t guard_z_ = 0;
|
||||
/** if guard_z_ > 0, write at least that many copies
|
||||
* of this guard byte following each complete allocation
|
||||
**/
|
||||
std::uint8_t guard_byte_ = 0xfd;
|
||||
/** if store_header_flag_ is true: mask bits for allocation size.
|
||||
* remaining bits can be stolen for other purposes
|
||||
* otherwise ignored
|
||||
**/
|
||||
/** true to store header (8 bytes) at the beginning of each allocation.
|
||||
* necessary and sufficient to allows iterating over allocs
|
||||
* present in arena
|
||||
**/
|
||||
bool store_header_flag_ = false;
|
||||
std::uint64_t header_size_mask_ = 0xffffffff;
|
||||
/** true to enable debug logging **/
|
||||
bool debug_flag_ = false;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ArenaConfig.hpp */
|
||||
|
|
@ -5,49 +5,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "ArenaConfig.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @class ArenaConfig
|
||||
*
|
||||
* @brief configuration for a @ref DArena instance
|
||||
**/
|
||||
struct ArenaConfig {
|
||||
/** @defgroup mm-arenaconfig-instance-vars ArenaConfig members **/
|
||||
///@{
|
||||
|
||||
/** optional name, for diagnostics **/
|
||||
std::string name_;
|
||||
/** desired arena size -- hard max = reserved virtual memory **/
|
||||
std::size_t size_;
|
||||
/** hugepage size -- using huge pages relieves some TLB pressure
|
||||
* (provided you use their full extent :)
|
||||
**/
|
||||
std::size_t hugepage_z_ = 2 * 1024 * 1024;
|
||||
/** true to store header (8 bytes) at the beginning of each allocation.
|
||||
* necessary and sufficient to allows iterating over allocs
|
||||
* present in arena
|
||||
**/
|
||||
bool store_header_flag_ = false;
|
||||
/** if non-zero, allocate extra space between allocs, and fill
|
||||
* with fixed test-pattern contents. Allows for simple
|
||||
* runtime arena sanitizing checks.
|
||||
* Will be rounded up to multiple of @ref padding::c_alloc_alignment
|
||||
**/
|
||||
std::size_t guard_z_ = 0;
|
||||
/** if store_header_flag_ is true: mask bits for allocation size.
|
||||
* remaining bits can be stolen for other purposes
|
||||
* otherwise ignored
|
||||
**/
|
||||
std::uint64_t header_size_mask_ = 0xffffffff;
|
||||
/** true to enable debug logging **/
|
||||
bool debug_flag_ = false;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
/** @class DArena
|
||||
*
|
||||
* @brief represent arena allocator state
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@
|
|||
#include <cassert>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
struct IAllocator_Any;
|
||||
}
|
||||
namespace mm { struct IAllocator_Any; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
|
|
@ -22,12 +20,14 @@ namespace xo {
|
|||
|
||||
namespace mm {
|
||||
/** @class IAllocator_Any
|
||||
* @brief Allocator implementation for variant instance.
|
||||
* @brief Allocator implementation for empty variant instance.
|
||||
**/
|
||||
struct IAllocator_Any : public AAllocator {
|
||||
//using Impl = IAllocator_ImplType<xo::facet::DVariantPlaceholder>;
|
||||
using size_type = std::size_t;
|
||||
|
||||
const AAllocator * iface() const { return std::launder(this); }
|
||||
|
||||
// from AAllocator
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace xo {
|
|||
enum class alloc_mode : uint8_t {
|
||||
standard,
|
||||
super,
|
||||
sub,
|
||||
sub_incomplete,
|
||||
sub_complete,
|
||||
};
|
||||
|
||||
|
|
@ -75,10 +75,7 @@ namespace xo {
|
|||
/** alloc driver. shared by alloc(), super_alloc(), sub_alloc() **/
|
||||
static value_type _alloc(DArena &,
|
||||
size_type z,
|
||||
alloc_mode mode,
|
||||
bool store_header_flag,
|
||||
bool remember_header_flag);
|
||||
|
||||
alloc_mode mode);
|
||||
};
|
||||
|
||||
// template <>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue