From 2cf18d3189ca7cdac1ddbf73b5fc5aa3322a9f21 Mon Sep 17 00:00:00 2001 From: vvshlyaga Date: Thu, 4 Dec 2025 16:01:47 +0300 Subject: YT-25976: fix blocks alignment in io requests commit_hash:785d73458fcb036340236b123b33a6f3b0b1c1ce --- library/cpp/yt/memory/ref.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'library/cpp/yt/memory/ref.cpp') 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 +{ +public: + TCustomAlignedAllocationHolder( + size_t size, + size_t alignment, + TSharedMutableRefAllocateOptions options, + TRefCountedTypeCookie cookie) + : Begin_(static_cast(::aligned_malloc(size, alignment))) + , Alignment_(alignment) + { + Initialize(size, options, cookie); + } + + ~TCustomAlignedAllocationHolder() + { + ::free(Begin_); + } + + char* GetBegin() + { + return Begin_; + } + + // TSharedRangeHolder overrides. + std::optional GetTotalByteSize() const override + { + return AlignUp(Size_, Alignment_); + } + +private: + char* const Begin_; + size_t Alignment_; +}; + +//////////////////////////////////////////////////////////////////////////////// + class TPageAlignedAllocationHolder : public TAllocationHolderBase { @@ -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(size, alignment, options, tagCookie); + auto ref = holder->GetRef(); + return TSharedMutableRef(ref, std::move(holder)); +} + TSharedMutableRef TSharedMutableRef::FromBlob(TBlob&& blob) { auto ref = TMutableRef::FromBlob(blob); -- cgit v1.3