xo-alloc: reserve virtual memory, commit pages on demand

This commit is contained in:
Roland Conybeare 2025-08-12 00:14:30 -05:00
commit d8b3d7a148
8 changed files with 140 additions and 23 deletions

View file

@ -24,6 +24,8 @@ namespace xo {
**/
class ArenaAlloc : public IAlloc {
public:
ArenaAlloc(const ArenaAlloc &) = delete;
ArenaAlloc(ArenaAlloc &&) = delete;
~ArenaAlloc();
/** create allocator with capacity @p z,
@ -38,10 +40,14 @@ namespace xo {
void capture_object_statistics(capture_phase phase,
ObjectStatistics * p_dest) const;
/** expand available (i.e. committed) space to size @p z **/
bool expand(std::size_t z);
// inherited from IAlloc...
virtual const std::string & name() const final override;
virtual std::size_t size() const final override;
virtual std::size_t committed() const final override;
virtual std::size_t available() const final override;
virtual std::size_t allocated() const final override;
virtual bool contains(const void * x) const final override;
@ -54,6 +60,9 @@ namespace xo {
virtual void checkpoint() final override;
virtual std::byte * alloc(std::size_t z) final override;
ArenaAlloc & operator=(const ArenaAlloc &) = delete;
ArenaAlloc & operator=(ArenaAlloc &&) = delete;
private:
ArenaAlloc(const std::string & name,
std::size_t z, bool debug_flag);
@ -67,8 +76,15 @@ namespace xo {
/** optional instance name, for diagnostics **/
std::string name_;
/** size of a VM page **/
std::size_t page_z_;
/** allocator owns memory in range [@ref lo_, @ref hi_) **/
std::byte * lo_ = nullptr;
/** prefix of this size is actually committed.
* Remainder uses uncommitted virtual address space
**/
std::size_t committed_z_ = 0;
/** checkpoint (for GC support); divides objects into
* older (addresses below checkpoint)
* and younger (addresses above checkpoint)
@ -76,9 +92,9 @@ namespace xo {
std::byte * checkpoint_;
/** free pointer. memory in range [@ref free_, @ref limit_) available **/
std::byte * free_ptr_ = nullptr;
/** soft limit: end of released memory **/
/** soft limit: end of committed virtual memory **/
std::byte * limit_ = nullptr;
/** hard limit: end of allocated memory **/
/** hard limit: end of reserved virtual memory **/
std::byte * hi_ = nullptr;
/** true to enable detailed debug logging **/
bool debug_flag_ = false;

View file

@ -164,7 +164,8 @@ namespace xo {
* since one role is always held empty between collections.
**/
virtual std::size_t size() const final override;
/** for committed count both to-space and from-space **/
virtual std::size_t committed() const final override;
virtual std::size_t allocated() const final override;
virtual std::size_t available() const final override;
/** only tests to-space **/
@ -194,10 +195,6 @@ namespace xo {
virtual std::byte * alloc(std::size_t z) final override;
virtual std::byte * alloc_gc_copy(std::size_t z, const void * src) final override;
#ifdef REDLINE_MEMORY
virtual void release_redline_memory() final override;
#endif
private:
ListAlloc * nursery_to() const { return nursery(role::to_space); }
ListAlloc * nursery_from() const { return nursery(role::from_space); }
@ -208,6 +205,8 @@ namespace xo {
ListAlloc * nursery(role r) const { return nursery_[role2int(r)].get(); }
ListAlloc * tenured(role r) const { return tenured_[role2int(r)].get(); }
MutationLog * mutation_log(role r) const { return mutation_log_[role2int(r)].get(); }
/** begin GC now **/
void execute_gc(generation g);
/** cleanup phase. aux function for @ref execute_gc **/

View file

@ -31,10 +31,12 @@ namespace xo {
/** optional name for this allocator; labelling for diagnostics **/
virtual const std::string & name() const = 0;
/** allocator size in bytes (up to soft limit).
/** allocator size in bytes (up to reserved limit)
* Includes unallocated mmeory
**/
virtual std::size_t size() const = 0;
/** committed size in bytes **/
virtual std::size_t committed() const = 0;
/** number of unallocated bytes available (up to soft limit)
* from this allocator
**/

View file

@ -55,6 +55,7 @@ namespace xo {
virtual const std::string & name() const final override;
virtual std::size_t size() const final override;
virtual std::size_t committed() const final override;
virtual std::size_t available() const final override;
virtual std::size_t allocated() const final override;
virtual bool contains(const void * x) const final override;