github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/common/mpool.go (about)

     1  // Copyright 2021 - 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // A few allocators for TAE
    16  package common
    17  
    18  import (
    19  	"sync"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    22  )
    23  
    24  // A few allocators for TAE
    25  var DefaultAllocator *mpool.MPool
    26  var MutMemAllocator *mpool.MPool
    27  var SmallAllocator *mpool.MPool
    28  var LogtailAllocator *mpool.MPool
    29  var CheckpointAllocator *mpool.MPool
    30  var MergeAllocator *mpool.MPool
    31  var WorkspaceAllocator *mpool.MPool
    32  var DebugAllocator *mpool.MPool
    33  
    34  // init with zero fixed pool, for test.
    35  func init() {
    36  	InitTAEMPool()
    37  }
    38  
    39  // tn service call this during start up, to get a real cached pool.
    40  var once sync.Once
    41  
    42  func InitTAEMPool() {
    43  	onceBody := func() {
    44  		var err error
    45  		mpool.DeleteMPool(DefaultAllocator)
    46  		if DefaultAllocator, err = mpool.NewMPool("tae_default", 0, mpool.NoFixed); err != nil {
    47  			panic(err)
    48  		}
    49  
    50  		mpool.DeleteMPool(MutMemAllocator)
    51  		if MutMemAllocator, err = mpool.NewMPool("tae_mutable", 0, mpool.NoFixed); err != nil {
    52  			panic(err)
    53  		}
    54  
    55  		mpool.DeleteMPool(SmallAllocator)
    56  		if SmallAllocator, err = mpool.NewMPool("tae_small", 0, mpool.NoFixed); err != nil {
    57  			panic(err)
    58  		}
    59  
    60  		mpool.DeleteMPool(LogtailAllocator)
    61  		if LogtailAllocator, err = mpool.NewMPool("tae_logtail", 0, mpool.NoFixed); err != nil {
    62  			panic(err)
    63  		}
    64  
    65  		mpool.DeleteMPool(CheckpointAllocator)
    66  		if CheckpointAllocator, err = mpool.NewMPool("tae_checkpoint", 0, mpool.NoFixed); err != nil {
    67  			panic(err)
    68  		}
    69  
    70  		mpool.DeleteMPool(MergeAllocator)
    71  		if MergeAllocator, err = mpool.NewMPool("tae_merge", 0, mpool.NoFixed); err != nil {
    72  			panic(err)
    73  		}
    74  
    75  		mpool.DeleteMPool(WorkspaceAllocator)
    76  		if WorkspaceAllocator, err = mpool.NewMPool("tae_workspace", 0, mpool.NoFixed); err != nil {
    77  			panic(err)
    78  		}
    79  
    80  		mpool.DeleteMPool(DebugAllocator)
    81  		if DebugAllocator, err = mpool.NewMPool("tae_debug", 0, mpool.NoFixed); err != nil {
    82  			panic(err)
    83  		}
    84  	}
    85  	once.Do(onceBody)
    86  }