diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-14 18:25:43 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-14 18:25:43 +0300 |
commit | c7783ffcebf50c210ca2b469f3a52f59eb9045f8 (patch) | |
tree | 6c0885079aaefb96aa502108f458659aa66570de /library/cpp/coroutine/engine | |
parent | 831543961b2710a44df149e1d363638bc008d265 (diff) | |
download | ydb-c7783ffcebf50c210ca2b469f3a52f59eb9045f8.tar.gz |
intermediate changes
ref:e520cbb2bc5359a80a7e56e636d1404e61f0c48c
Diffstat (limited to 'library/cpp/coroutine/engine')
18 files changed, 134 insertions, 134 deletions
diff --git a/library/cpp/coroutine/engine/stack/benchmark/alloc_bm.cpp b/library/cpp/coroutine/engine/stack/benchmark/alloc_bm.cpp index 38d713d274..0a71b02e62 100644 --- a/library/cpp/coroutine/engine/stack/benchmark/alloc_bm.cpp +++ b/library/cpp/coroutine/engine/stack/benchmark/alloc_bm.cpp @@ -12,9 +12,9 @@ namespace NCoro::NStack::NBenchmark { const char* TestCoroName = "any_name"; - constexpr uint64_t BigCoroSize = PageSize * 25; - constexpr uint64_t SmallCoroSize = PageSize * 4; - constexpr uint64_t ManyStacks = 4096; + constexpr size_t BigCoroSize = PageSize * 25; + constexpr size_t SmallCoroSize = PageSize * 4; + constexpr size_t ManyStacks = 4096; void BasicOperations(TStackHolder& stack) { Y_VERIFY(!stack.Get().empty()); @@ -27,7 +27,7 @@ namespace NCoro::NStack::NBenchmark { Y_VERIFY(!memory.empty()); stack.LowerCanaryOk(); stack.UpperCanaryOk(); - for (uint64_t i = PageSize / 2; i < memory.size(); i += PageSize * 2) { + for (size_t i = PageSize / 2; i < memory.size(); i += PageSize * 2) { memory[i] = 42; } } @@ -87,7 +87,7 @@ namespace NCoro::NStack::NBenchmark { settings.StacksPerChunk = state.range(2); auto allocator = GetAllocator(settings, (EGuard)state.range(0)); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { TStackHolder stack(*allocator, state.range(1), TestCoroName); BasicOperations(stack); } @@ -106,7 +106,7 @@ namespace NCoro::NStack::NBenchmark { static void BM_DefaultAllocatorManyStacksOneAtTime(benchmark::State& state) { auto allocator = GetAllocator(Nothing(), (EGuard)state.range(0)); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { TStackHolder stack(*allocator, state.range(1), TestCoroName); BasicOperations(stack); } @@ -125,7 +125,7 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.emplace_back(*allocator, state.range(1), TestCoroName); BasicOperations(stacks.back()); } @@ -146,7 +146,7 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.push_back(TStackHolder(*allocator, state.range(1), TestCoroName)); BasicOperations(stacks.back()); } @@ -166,7 +166,7 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.emplace_back(*allocator, state.range(1), TestCoroName); BasicOperations(stacks.back()); } @@ -188,7 +188,7 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.push_back(TStackHolder(*allocator, state.range(1), TestCoroName)); BasicOperations(stacks.back()); } @@ -209,12 +209,12 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.emplace_back(*allocator, state.range(1), TestCoroName); BasicOperations(stacks.back()); } stacks.clear(); - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.emplace_back(*allocator, state.range(1), TestCoroName); BasicOperations(stacks.back()); } @@ -239,12 +239,12 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.push_back(TStackHolder(*allocator, state.range(1), TestCoroName)); BasicOperations(stacks.back()); } stacks.clear(); - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.push_back(TStackHolder(*allocator, state.range(1), TestCoroName)); BasicOperations(stacks.back()); } @@ -264,12 +264,12 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.emplace_back(*allocator, state.range(1), TestCoroName); WriteStack(stacks.back()); } stacks.clear(); - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.emplace_back(*allocator, state.range(1), TestCoroName); WriteStack(stacks.back()); } @@ -294,12 +294,12 @@ namespace NCoro::NStack::NBenchmark { TVector<TStackHolder> stacks; // store stacks during benchmark stacks.reserve(ManyStacks); for (auto _ : state) { - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.push_back(TStackHolder(*allocator, state.range(1), TestCoroName)); WriteStack(stacks.back()); } stacks.clear(); - for (uint64_t i = 0; i < ManyStacks; ++i) { + for (size_t i = 0; i < ManyStacks; ++i) { stacks.push_back(TStackHolder(*allocator, state.range(1), TestCoroName)); WriteStack(stacks.back()); } diff --git a/library/cpp/coroutine/engine/stack/stack.cpp b/library/cpp/coroutine/engine/stack/stack.cpp index e29450261d..9d7dbf8ae0 100644 --- a/library/cpp/coroutine/engine/stack/stack.cpp +++ b/library/cpp/coroutine/engine/stack/stack.cpp @@ -8,14 +8,14 @@ namespace NCoro::NStack { namespace NDetails { - TStack::TStack(void* rawMemory, void* alignedMemory, uint64_t alignedSize, const char* /*name*/) + TStack::TStack(void* rawMemory, void* alignedMemory, size_t alignedSize, const char* /*name*/) : RawMemory_((char*)rawMemory) , AlignedMemory_((char*)alignedMemory) , Size_(alignedSize) { Y_ASSERT(AlignedMemory_ && RawMemory_ && Size_); Y_ASSERT(!(Size_ & PageSizeMask)); - Y_ASSERT(!((uint64_t)AlignedMemory_ & PageSizeMask)); + Y_ASSERT(!((size_t)AlignedMemory_ & PageSizeMask)); } TStack::TStack(TStack&& rhs) noexcept diff --git a/library/cpp/coroutine/engine/stack/stack.h b/library/cpp/coroutine/engine/stack/stack.h index 7d98ba4c68..33de58a085 100644 --- a/library/cpp/coroutine/engine/stack/stack.h +++ b/library/cpp/coroutine/engine/stack/stack.h @@ -22,7 +22,7 @@ namespace NDetails { * guard: guard to protect this stack * name: name of coroutine for which this stack is allocated */ - TStack(void* rawMemory, void* alignedMemory, uint64_t alignedSize, const char* name); + TStack(void* rawMemory, void* alignedMemory, size_t alignedSize, const char* name); TStack(TStack&& rhs) noexcept; TStack& operator=(TStack&& rhs) noexcept; @@ -35,7 +35,7 @@ namespace NDetails { } //! Stack size (includes memory for guard) - uint64_t GetSize() const noexcept { + size_t GetSize() const noexcept { return Size_; } @@ -45,7 +45,7 @@ namespace NDetails { private: char* RawMemory_ = nullptr; // not owned char* AlignedMemory_ = nullptr; // not owned - uint64_t Size_ = 0; + size_t Size_ = 0; }; } // namespace NDetails @@ -61,7 +61,7 @@ namespace NDetails { char* GetAlignedMemory() const noexcept { return Stack_.GetAlignedMemory(); } - uint64_t GetSize() const noexcept { + size_t GetSize() const noexcept { return Stack_.GetSize(); } diff --git a/library/cpp/coroutine/engine/stack/stack_allocator.h b/library/cpp/coroutine/engine/stack/stack_allocator.h index da3c3a93a1..ab8806e282 100644 --- a/library/cpp/coroutine/engine/stack/stack_allocator.h +++ b/library/cpp/coroutine/engine/stack/stack_allocator.h @@ -18,8 +18,8 @@ namespace NCoro::NStack { //! Size should be page-aligned. Stack would be protected by guard, thus, actual //! workspace for stack = size - size of guard. - NDetails::TStack AllocStack(uint64_t size, const char* name) { - uint64_t alignedSize = (size + PageSize - 1) & ~PageSizeMask; + NDetails::TStack AllocStack(size_t size, const char* name) { + size_t alignedSize = (size + PageSize - 1) & ~PageSizeMask; Y_ASSERT(alignedSize < 10 * 1024 * PageSize); // more than 10K pages for stack - do you really need it? #if defined(_san_enabled_) || !defined(NDEBUG) alignedSize *= DebugOrSanStackMultiplier; @@ -36,12 +36,12 @@ namespace NCoro::NStack { virtual TAllocatorStats GetStackStats() const noexcept = 0; // Stack helpers - virtual TArrayRef<char> GetStackWorkspace(void* stack, uint64_t size) noexcept = 0; + virtual TArrayRef<char> GetStackWorkspace(void* stack, size_t size) noexcept = 0; virtual bool CheckStackOverflow(void* stack) const noexcept = 0; - virtual bool CheckStackOverride(void* stack, uint64_t size) const noexcept = 0; + virtual bool CheckStackOverride(void* stack, size_t size) const noexcept = 0; private: - virtual NDetails::TStack DoAllocStack(uint64_t size, const char* name) = 0; + virtual NDetails::TStack DoAllocStack(size_t size, const char* name) = 0; virtual void DoFreeStack(NDetails::TStack& stack) noexcept = 0; }; diff --git a/library/cpp/coroutine/engine/stack/stack_allocator.inl b/library/cpp/coroutine/engine/stack/stack_allocator.inl index 0f25a4167b..2f8856da46 100644 --- a/library/cpp/coroutine/engine/stack/stack_allocator.inl +++ b/library/cpp/coroutine/engine/stack/stack_allocator.inl @@ -16,13 +16,13 @@ namespace NCoro::NStack { public: explicit TPoolAllocator(const TPoolAllocatorSettings& settings); - TArrayRef<char> GetStackWorkspace(void* stack, uint64_t size) noexcept override { + TArrayRef<char> GetStackWorkspace(void* stack, size_t size) noexcept override { return Guard_.GetWorkspace(stack, size); } bool CheckStackOverflow(void* stack) const noexcept override { return Guard_.CheckOverflow(stack); } - bool CheckStackOverride(void* stack, uint64_t size) const noexcept override { + bool CheckStackOverride(void* stack, size_t size) const noexcept override { return Guard_.CheckOverride(stack, size); } @@ -37,13 +37,13 @@ namespace NCoro::NStack { } private: // methods - NDetails::TStack DoAllocStack(uint64_t size, const char* name) override; + NDetails::TStack DoAllocStack(size_t size, const char* name) override; void DoFreeStack(NDetails::TStack& stack) noexcept override; private: // data const TPoolAllocatorSettings PoolSettings_; const TGuard& Guard_; - THashMap<uint64_t, TPool<TGuard>> Pools_; // key - stack size + THashMap<size_t, TPool<TGuard>> Pools_; // key - stack size }; template<typename TGuard> @@ -57,7 +57,7 @@ namespace NCoro::NStack { } template<typename TGuard> - NDetails::TStack TPoolAllocator<TGuard>::DoAllocStack(uint64_t alignedSize, const char* name) { + NDetails::TStack TPoolAllocator<TGuard>::DoAllocStack(size_t alignedSize, const char* name) { Y_ASSERT(alignedSize > Guard_.GetSize()); auto pool = Pools_.find(alignedSize); @@ -84,20 +84,20 @@ namespace NCoro::NStack { public: explicit TSimpleAllocator(); - TArrayRef<char> GetStackWorkspace(void* stack, uint64_t size) noexcept override { + TArrayRef<char> GetStackWorkspace(void* stack, size_t size) noexcept override { return Guard_.GetWorkspace(stack, size); } bool CheckStackOverflow(void* stack) const noexcept override { return Guard_.CheckOverflow(stack); } - bool CheckStackOverride(void* stack, uint64_t size) const noexcept override { + bool CheckStackOverride(void* stack, size_t size) const noexcept override { return Guard_.CheckOverride(stack, size); } TAllocatorStats GetStackStats() const noexcept override { return {}; } // not used for simple allocator private: // methods - NDetails::TStack DoAllocStack(uint64_t size, const char* name) override; + NDetails::TStack DoAllocStack(size_t size, const char* name) override; void DoFreeStack(NDetails::TStack& stack) noexcept override; private: // data @@ -111,7 +111,7 @@ namespace NCoro::NStack { {} template<typename TGuard> - NDetails::TStack TSimpleAllocator<TGuard>::DoAllocStack(uint64_t alignedSize, const char* name) { + NDetails::TStack TSimpleAllocator<TGuard>::DoAllocStack(size_t alignedSize, const char* name) { Y_ASSERT(alignedSize > Guard_.GetSize()); char* rawPtr = nullptr; diff --git a/library/cpp/coroutine/engine/stack/stack_common.h b/library/cpp/coroutine/engine/stack/stack_common.h index ed2d74d296..0e81db56a8 100644 --- a/library/cpp/coroutine/engine/stack/stack_common.h +++ b/library/cpp/coroutine/engine/stack/stack_common.h @@ -1,15 +1,15 @@ #pragma once -#include <cstdint> +#include <cstddef> class TContExecutor; namespace NCoro::NStack { - static constexpr uint64_t PageSize = 4096; - static constexpr uint64_t PageSizeMask = PageSize - 1; // for checks - static constexpr uint64_t DebugOrSanStackMultiplier = 4; // for debug or sanitizer builds - static constexpr uint64_t SmallStackMaxSizeInPages = 6; + static constexpr size_t PageSize = 4096; + static constexpr size_t PageSizeMask = PageSize - 1; // for checks + static constexpr size_t DebugOrSanStackMultiplier = 4; // for debug or sanitizer builds + static constexpr size_t SmallStackMaxSizeInPages = 6; enum class EGuard { Canary, //!< writes some data to check it for corruption @@ -17,19 +17,19 @@ namespace NCoro::NStack { }; struct TPoolAllocatorSettings { - uint64_t RssPagesToKeep = 1; - uint64_t SmallStackRssPagesToKeep = 1; // for stack less than SmallStackMaxSizeInPages - uint64_t ReleaseRate = 2; + size_t RssPagesToKeep = 1; + size_t SmallStackRssPagesToKeep = 1; // for stack less than SmallStackMaxSizeInPages + size_t ReleaseRate = 2; #if !defined(_san_enabled_) && defined(NDEBUG) - uint64_t StacksPerChunk = 256; + size_t StacksPerChunk = 256; #else - uint64_t StacksPerChunk = 2; + size_t StacksPerChunk = 2; #endif }; struct TAllocatorStats { - uint64_t ReleasedSize = 0; - uint64_t NotReleasedSize = 0; - uint64_t NumOfAllocated = 0; + size_t ReleasedSize = 0; + size_t NotReleasedSize = 0; + size_t NumOfAllocated = 0; }; } diff --git a/library/cpp/coroutine/engine/stack/stack_guards.h b/library/cpp/coroutine/engine/stack/stack_guards.h index 3a7ef26481..f22000b152 100644 --- a/library/cpp/coroutine/engine/stack/stack_guards.h +++ b/library/cpp/coroutine/engine/stack/stack_guards.h @@ -20,24 +20,24 @@ namespace NCoro::NStack { class TCanaryGuard final { public: //! Size of guard section in bytes - static constexpr uint64_t GetSize() { return Canary.size(); } + static constexpr size_t GetSize() { return Canary.size(); } //! Size of page-aligned guard section in bytes - static constexpr uint64_t GetPageAlignedSize() { return AlignedSize_; } + static constexpr size_t GetPageAlignedSize() { return AlignedSize_; } //! Get stack memory between guard sections - static TArrayRef<char> GetWorkspace(void* stack, uint64_t size) noexcept { - Y_ASSERT( !((uint64_t)stack & PageSizeMask) ); + static TArrayRef<char> GetWorkspace(void* stack, size_t size) noexcept { + Y_ASSERT( !((size_t)stack & PageSizeMask) ); Y_ASSERT( !(size & PageSizeMask) ); Y_ASSERT(size > Canary.size()); - return {(char*) stack, size - Canary.size()}; + return {(char*)stack, size - Canary.size()}; } /*! Set guard section before the end of stack memory (at stack + size - guard size position) * checkPrevious: check guard before stack memory for integrity */ - static void Protect(void* stack, uint64_t size, bool checkPrevious) noexcept { - Y_ASSERT( !((uint64_t)stack & PageSizeMask) ); // stack pointer should be page aligned + static void Protect(void* stack, size_t size, bool checkPrevious) noexcept { + Y_ASSERT( !((size_t)stack & PageSizeMask) ); // stack pointer should be page aligned Y_ASSERT( !(size & PageSizeMask) ); // stack size should be page aligned Y_ASSERT(size >= Canary.size()); // stack should have enough space to place guard @@ -49,29 +49,29 @@ namespace NCoro::NStack { } //! This guard doesn't change memory flags - static constexpr void RemoveProtection(void*, uint64_t) {} + static constexpr void RemoveProtection(void*, size_t) {} //! Should remove protection before returning memory to system static constexpr bool ShouldRemoveProtectionBeforeFree() { return false; } static bool CheckOverflow(void* stack) noexcept { Y_ASSERT(stack); - char* guardPos = (char*) ((uint64_t)stack - Canary.size()); + char* guardPos = (char*) ((size_t)stack - Canary.size()); return TStringBuf(guardPos, Canary.size()) == Canary; } - static bool CheckOverride(void* stack, uint64_t size) noexcept { + static bool CheckOverride(void* stack, size_t size) noexcept { Y_ASSERT(stack); Y_ASSERT(size > Canary.size()); - char* guardPos = (char*) ((uint64_t)stack + size - Canary.size()); + char* guardPos = (char*) ((size_t)stack + size - Canary.size()); return TStringBuf(guardPos, Canary.size()) == Canary; } private: static constexpr TStringBuf Canary = "[ThisIsACanaryCoroutineStackGuardIfYouReadThisTheStackIsStillOK]"; static_assert(Canary.size() == 64); - static constexpr uint64_t AlignedSize_ = (Canary.size() + PageSize - 1) & ~PageSizeMask; + static constexpr size_t AlignedSize_ = (Canary.size() + PageSize - 1) & ~PageSizeMask; }; @@ -81,20 +81,20 @@ namespace NCoro::NStack { class TPageGuard final { public: //! Size of guard section in bytes - static constexpr uint64_t GetSize() { return PageSize; } + static constexpr size_t GetSize() { return PageSize; } //! Size of page-aligned guard section in bytes - static constexpr uint64_t GetPageAlignedSize() { return PageSize; } + static constexpr size_t GetPageAlignedSize() { return PageSize; } - static TArrayRef<char> GetWorkspace(void* stack, uint64_t size) noexcept { - Y_ASSERT( !((uint64_t)stack & PageSizeMask) ); + static TArrayRef<char> GetWorkspace(void* stack, size_t size) noexcept { + Y_ASSERT( !((size_t)stack & PageSizeMask) ); Y_ASSERT( !(size & PageSizeMask) ); Y_ASSERT(size > PageSize); return {(char*)stack, size - PageSize}; } - static void Protect(void* stack, uint64_t size, bool /*checkPrevious*/) noexcept { - Y_ASSERT( !((uint64_t)stack & PageSizeMask) ); // stack pointer should be page aligned + static void Protect(void* stack, size_t size, bool /*checkPrevious*/) noexcept { + Y_ASSERT( !((size_t)stack & PageSizeMask) ); // stack pointer should be page aligned Y_ASSERT( !(size & PageSizeMask) ); // stack size should be page aligned Y_ASSERT(size >= PageSize); // stack should have enough space to place guard @@ -102,8 +102,8 @@ namespace NCoro::NStack { } //! Remove protection, to allow stack memory be freed - static void RemoveProtection(void* stack, uint64_t size) noexcept { - Y_ASSERT( !((uint64_t)stack & PageSizeMask) ); + static void RemoveProtection(void* stack, size_t size) noexcept { + Y_ASSERT( !((size_t)stack & PageSizeMask) ); Y_ASSERT( !(size & PageSizeMask) ); Y_ASSERT(size >= PageSize); @@ -114,7 +114,7 @@ namespace NCoro::NStack { //! For page guard is not used - it crashes process at once in this case. static constexpr bool CheckOverflow(void*) { return true; } - static constexpr bool CheckOverride(void*, uint64_t) { return true; } + static constexpr bool CheckOverride(void*, size_t) { return true; } }; diff --git a/library/cpp/coroutine/engine/stack/stack_pool.h b/library/cpp/coroutine/engine/stack/stack_pool.h index 27a8e9394b..d9b38e0ac3 100644 --- a/library/cpp/coroutine/engine/stack/stack_pool.h +++ b/library/cpp/coroutine/engine/stack/stack_pool.h @@ -21,16 +21,16 @@ namespace NCoro::NStack { char* Aligned = nullptr; // points to aligned memory, which includes space for first page guard }; public: - TPool(uint64_t stackSize, const TPoolAllocatorSettings& settings, const TGuard& guard); + TPool(size_t stackSize, const TPoolAllocatorSettings& settings, const TGuard& guard); TPool(TPool&& other) noexcept; ~TPool(); NDetails::TStack AllocStack(const char* name); void FreeStack(NDetails::TStack& stack); - uint64_t GetReleasedSize() const noexcept; - uint64_t GetFullSize() const noexcept; - uint64_t GetNumOfAllocated() const noexcept { return NumOfAllocated_; } + size_t GetReleasedSize() const noexcept; + size_t GetFullSize() const noexcept; + size_t GetNumOfAllocated() const noexcept { return NumOfAllocated_; } private: void AllocNewMemoryChunk(); @@ -39,14 +39,14 @@ namespace NCoro::NStack { NDetails::TStack AllocNewStack(const char* name); private: - const uint64_t StackSize_ = 0; - uint64_t RssPagesToKeep_ = 0; + const size_t StackSize_ = 0; + size_t RssPagesToKeep_ = 0; const TGuard& Guard_; TVector<TMemory> Memory_; // memory chunks THolder<TStorage> Storage_; char* NextToAlloc_ = nullptr; // points to next available stack in the last memory chunk - const uint64_t ChunkSize_ = 0; - uint64_t NumOfAllocated_ = 0; + const size_t ChunkSize_ = 0; + size_t NumOfAllocated_ = 0; }; } diff --git a/library/cpp/coroutine/engine/stack/stack_pool.inl b/library/cpp/coroutine/engine/stack/stack_pool.inl index 6e08e05a48..503e75664e 100644 --- a/library/cpp/coroutine/engine/stack/stack_pool.inl +++ b/library/cpp/coroutine/engine/stack/stack_pool.inl @@ -5,7 +5,7 @@ namespace NCoro::NStack { template<typename TGuard> - TPool<TGuard>::TPool(uint64_t stackSize, const TPoolAllocatorSettings& settings, const TGuard& guard) + TPool<TGuard>::TPool(size_t stackSize, const TPoolAllocatorSettings& settings, const TGuard& guard) : StackSize_(stackSize) , RssPagesToKeep_(IsSmallStack() ? settings.SmallStackRssPagesToKeep : settings.RssPagesToKeep) , Guard_(guard) @@ -16,7 +16,7 @@ namespace NCoro::NStack { RssPagesToKeep_ = 1; // at least guard should be kept } - const uint64_t stackSizeInPages = stackSize / PageSize; + const size_t stackSizeInPages = stackSize / PageSize; Y_ASSERT(stackSizeInPages >= RssPagesToKeep_); if (stackSizeInPages < RssPagesToKeep_) { RssPagesToKeep_ = stackSizeInPages; // keep all stack pages @@ -77,17 +77,17 @@ namespace NCoro::NStack { } template<typename TGuard> - uint64_t TPool<TGuard>::GetReleasedSize() const noexcept { + size_t TPool<TGuard>::GetReleasedSize() const noexcept { return Storage_->GetReleasedSize(); } template<typename TGuard> - uint64_t TPool<TGuard>::GetFullSize() const noexcept { + size_t TPool<TGuard>::GetFullSize() const noexcept { return Storage_->GetFullSize(); } template<typename TGuard> void TPool<TGuard>::AllocNewMemoryChunk() { - const uint64_t totalSizeInPages = ChunkSize_ / PageSize; + const size_t totalSizeInPages = ChunkSize_ / PageSize; TMemory memory; const auto res = GetAlignedMemory(totalSizeInPages, memory.Raw, memory.Aligned); diff --git a/library/cpp/coroutine/engine/stack/stack_storage.cpp b/library/cpp/coroutine/engine/stack/stack_storage.cpp index 6dc2b2d44b..121c1f5b0f 100644 --- a/library/cpp/coroutine/engine/stack/stack_storage.cpp +++ b/library/cpp/coroutine/engine/stack/stack_storage.cpp @@ -8,7 +8,7 @@ namespace NCoro::NStack { - TStorage::TStorage(uint64_t stackSize, uint64_t rssPagesToKeep, uint64_t releaseRate) + TStorage::TStorage(size_t stackSize, size_t rssPagesToKeep, size_t releaseRate) : StackSize_(stackSize) , RssPagesToKeep_(rssPagesToKeep) , ReleaseRate_(releaseRate ? releaseRate : 1) @@ -20,12 +20,12 @@ namespace NCoro::NStack { return Released_.empty() && Full_.empty(); } - uint64_t TStorage::Size() const noexcept { + size_t TStorage::Size() const noexcept { return Released_.size() + Full_.size(); } void TStorage::ReturnStack(NDetails::TStack& stack) { - thread_local uint64_t i = 0; + thread_local size_t i = 0; if (++i % ReleaseRate_ != 0) { Full_.push_back(stack.GetAlignedMemory()); } else { @@ -35,9 +35,9 @@ namespace NCoro::NStack { stack.Reset(); } - void TStorage::ReleaseMemory([[maybe_unused]] char* alignedStackMemory, [[maybe_unused]] uint64_t pagesToKeep) noexcept { + void TStorage::ReleaseMemory([[maybe_unused]] char* alignedStackMemory, [[maybe_unused]] size_t pagesToKeep) noexcept { #if !defined(_san_enabled_) && defined(NDEBUG) - uint64_t numOfPagesToFree = StackSize_ / PageSize; + size_t numOfPagesToFree = StackSize_ / PageSize; numOfPagesToFree -= pagesToKeep; ReleaseRss(alignedStackMemory, numOfPagesToFree); #endif diff --git a/library/cpp/coroutine/engine/stack/stack_storage.h b/library/cpp/coroutine/engine/stack/stack_storage.h index 25fe2cfb17..8327ce6fe0 100644 --- a/library/cpp/coroutine/engine/stack/stack_storage.h +++ b/library/cpp/coroutine/engine/stack/stack_storage.h @@ -14,27 +14,27 @@ namespace NCoro::NStack { class TStorage final : private TMoveOnly { public: - TStorage(uint64_t stackSize, uint64_t rssPagesToKeep, uint64_t releaseRate); + TStorage(size_t stackSize, size_t rssPagesToKeep, size_t releaseRate); bool IsEmpty() const noexcept; - uint64_t Size() const noexcept; + size_t Size() const noexcept; - uint64_t GetReleasedSize() const noexcept { return Released_.size(); } - uint64_t GetFullSize() const noexcept { return Full_.size(); } + size_t GetReleasedSize() const noexcept { return Released_.size(); } + size_t GetFullSize() const noexcept { return Full_.size(); } template<typename TGuard> NDetails::TStack GetStack(const TGuard& guard, const char* name); void ReturnStack(NDetails::TStack& stack); private: - void ReleaseMemory(char* alignedStackMemory, uint64_t pagesToKeep) noexcept; + void ReleaseMemory(char* alignedStackMemory, size_t pagesToKeep) noexcept; private: TDeque<void*> Released_; //!< stacks memory with released RSS memory TDeque<void*> Full_; //!< stacks memory with RSS memory - uint64_t StackSize_ = 0; - uint64_t RssPagesToKeep_ = 0; - const uint64_t ReleaseRate_ = 1; + size_t StackSize_ = 0; + size_t RssPagesToKeep_ = 0; + const size_t ReleaseRate_ = 1; }; diff --git a/library/cpp/coroutine/engine/stack/stack_utils.cpp b/library/cpp/coroutine/engine/stack/stack_utils.cpp index 1548529b66..d3076be2c5 100644 --- a/library/cpp/coroutine/engine/stack/stack_utils.cpp +++ b/library/cpp/coroutine/engine/stack/stack_utils.cpp @@ -16,7 +16,7 @@ namespace NCoro::NStack { #ifdef _linux_ - bool GetAlignedMemory(uint64_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept { + bool GetAlignedMemory(size_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept { Y_ASSERT(sizeInPages); void* ptr = nullptr; @@ -25,18 +25,18 @@ namespace NCoro::NStack { return rawPtr && alignedPtr && !error; } #else - bool GetAlignedMemory(uint64_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept { + bool GetAlignedMemory(size_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept { Y_ASSERT(sizeInPages); rawPtr = (char*) malloc((sizeInPages + 1) * PageSize); // +1 in case result would be unaligned - alignedPtr = (char*)( ((uint64_t)rawPtr + PageSize - 1) & ~PageSizeMask); + alignedPtr = (char*)( ((size_t)rawPtr + PageSize - 1) & ~PageSizeMask); return rawPtr && alignedPtr; } #endif #ifdef _linux_ - void ReleaseRss(char* alignedPtr, uint64_t numOfPages) noexcept { - Y_VERIFY( !((uint64_t)alignedPtr & PageSizeMask), "Not aligned pointer to release RSS memory"); + void ReleaseRss(char* alignedPtr, size_t numOfPages) noexcept { + Y_VERIFY( !((size_t)alignedPtr & PageSizeMask), "Not aligned pointer to release RSS memory"); if (!numOfPages) { return; } @@ -45,16 +45,16 @@ namespace NCoro::NStack { } } #else - void ReleaseRss(char*, uint64_t) noexcept { + void ReleaseRss(char*, size_t) noexcept { } #endif #ifdef _linux_ - uint64_t CountMapped(char* alignedPtr, uint64_t numOfPages) noexcept { - Y_VERIFY( !((uint64_t)alignedPtr & PageSizeMask) ); + size_t CountMapped(char* alignedPtr, size_t numOfPages) noexcept { + Y_VERIFY( !((size_t)alignedPtr & PageSizeMask) ); Y_ASSERT(numOfPages); - uint64_t result = 0; + size_t result = 0; unsigned char* mappedPages = (unsigned char*) calloc(numOfPages, numOfPages); Y_VERIFY(mappedPages); Y_DEFER { @@ -62,7 +62,7 @@ namespace NCoro::NStack { }; if (!mincore((void*)alignedPtr, numOfPages * PageSize, mappedPages)) { - for (uint64_t i = 0; i < numOfPages; ++i) { + for (size_t i = 0; i < numOfPages; ++i) { if (mappedPages[i] & 1) { ++result; } @@ -76,7 +76,7 @@ namespace NCoro::NStack { } #else - uint64_t CountMapped(char*, uint64_t) noexcept { + size_t CountMapped(char*, size_t) noexcept { return 0; // stub for Windows tests } #endif diff --git a/library/cpp/coroutine/engine/stack/stack_utils.h b/library/cpp/coroutine/engine/stack/stack_utils.h index 46c65240b5..d5d6ef9e98 100644 --- a/library/cpp/coroutine/engine/stack/stack_utils.h +++ b/library/cpp/coroutine/engine/stack/stack_utils.h @@ -10,18 +10,18 @@ namespace NCoro::NStack { * @param alignedPtr : pointer to beginning of first fully allocated page * @return : true on success */ - bool GetAlignedMemory(uint64_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept; + bool GetAlignedMemory(size_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept; /*! Release mapped RSS memory. * @param alignedPt : page-size aligned memory on which RSS memory should be freed * @param numOfPages : number of pages to free from RSS memory */ - void ReleaseRss(char* alignedPtr, uint64_t numOfPages) noexcept; + void ReleaseRss(char* alignedPtr, size_t numOfPages) noexcept; /*! Count pages with RSS memory * @param alignedPtr : pointer to page-aligned memory for which calculations would be done * @param numOfPages : number of pages to check * @return : number of pages with RSS memory */ - uint64_t CountMapped(char* alignedPtr, uint64_t numOfPages) noexcept; + size_t CountMapped(char* alignedPtr, size_t numOfPages) noexcept; } diff --git a/library/cpp/coroutine/engine/stack/ut/stack_allocator_ut.cpp b/library/cpp/coroutine/engine/stack/ut/stack_allocator_ut.cpp index a7283d44a3..f828793721 100644 --- a/library/cpp/coroutine/engine/stack/ut/stack_allocator_ut.cpp +++ b/library/cpp/coroutine/engine/stack/ut/stack_allocator_ut.cpp @@ -33,7 +33,7 @@ namespace NCoro::NStack::Tests { TEST_P(TAllocatorParamFixture, StackAllocationAndRelease) { - uint64_t stackSize = PageSize * 12; + size_t stackSize = PageSize * 12; auto stack = Allocator_->AllocStack(stackSize, "test_stack"); #if defined(_san_enabled_) || !defined(NDEBUG) stackSize *= DebugOrSanStackMultiplier; @@ -41,10 +41,10 @@ namespace NCoro::NStack::Tests { // Correct stack should have EXPECT_EQ(stack.GetSize(), stackSize); // predefined size - EXPECT_FALSE((uint64_t)stack.GetAlignedMemory() & PageSizeMask); // aligned pointer + EXPECT_FALSE((size_t)stack.GetAlignedMemory() & PageSizeMask); // aligned pointer // Writable workspace auto workspace = Allocator_->GetStackWorkspace(stack.GetAlignedMemory(), stack.GetSize()); - for (uint64_t i = 0; i < workspace.size(); i += 512) { + for (size_t i = 0; i < workspace.size(); i += 512) { workspace[i] = 42; } EXPECT_TRUE(Allocator_->CheckStackOverflow(stack.GetAlignedMemory())); @@ -87,7 +87,7 @@ namespace NCoro::NStack::Tests { : Allocator_(GetAllocator<AllocatorType>(EGuard::Page)) {} - const uint64_t StackSize_ = PageSize * 2; + const size_t StackSize_ = PageSize * 2; THolder<IAllocator> Allocator_; }; diff --git a/library/cpp/coroutine/engine/stack/ut/stack_guards_ut.cpp b/library/cpp/coroutine/engine/stack/ut/stack_guards_ut.cpp index 9da9a9b3d5..418ec56096 100644 --- a/library/cpp/coroutine/engine/stack/ut/stack_guards_ut.cpp +++ b/library/cpp/coroutine/engine/stack/ut/stack_guards_ut.cpp @@ -32,7 +32,7 @@ namespace NCoro::NStack::Tests { } TYPED_TEST(TGuardFixture, StackWorkspace) { - for (uint64_t sizeInPages : {2, 5, 12}) { + for (size_t sizeInPages : {2, 5, 12}) { char *rawPtr, *alignedPtr = nullptr; ASSERT_TRUE(GetAlignedMemory(sizeInPages, rawPtr, alignedPtr)); auto workspace = this->Guard_.GetWorkspace(alignedPtr, sizeInPages * PageSize); @@ -52,7 +52,7 @@ namespace NCoro::NStack::Tests { TYPED_TEST(TGuardFixture, SetRemoveProtectionWorks) { char *rawPtr, *alignedPtr = nullptr; - constexpr uint64_t sizeInPages = 4; + constexpr size_t sizeInPages = 4; ASSERT_TRUE(GetAlignedMemory(sizeInPages + 1, rawPtr, alignedPtr)); this->Guard_.Protect(alignedPtr, PageSize, false); // set previous guard @@ -72,7 +72,7 @@ namespace NCoro::NStack::Tests { const auto& guard = GetGuard<TCanaryGuard>(); char *rawPtr, *alignedPtr = nullptr; - constexpr uint64_t sizeInPages = 4; + constexpr size_t sizeInPages = 4; ASSERT_TRUE(GetAlignedMemory(sizeInPages + 1, rawPtr, alignedPtr)); guard.Protect(alignedPtr, PageSize, false); // set previous guard alignedPtr += PageSize; // leave first page for previous guard @@ -93,7 +93,7 @@ namespace NCoro::NStack::Tests { const auto& guard = GetGuard<TCanaryGuard>(); char *rawPtr, *alignedPtr = nullptr; - constexpr uint64_t sizeInPages = 4; + constexpr size_t sizeInPages = 4; ASSERT_TRUE(GetAlignedMemory(sizeInPages + 1, rawPtr, alignedPtr)); guard.Protect(alignedPtr, PageSize, false); // set previous guard alignedPtr += PageSize; // leave first page for previous guard @@ -116,7 +116,7 @@ namespace NCoro::NStack::Tests { char* rawPtr = nullptr; char* alignedPtr = nullptr; - constexpr uint64_t sizeInPages = 4; + constexpr size_t sizeInPages = 4; ASSERT_TRUE(GetAlignedMemory(sizeInPages + 1, rawPtr, alignedPtr)); guard.Protect(alignedPtr, PageSize, false); // set previous guard @@ -139,7 +139,7 @@ namespace NCoro::NStack::Tests { char* rawPtr = nullptr; char* alignedPtr = nullptr; - constexpr uint64_t sizeInPages = 4; + constexpr size_t sizeInPages = 4; ASSERT_TRUE(GetAlignedMemory(sizeInPages + 1, rawPtr, alignedPtr)); guard.Protect(alignedPtr, PageSize, false); // set previous guard alignedPtr += PageSize; // leave first page for previous guard diff --git a/library/cpp/coroutine/engine/stack/ut/stack_pool_ut.cpp b/library/cpp/coroutine/engine/stack/ut/stack_pool_ut.cpp index 9e3e5e7117..cec3f2ae56 100644 --- a/library/cpp/coroutine/engine/stack/ut/stack_pool_ut.cpp +++ b/library/cpp/coroutine/engine/stack/ut/stack_pool_ut.cpp @@ -13,7 +13,7 @@ namespace NCoro::NStack::Tests { protected: TPoolFixture() : Guard_(GetGuard<TGuard>()), Pool_(StackSize_, TPoolAllocatorSettings{1, 1, 8, 32}, Guard_) {} - const uint64_t StackSize_ = PageSize * 4; + const size_t StackSize_ = PageSize * 4; const TGuard& Guard_; TPool<TGuard> Pool_; }; diff --git a/library/cpp/coroutine/engine/stack/ut/stack_ut.cpp b/library/cpp/coroutine/engine/stack/ut/stack_ut.cpp index 31f8ad6b61..7b02d0cfd4 100644 --- a/library/cpp/coroutine/engine/stack/ut/stack_ut.cpp +++ b/library/cpp/coroutine/engine/stack/ut/stack_ut.cpp @@ -9,7 +9,7 @@ using namespace testing; namespace NCoro::NStack::Tests { - constexpr uint64_t StackSizeInPages = 4; + constexpr size_t StackSizeInPages = 4; template <class TGuard> class TStackFixture : public Test { @@ -34,7 +34,7 @@ namespace NCoro::NStack::Tests { protected: // data const TGuard& Guard_; - const uint64_t StackSize_ = 0; + const size_t StackSize_ = 0; char* RawMemory_ = nullptr; char* AlignedMemory_ = nullptr; THolder<NDetails::TStack> Stack_; @@ -51,7 +51,7 @@ namespace NCoro::NStack::Tests { TYPED_TEST(TStackFixture, WriteStack) { auto workspace = this->Guard_.GetWorkspace(this->Stack_->GetAlignedMemory(), this->Stack_->GetSize()); - for (uint64_t i = 0; i < workspace.size(); i += 512) { + for (size_t i = 0; i < workspace.size(); i += 512) { workspace[i] = 42; } EXPECT_TRUE(this->Guard_.CheckOverride(this->Stack_->GetAlignedMemory(), this->Stack_->GetSize())); diff --git a/library/cpp/coroutine/engine/stack/ut/stack_utils_ut.cpp b/library/cpp/coroutine/engine/stack/ut/stack_utils_ut.cpp index dc0593dcf2..8ef895dcf0 100644 --- a/library/cpp/coroutine/engine/stack/ut/stack_utils_ut.cpp +++ b/library/cpp/coroutine/engine/stack/ut/stack_utils_ut.cpp @@ -9,11 +9,11 @@ namespace NCoro::NStack::Tests { TEST(StackUtilsTest, Allocation) { char *rawPtr, *alignedPtr = nullptr; - for (uint64_t i : {1, 2, 3, 4, 11}) { + for (size_t i : {1, 2, 3, 4, 11}) { EXPECT_TRUE(GetAlignedMemory(i, rawPtr, alignedPtr)); EXPECT_TRUE(rawPtr); EXPECT_TRUE(alignedPtr); - EXPECT_FALSE((uint64_t)alignedPtr & PageSizeMask); + EXPECT_FALSE((size_t)alignedPtr & PageSizeMask); free(rawPtr); } } @@ -22,11 +22,11 @@ namespace NCoro::NStack::Tests { TEST(StackUtilsTest, RssReleaseOnePage) { char *rawPtr, *alignedPtr = nullptr; - for (uint64_t i : {1, 2, 8}) { + for (size_t i : {1, 2, 8}) { EXPECT_TRUE(GetAlignedMemory(i, rawPtr, alignedPtr)); EXPECT_TRUE(rawPtr); EXPECT_TRUE(alignedPtr); - EXPECT_FALSE((uint64_t)alignedPtr & PageSizeMask); + EXPECT_FALSE((size_t)alignedPtr & PageSizeMask); ReleaseRss(alignedPtr, i); // allocator can provide reused memory with RSS memory on it EXPECT_EQ(CountMapped(alignedPtr, i), 0ul); // no RSS memory allocated @@ -44,21 +44,21 @@ namespace NCoro::NStack::Tests { TEST(StackUtilsTest, RssReleaseSeveralPages) { char *rawPtr, *alignedPtr = nullptr; - for (uint64_t i : {1, 2, 5, 8}) { + for (size_t i : {1, 2, 5, 8}) { EXPECT_TRUE(GetAlignedMemory(i, rawPtr, alignedPtr)); EXPECT_TRUE(rawPtr); EXPECT_TRUE(alignedPtr); - EXPECT_FALSE((uint64_t)alignedPtr & PageSizeMask); + EXPECT_FALSE((size_t)alignedPtr & PageSizeMask); ReleaseRss(alignedPtr, i); // allocator can provide reused memory with RSS memory on it EXPECT_EQ(CountMapped(alignedPtr, i), 0ul); // no RSS memory allocated - for (uint64_t page = 0; page < i; ++page) { + for (size_t page = 0; page < i; ++page) { *(alignedPtr + page * PageSize) = 42; // map RSS memory EXPECT_EQ(CountMapped(alignedPtr, page + 1), page + 1); } - const uint64_t pagesToKeep = (i > 2) ? 2 : i; + const size_t pagesToKeep = (i > 2) ? 2 : i; ReleaseRss(alignedPtr, i - pagesToKeep); EXPECT_EQ(CountMapped(alignedPtr, i), pagesToKeep) << "number of pages " << i; // no RSS memory allocated |