Skip to content

Commit

Permalink
Merge pull request #9786 from BohuTANG/dev-jemalloc-fallback
Browse files Browse the repository at this point in the history
fix(jemalloc): fix not linux and macos jemalloc fallback to std
  • Loading branch information
BohuTANG authored Jan 30, 2023
2 parents ac1ffef + d20e261 commit 6c6f2ea
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions src/common/base/src/mem_allocator/jemalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NonNull<[u8]>, AllocError> {
StdAllocator.allocate(layout)
}

#[inline(always)]
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
StdAllocator.allocate_zeroed(layout)
}

#[inline(always)]
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
StdAllocator.deallocate(ptr, layout)
}

unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
StdAllocator.grow(ptr, old_layout, new_layout)
}

unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
StdAllocator.grow_zeroed(ptr, old_layout, new_layout)
}

unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
StdAllocator.shrink(ptr, old_layout, new_layout)
}
}
}

1 comment on commit 6c6f2ea

@vercel
Copy link

@vercel vercel bot commented on 6c6f2ea Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-git-main-databend.vercel.app
databend-databend.vercel.app
databend.rs
databend.vercel.app

Please sign in to comment.