xo-alloc2: AAllocator.expand() working
This commit is contained in:
parent
38f419f2ea
commit
24109a9e11
3 changed files with 21 additions and 10 deletions
|
|
@ -11,3 +11,4 @@ set(SELF_SRCS
|
|||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
# note: deps here must also appear in cmake/xo_alloc2Config.cmake.in
|
||||
xo_dependency(${SELF_LIB} xo_facet)
|
||||
xo_dependency(${SELF_LIB} indentlog)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "IAllocator_DArena.hpp"
|
||||
#include "padding.hpp"
|
||||
#include "xo/indentlog/scope.hpp"
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <sys/mman.h>
|
||||
|
|
@ -42,20 +43,21 @@ namespace xo {
|
|||
bool
|
||||
IAllocator_DArena::expand(DArena & s, size_t target_z)
|
||||
{
|
||||
// scope log(XO_DEBUG(debug_flag_),
|
||||
// xtag("offset_z", offset_z),
|
||||
// xtag("committed_z", committed_z_));
|
||||
scope log(XO_DEBUG(s.config_.debug_flag_),
|
||||
xtag("target_z", target_z),
|
||||
xtag("committed_z", s.committed_z_));
|
||||
|
||||
if (target_z <= s.committed_z_) {
|
||||
// log && log("trivial success, offset within committed range",
|
||||
// xtag("offset_z", offset_z),
|
||||
// xtag("committed_z", committed_z_));
|
||||
log && log("trivial success, offset within committed range",
|
||||
xtag("target_z", target_z),
|
||||
xtag("committed_z", s.committed_z_));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (s.lo_ + target_z > s.hi_) {
|
||||
// throw std::runtime_error(tostr("ArenaAlloc::expand: requested size exceeds reserved size",
|
||||
// xtag("requested", offset_z), xtag("reserved", reserved())));
|
||||
throw std::runtime_error(tostr("ArenaAlloc::expand: requested size exceeds reserved size",
|
||||
xtag("requested", target_z),
|
||||
xtag("reserved", reserved(s))));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "xo/alloc2/IAllocator_DArena.hpp"
|
||||
#include "xo/alloc2/RAllocator.hpp"
|
||||
#include "xo/alloc2/padding.hpp"
|
||||
#include "xo/indentlog/scope.hpp"
|
||||
#include "xo/facet/obj.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ namespace xo {
|
|||
using xo::mm::DArena;
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::facet::obj;
|
||||
using xo::scope;
|
||||
using std::byte;
|
||||
using std::size_t;
|
||||
|
||||
|
|
@ -107,13 +109,19 @@ namespace xo {
|
|||
{
|
||||
/* typed allocator a1o */
|
||||
ArenaConfig cfg { .name_ = "testarena",
|
||||
.size_ = 1 };
|
||||
.size_ = 1,
|
||||
.debug_flag_ = false };
|
||||
DArena arena = DArena::map(cfg);
|
||||
obj<AAllocator, DArena> a1o{&arena};
|
||||
|
||||
a1o.expand(3*1024*1024);
|
||||
size_t z2 = 512;
|
||||
REQUIRE(a1o.expand(z2));
|
||||
|
||||
REQUIRE(a1o.reserved() % cfg.hugepage_z_ == 0);
|
||||
REQUIRE(a1o.committed() >= z2);
|
||||
REQUIRE(a1o.committed() % cfg.hugepage_z_ == 0);
|
||||
/* .size() is synonym for .committed() */
|
||||
REQUIRE(a1o.size() == a1o.committed());
|
||||
|
||||
#ifdef NOPE
|
||||
byte * m = a1o.alloc(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue