xo-alloc: retire redline-memory feature

This commit is contained in:
Roland Conybeare 2025-08-06 22:50:29 -05:00
commit 8b622e6999
8 changed files with 106 additions and 10 deletions

View file

@ -12,20 +12,37 @@
namespace xo {
namespace gc {
ArenaAlloc::ArenaAlloc(const std::string & name, std::size_t rz, std::size_t z, bool debug_flag)
ArenaAlloc::ArenaAlloc(const std::string & name,
#ifdef REDLINE_MEMORY
std::size_t rz,
#endif
std::size_t z, bool debug_flag)
{
this->name_ = name;
#ifdef REDLINE_MEMORY
this->lo_ = (new std::byte [rz + z]);
#else
this->lo_ = (new std::byte [z]);
#endif
this->checkpoint_ = lo_;
this->free_ptr_ = lo_;
this->limit_ = lo_ + z;
#ifdef REDLINE_MEMORY
this->redline_z_ = rz;
this->hi_ = limit_ + rz;
#else
this->hi_ = limit_;
#endif
this->debug_flag_ = debug_flag;
if (!lo_) {
#ifdef REDLINE_MEMORY
throw std::runtime_error(tostr("ArenaAlloc: allocation failed",
xtag("size", rz + z)));
#else
throw std::runtime_error(tostr("ArenaAlloc: allocation failed",
xtag("size", z)));
#endif
}
}
@ -39,15 +56,25 @@ namespace xo {
this->checkpoint_ = nullptr;
this->free_ptr_ = nullptr;
this->limit_ = nullptr;
#ifdef REDLINE_MEMORY
this->redline_z_ = 0;
#endif
this->hi_ = nullptr;
this->debug_flag_ = false;
}
up<ArenaAlloc>
ArenaAlloc::make(const std::string & name, std::size_t rz, std::size_t z, bool debug_flag)
ArenaAlloc::make(const std::string & name,
#ifdef REDLINE_MEMORY
std::size_t rz,
#endif
std::size_t z, bool debug_flag)
{
return up<ArenaAlloc>(new ArenaAlloc(name, rz, z, debug_flag));
return up<ArenaAlloc>(new ArenaAlloc(name,
#ifdef REDLINE_MEMORY
rz,
#endif
z, debug_flag));
}
void
@ -144,7 +171,11 @@ namespace xo {
ArenaAlloc::clear()
{
this->set_free_ptr(lo_);
#ifdef REDLINE_MEMORY
this->limit_ = hi_ - redline_z_;
#else
this->limit_ = hi_;
#endif
}
void
@ -184,10 +215,12 @@ namespace xo {
return retval;
}
#ifdef REDLINE_MEMORY
void
ArenaAlloc::release_redline_memory() {
this->limit_ = this->hi_;
}
#endif
} /*namespace gc*/
} /*namespace xo*/

View file

@ -255,13 +255,17 @@ namespace xo {
std::byte * x = nursery_[role2int(role::to_space)]->alloc(z);
if (!x) {
/* ListAlloc won't fail -- instead will increase heap size */
this->request_gc(generation::nursery);
#ifdef REDLINE_MEMORY
if (incr_gc_pending_ || full_gc_pending_)
nursery_[role2int(role::to_space)]->release_redline_memory();
/* try (just once) more, maybe request fits in redline space */
x = nursery_[role2int(role::to_space)]->alloc(z);
#endif
assert(x);
}
@ -310,7 +314,9 @@ namespace xo {
this->request_gc(generation::nursery);
#ifdef REDLINE_MEMORY
nursery_[role2int(role::to_space)]->release_redline_memory();
#endif
retval = nursery_[role2int(role::to_space)]->alloc(z);
}
@ -387,11 +393,13 @@ namespace xo {
}
}
#ifdef REDLINE_MEMORY
void
GC::release_redline_memory()
{
// not supported feature for GC
}
#endif
void
GC::swap_nursery()

View file

@ -13,7 +13,9 @@ namespace xo {
ListAlloc::ListAlloc(std::unique_ptr<ArenaAlloc> hd,
ArenaAlloc * marked,
std::size_t cz, std::size_t nz, std::size_t tz,
#ifdef REDLINE_MEMORY
bool use_redline,
#endif
bool debug_flag)
: start_z_{cz},
hd_{std::move(hd)},
@ -22,7 +24,9 @@ namespace xo {
current_z_{cz},
next_z_{nz},
total_z_{tz},
#ifdef REDLINE_MEMOORY
use_redline_{use_redline},
#endif
debug_flag_{debug_flag}
{}
@ -34,7 +38,11 @@ namespace xo {
up<ListAlloc>
ListAlloc::make(const std::string & name, std::size_t cz, std::size_t nz, bool debug_flag)
{
std::unique_ptr<ArenaAlloc> hd{ArenaAlloc::make(name, 0, cz, debug_flag)};
std::unique_ptr<ArenaAlloc> hd{ArenaAlloc::make(name,
#ifdef REDLINE_MEMORY
0,
#endif
cz, debug_flag)};
if (!hd)
return nullptr;
@ -44,7 +52,9 @@ namespace xo {
up<ListAlloc> retval{new ListAlloc(std::move(hd),
marked,
cz, nz, cz,
#ifdef REDLINE_MEMORY
false /*!use_redline*/,
#endif
debug_flag)};
return retval;
@ -248,20 +258,26 @@ namespace xo {
current_z_ = 0;
next_z_ = 0;
total_z_ = 0;
#ifdef REDLINE_MEMORY
use_redline_ = false;
#endif
}
bool
ListAlloc::reset(std::size_t z)
{
#ifdef REDLINE_MEMORY
// warning: hd_->size() does not include redline memory
hd_->release_redline_memory();
#endif
bool recycle_head_bucket = hd_ && (z <= hd_->size());
this->full_l_.clear();
this->marked_ = nullptr;
#ifdef REDLINE_MEMORY
this->redlined_flag_ = false;
#endif
if (recycle_head_bucket) {
this->hd_->clear();
@ -291,7 +307,11 @@ namespace xo {
std::string name = hd_->name() + "+exp";
std::unique_ptr<ArenaAlloc> new_alloc = ArenaAlloc::make(name, 0, cz, debug_flag_);
std::unique_ptr<ArenaAlloc> new_alloc = ArenaAlloc::make(name,
#ifdef REDLINE_MEMORY
0,
#endif
cz, debug_flag_);
if (!new_alloc)
return false;
@ -325,6 +345,7 @@ namespace xo {
return nullptr;
}
#ifdef REDLINE_MEMORY
void
ListAlloc::release_redline_memory()
{
@ -333,6 +354,7 @@ namespace xo {
this->hd_->release_redline_memory();
}
#endif
} /*namespace gc*/
} /*namespace xo*/