xo-arena: + DArena methods {checkpoint, restore}
This commit is contained in:
parent
15028cbe92
commit
64b165766f
1 changed files with 16 additions and 29 deletions
|
|
@ -62,6 +62,12 @@ namespace xo {
|
|||
sub_complete,
|
||||
};
|
||||
|
||||
/** @brief Checkpoint for unwinding arena state **/
|
||||
struct Checkpoint {
|
||||
explicit Checkpoint(std::byte * x) : free_{x} {}
|
||||
std::byte * free_;
|
||||
};
|
||||
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-arena-ctors arena constructors and destructors **/
|
||||
|
|
@ -115,34 +121,6 @@ namespace xo {
|
|||
**/
|
||||
bool contains(const void * addr) const noexcept { return (lo_ <= addr) && (addr < hi_); }
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/** obtain uncommitted contiguous memory range comprising
|
||||
* a whole multiple of @p align_z bytes, of at least size @p req_z,
|
||||
* aligned on a @p align_z boundary. Uncommitted memory is not (yet)
|
||||
* backed by physical memory.
|
||||
*
|
||||
* If @p enable_hugepage_flag is true and THP
|
||||
* (transparent huge pages) are available, use THP for arena memory.
|
||||
* This relieves TLB and page table memory when @p req_z is a lot larger than
|
||||
* page size (likely 4KB). Cost is that arena will consum physical memory in unit
|
||||
* of @p align_z. Arena may waste up to @p align_z bytes of memory as a result.
|
||||
*
|
||||
* If @p enable_hugepage_flag is true, @p align_z should be huge page size
|
||||
* (probably 2MB) for optimal performance.
|
||||
*
|
||||
* At present the THP feature is not supported on OSX.
|
||||
* May be supportable through mach_vm_allocate().
|
||||
*
|
||||
* Note that we reject MAP_HUGETLB|MAP_HUGE_2MB flags to mmap here,
|
||||
* since requires previously-reserved memory in /proc/sys/vm/nr_hugepages.
|
||||
*
|
||||
* @return pair giving reserved memory address range [lo,hi)
|
||||
**/
|
||||
static range_type map_aligned_range(size_type req_z,
|
||||
size_type align_z,
|
||||
bool enable_hugepage_flag);
|
||||
#endif
|
||||
|
||||
/** true if arena is mapped i.e. has a reserved address range **/
|
||||
bool is_mapped() const noexcept { return (lo_ != nullptr) && (hi_ != nullptr); }
|
||||
|
||||
|
|
@ -165,7 +143,8 @@ namespace xo {
|
|||
*
|
||||
* Require:
|
||||
* 1. @p mem is address returned by allocation on this arena
|
||||
* i.e. by @ref IAllocator_DArena::alloc() or @ref IAllocator_DArena::alloc_super()
|
||||
* i.e. by @ref IAllocator_DArena::alloc() or
|
||||
* @ref IAllocator_DArena::alloc_super()
|
||||
* 2. @p mem has not been invalidated since it was allocated
|
||||
* i.e. by call to @ref DArena::clear
|
||||
*
|
||||
|
|
@ -218,6 +197,14 @@ namespace xo {
|
|||
/** create initial guard **/
|
||||
void establish_initial_guard() noexcept;
|
||||
|
||||
/** checkpoint arena state. Revert to the same state with
|
||||
* @ref rstore
|
||||
**/
|
||||
Checkpoint checkpoint() noexcept { return Checkpoint(free_); }
|
||||
|
||||
/** restore arena state to previously-established checkpoint **/
|
||||
void restore(Checkpoint ckp) noexcept { free_ = ckp.free_; }
|
||||
|
||||
/** discard all allocated memory, return to empty state
|
||||
* Promise:
|
||||
* - committed memory unchanged
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue