LuciferYang opened a new pull request, #13360: URL: https://github.com/apache/gluten/pull/13360
## What changes are proposed in this pull request? `StdMemoryAllocator::reallocateAligned` shrinks a block with `std::realloc`, which only guarantees fundamental alignment. On macOS, realloc often moves the shrunk block to an address that is not a multiple of the requested alignment (64 for Arrow buffers), so `ArrowMemoryPool::Reallocate` can return a buffer that breaks the Arrow MemoryPool alignment contract. Linux glibc shrinks in place, so this has only been seen on macOS. After the shrink, if the result is not aligned, this allocates an aligned block of the same size and copies into it. The in-place case is unchanged, so the extra copy only happens when realloc moved the block to a misaligned address. If that allocation fails, the moved block is kept, because realloc has already released the original one. ## How was this patch tested? Added `StdMemoryAllocator.shrinkKeepsAlignment`, which shrinks a 1024-byte block to every multiple of 64 below it and checks alignment, contents and the byte count. It fails on macOS without this change. On Linux the shrink never moves to a misaligned address, so the new branch is only exercised on macOS, and the macOS weekly job builds the native tests but does not run them. On macOS, with native libraries that log misaligned shrinks, `VeloxTPCHV1Suite` and `VeloxTPCHV1GlutenShuffleManagerSuite` hit 354 misaligned shrinks before this change, none of which made a test fail. ## Was this patch authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Opus. Related issue: #13359. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
