github.com/matrixorigin/matrixone@v0.7.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 CacheAllocator *mpool.MPool
    28  var LogAllocator *mpool.MPool
    29  
    30  // init with zero fixed pool, for test.
    31  func init() {
    32  	InitTAEMPool()
    33  }
    34  
    35  // dn service call this during start up, to get a real cached pool.
    36  var once sync.Once
    37  
    38  func InitTAEMPool() {
    39  	onceBody := func() {
    40  		var err error
    41  		mpool.DeleteMPool(DefaultAllocator)
    42  		if DefaultAllocator, err = mpool.NewMPool("tae_default", 0, mpool.Large); err != nil {
    43  			panic(err)
    44  		}
    45  
    46  		mpool.DeleteMPool(MutMemAllocator)
    47  		if MutMemAllocator, err = mpool.NewMPool("tae_immutable", 0, mpool.Mid); err != nil {
    48  			panic(err)
    49  		}
    50  
    51  		mpool.DeleteMPool(CacheAllocator)
    52  		if CacheAllocator, err = mpool.NewMPool("tae_cache", 0, mpool.Large); err != nil {
    53  			panic(err)
    54  		}
    55  
    56  		mpool.DeleteMPool(LogAllocator)
    57  		if LogAllocator, err = mpool.NewMPool("tae_log", 0, mpool.Mid); err != nil {
    58  			panic(err)
    59  		}
    60  	}
    61  	once.Do(onceBody)
    62  }