diff options
| author | vvshlyaga <[email protected]> | 2025-12-04 16:01:47 +0300 |
|---|---|---|
| committer | vvshlyaga <[email protected]> | 2025-12-04 16:25:26 +0300 |
| commit | 2cf18d3189ca7cdac1ddbf73b5fc5aa3322a9f21 (patch) | |
| tree | 5e3b6bd04e5fff4c13443bcb0978eb34ecd1645d /library/cpp/yt/memory/ref.cpp | |
| parent | 3ff5af493bc114b64714938ac4fed7dddfb7c51b (diff) | |
YT-25976: fix blocks alignment in io requests
commit_hash:785d73458fcb036340236b123b33a6f3b0b1c1ce
Diffstat (limited to 'library/cpp/yt/memory/ref.cpp')
| -rw-r--r-- | library/cpp/yt/memory/ref.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/ref.cpp b/library/cpp/yt/memory/ref.cpp index fc153bb02e3..5a6ca1e3373 100644 --- a/library/cpp/yt/memory/ref.cpp +++ b/library/cpp/yt/memory/ref.cpp @@ -171,6 +171,44 @@ public: //////////////////////////////////////////////////////////////////////////////// +class TCustomAlignedAllocationHolder + : public TAllocationHolderBase<TCustomAlignedAllocationHolder> +{ +public: + TCustomAlignedAllocationHolder( + size_t size, + size_t alignment, + TSharedMutableRefAllocateOptions options, + TRefCountedTypeCookie cookie) + : Begin_(static_cast<char*>(::aligned_malloc(size, alignment))) + , Alignment_(alignment) + { + Initialize(size, options, cookie); + } + + ~TCustomAlignedAllocationHolder() + { + ::free(Begin_); + } + + char* GetBegin() + { + return Begin_; + } + + // TSharedRangeHolder overrides. + std::optional<size_t> GetTotalByteSize() const override + { + return AlignUp(Size_, Alignment_); + } + +private: + char* const Begin_; + size_t Alignment_; +}; + +//////////////////////////////////////////////////////////////////////////////// + class TPageAlignedAllocationHolder : public TAllocationHolderBase<TPageAlignedAllocationHolder> { @@ -311,6 +349,13 @@ TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t size, TSharedMut return TSharedMutableRef(ref, std::move(holder)); } +TSharedMutableRef TSharedMutableRef::AllocateAligned(size_t size, size_t alignment, TSharedMutableRefAllocateOptions options, TRefCountedTypeCookie tagCookie) +{ + auto holder = New<TCustomAlignedAllocationHolder>(size, alignment, options, tagCookie); + auto ref = holder->GetRef(); + return TSharedMutableRef(ref, std::move(holder)); +} + TSharedMutableRef TSharedMutableRef::FromBlob(TBlob&& blob) { auto ref = TMutableRef::FromBlob(blob); |
