diff --git a/src/common/base/src/mem_allocator/jemalloc.rs b/src/common/base/src/mem_allocator/jemalloc.rs index 278c059bde499..1250390821055 100644 --- a/src/common/base/src/mem_allocator/jemalloc.rs +++ b/src/common/base/src/mem_allocator/jemalloc.rs @@ -20,8 +20,8 @@ #[derive(Debug, Clone, Copy, Default)] pub struct JEAllocator; -#[cfg(any(target_os = "linux", target_os = "macos"))] -pub mod linux_or_macos { +#[cfg(target_os = "linux")] +pub mod linux { use std::alloc::AllocError; use std::alloc::Allocator; use std::alloc::Layout; @@ -212,3 +212,59 @@ pub mod linux_or_macos { } } } + +/// Other target fallback to std allocator. +#[cfg(not(target_os = "linux"))] +pub mod not_linux { + use std::alloc::AllocError; + use std::alloc::Allocator; + use std::alloc::Layout; + use std::ptr::NonNull; + + use super::JEAllocator; + use crate::mem_allocator::StdAllocator; + + unsafe impl Allocator for JEAllocator { + #[inline(always)] + fn allocate(&self, layout: Layout) -> Result, AllocError> { + StdAllocator.allocate(layout) + } + + #[inline(always)] + fn allocate_zeroed(&self, layout: Layout) -> Result, AllocError> { + StdAllocator.allocate_zeroed(layout) + } + + #[inline(always)] + unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { + StdAllocator.deallocate(ptr, layout) + } + + unsafe fn grow( + &self, + ptr: NonNull, + old_layout: Layout, + new_layout: Layout, + ) -> Result, AllocError> { + StdAllocator.grow(ptr, old_layout, new_layout) + } + + unsafe fn grow_zeroed( + &self, + ptr: NonNull, + old_layout: Layout, + new_layout: Layout, + ) -> Result, AllocError> { + StdAllocator.grow_zeroed(ptr, old_layout, new_layout) + } + + unsafe fn shrink( + &self, + ptr: NonNull, + old_layout: Layout, + new_layout: Layout, + ) -> Result, AllocError> { + StdAllocator.shrink(ptr, old_layout, new_layout) + } + } +}