diff --git a/xo-alloc2/src/alloc2/CMakeLists.txt b/xo-alloc2/src/alloc2/CMakeLists.txt index 07b7dec4..42e98ed4 100644 --- a/xo-alloc2/src/alloc2/CMakeLists.txt +++ b/xo-alloc2/src/alloc2/CMakeLists.txt @@ -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) diff --git a/xo-alloc2/src/alloc2/IAllocator_DArena.cpp b/xo-alloc2/src/alloc2/IAllocator_DArena.cpp index babc0f00..83ebd8a2 100644 --- a/xo-alloc2/src/alloc2/IAllocator_DArena.cpp +++ b/xo-alloc2/src/alloc2/IAllocator_DArena.cpp @@ -5,6 +5,7 @@ #include "IAllocator_DArena.hpp" #include "padding.hpp" +#include "xo/indentlog/scope.hpp" #include #include #include @@ -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; } diff --git a/xo-alloc2/utest/arena.test.cpp b/xo-alloc2/utest/arena.test.cpp index 8e3cae61..72c6b4ec 100644 --- a/xo-alloc2/utest/arena.test.cpp +++ b/xo-alloc2/utest/arena.test.cpp @@ -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 @@ -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 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);