diff --git a/src/common/base/src/mem_allocator/mmap.rs b/src/common/base/src/mem_allocator/mmap.rs index 9fbffa6f7ab6e..b1cc700599e55 100644 --- a/src/common/base/src/mem_allocator/mmap.rs +++ b/src/common/base/src/mem_allocator/mmap.rs @@ -16,17 +16,20 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +use crate::mem_allocator::JEAllocator; + /// mmap allocator. -/// This is used for some hash tables. -/// T is a fallback inner allocator for some memory special case. +/// For better performance, we use jemalloc as the inner allocator. #[derive(Debug, Clone, Copy, Default)] -pub struct MmapAllocator { - allocator: T, +pub struct MmapAllocator { + allocator: JEAllocator, } -impl MmapAllocator { - pub fn new(allocator: T) -> Self { - Self { allocator } +impl MmapAllocator { + pub fn new() -> Self { + Self { + allocator: JEAllocator::default(), + } } } @@ -46,7 +49,7 @@ pub mod linux { const THRESHOLD: usize = 64 << 20; - impl MmapAllocator { + impl MmapAllocator { #[inline(always)] fn mmap_alloc(&self, layout: Layout) -> Result, AllocError> { debug_assert!(layout.align() <= page_size()); @@ -128,7 +131,7 @@ pub mod linux { } } - unsafe impl Allocator for MmapAllocator { + unsafe impl Allocator for MmapAllocator { #[inline(always)] fn allocate(&self, layout: Layout) -> Result, AllocError> { if layout.align() > page_size() { @@ -310,7 +313,7 @@ pub mod not_linux { use super::MmapAllocator; - unsafe impl Allocator for MmapAllocator { + unsafe impl Allocator for MmapAllocator { #[inline(always)] fn allocate(&self, layout: Layout) -> Result, AllocError> { self.allocator.allocate(layout) diff --git a/src/common/hashtable/src/hashtable.rs b/src/common/hashtable/src/hashtable.rs index b4594388e3c27..4e6455373dc25 100644 --- a/src/common/hashtable/src/hashtable.rs +++ b/src/common/hashtable/src/hashtable.rs @@ -16,7 +16,6 @@ use std::alloc::Allocator; use std::intrinsics::unlikely; use std::mem::MaybeUninit; -use common_base::mem_allocator::GlobalAllocator; use common_base::mem_allocator::MmapAllocator; use super::container::HeapContainer; @@ -29,7 +28,7 @@ use super::traits::Keyable; use super::utils::ZeroEntry; use crate::FastHash; -pub struct Hashtable> +pub struct Hashtable where K: Keyable, A: Allocator + Clone, diff --git a/src/common/hashtable/src/lookup_hashtable.rs b/src/common/hashtable/src/lookup_hashtable.rs index bba0f8af93a74..45ee54427f686 100644 --- a/src/common/hashtable/src/lookup_hashtable.rs +++ b/src/common/hashtable/src/lookup_hashtable.rs @@ -16,18 +16,13 @@ use std::alloc::Allocator; use std::mem; use std::mem::MaybeUninit; -use common_base::mem_allocator::GlobalAllocator; use common_base::mem_allocator::MmapAllocator; use crate::table0::Entry; use crate::HashtableLike; -pub struct LookupHashtable< - K: Sized, - const CAPACITY: usize, - V, - A: Allocator + Clone = MmapAllocator, -> { +pub struct LookupHashtable +{ flags: Box<[bool; CAPACITY], A>, data: Box<[Entry; CAPACITY], A>, len: usize, diff --git a/src/common/hashtable/src/short_string_hashtable.rs b/src/common/hashtable/src/short_string_hashtable.rs index 4a7954044b6e6..a65d57597605a 100644 --- a/src/common/hashtable/src/short_string_hashtable.rs +++ b/src/common/hashtable/src/short_string_hashtable.rs @@ -19,7 +19,6 @@ use std::num::NonZeroU64; use std::ptr::NonNull; use bumpalo::Bump; -use common_base::mem_allocator::GlobalAllocator; use common_base::mem_allocator::MmapAllocator; use super::container::HeapContainer; @@ -38,7 +37,7 @@ use crate::table_empty::TableEmpty; use crate::table_empty::TableEmptyIter; use crate::table_empty::TableEmptyIterMut; -pub struct ShortStringHashtable> +pub struct ShortStringHashtable where K: UnsizedKeyable + ?Sized, A: Allocator + Clone, diff --git a/src/common/hashtable/src/stack_hashtable.rs b/src/common/hashtable/src/stack_hashtable.rs index 98b673d5563ca..5e58a9fd19388 100644 --- a/src/common/hashtable/src/stack_hashtable.rs +++ b/src/common/hashtable/src/stack_hashtable.rs @@ -16,7 +16,6 @@ use std::alloc::Allocator; use std::intrinsics::unlikely; use std::mem::MaybeUninit; -use common_base::mem_allocator::GlobalAllocator; use common_base::mem_allocator::MmapAllocator; use super::container::StackContainer; @@ -27,7 +26,7 @@ use super::table0::Table0IterMut; use super::traits::Keyable; use super::utils::ZeroEntry; -pub struct StackHashtable> +pub struct StackHashtable where K: Keyable, A: Allocator + Clone, diff --git a/src/common/hashtable/src/string_hashtable.rs b/src/common/hashtable/src/string_hashtable.rs index 3cab512c116b9..5af6f4d6b9b21 100644 --- a/src/common/hashtable/src/string_hashtable.rs +++ b/src/common/hashtable/src/string_hashtable.rs @@ -17,7 +17,6 @@ use std::marker::PhantomData; use std::mem::MaybeUninit; use bumpalo::Bump; -use common_base::mem_allocator::GlobalAllocator; use common_base::mem_allocator::MmapAllocator; use super::container::HeapContainer; @@ -37,7 +36,7 @@ use crate::table_empty::TableEmptyIterMut; /// Simple unsized hashtable is used for storing unsized keys in arena. It can be worked with HashMethodSerializer. /// Different from `ShortStringHashTable`, it doesn't use adpative sub hashtable to store key values via key size. /// It can be considered as a minimal hashtable implementation of ShortStringHashTable -pub struct StringHashtable> +pub struct StringHashtable where K: UnsizedKeyable + ?Sized, A: Allocator + Clone,