github.com/matrixorigin/matrixone@v1.2.0/pkg/common/malloc/flush.go (about) 1 // Copyright 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 package malloc 16 17 import "time" 18 19 func init() { 20 go func() { 21 lastNumAllocs := make([]int64, numShards) 22 for range time.NewTicker(time.Second * 37).C { 23 for i := 0; i < numShards; i++ { 24 numAllocs := shards[i].numAlloc.Load() 25 if numAllocs == lastNumAllocs[i] { 26 // not active, flush 27 shards[i].flush() 28 } 29 lastNumAllocs[i] = numAllocs 30 } 31 } 32 }() 33 } 34 35 func (s *Shard) flush() { 36 for _, ch := range s.pools { 37 loop: 38 for { 39 select { 40 case <-ch: 41 default: 42 break loop 43 } 44 } 45 } 46 }