diff --git a/src/snmalloc/backend/backend.h b/src/snmalloc/backend/backend.h index db380fc..dda05ab 100644 --- a/src/snmalloc/backend/backend.h +++ b/src/snmalloc/backend/backend.h @@ -117,23 +117,33 @@ namespace snmalloc } // Global range of memory - using GlobalR = GlobalRange< - LargeBuddyRange>; + using GlobalR = GlobalRange>>; #ifdef SNMALLOC_META_PROTECTED // Introduce two global ranges, so we don't mix Object and Meta - using CentralObectRange = GlobalRange< - LargeBuddyRange>; - using CentralMetaRange = GlobalRange, // Use SubRange to introduce guard pages. - 24, - bits::BITS - 1, - Pagemap, - MinBaseSizeBits()>>; + using CentralObjectRange = GlobalRange>>; + using CentralMetaRange = GlobalRange, // Use SubRange to introduce guard pages. + 24, + bits::BITS - 1, + Pagemap, + MinBaseSizeBits()>>>; // Source for object allocations - using StatsObject = StatsRange>; - using ObjectRange = LargeBuddyRange; + using StatsObject = StatsRange>; + using ObjectRange = + LogRange<5, LargeBuddyRange>; using StatsMeta = StatsRange>; diff --git a/src/snmalloc/backend_helpers/backend_helpers.h b/src/snmalloc/backend_helpers/backend_helpers.h index 06f0c92..94dfec2 100644 --- a/src/snmalloc/backend_helpers/backend_helpers.h +++ b/src/snmalloc/backend_helpers/backend_helpers.h @@ -5,6 +5,7 @@ #include "empty_range.h" #include "globalrange.h" #include "largebuddyrange.h" +#include "logrange.h" #include "pagemap.h" #include "pagemapregisterrange.h" #include "palrange.h" diff --git a/src/snmalloc/backend_helpers/logrange.h b/src/snmalloc/backend_helpers/logrange.h new file mode 100644 index 0000000..432e877 --- /dev/null +++ b/src/snmalloc/backend_helpers/logrange.h @@ -0,0 +1,52 @@ +#pragma once + +namespace snmalloc +{ + /** + * RangeName is an integer to specify which range is being logged. Strings can + * be used as template parameters. + * + * ParentRange is what the range is logging calls to. + */ + template + class LogRange + { + ParentRange parent{}; + + public: + static constexpr bool Aligned = ParentRange::Aligned; + + static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + + constexpr LogRange() = default; + + capptr::Chunk alloc_range(size_t size) + { +#ifdef SNMALLOC_TRACING + message<1024>("Call alloc_range({}) on {}", size, RangeName); +#endif + auto range = parent.alloc_range(size); +#ifdef SNMALLOC_TRACING + message<1024>( + "{} = alloc_range({}) in {}", range.unsafe_ptr(), size, RangeName); +#endif + return range; + } + + void dealloc_range(capptr::Chunk base, size_t size) + { +#ifdef SNMALLOC_TRACING + message<1024>( + "dealloc_range({}, {}}) on {}", base.unsafe_ptr(), size, RangeName); +#endif + parent.dealloc_range(base, size); +#ifdef SNMALLOC_TRACING + message<1024>( + "Done dealloc_range({}, {}})! on {}", + base.unsafe_ptr(), + size, + RangeName); +#endif + } + }; +} // namespace snmalloc \ No newline at end of file