mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
avoid pool memory allocation if too large
This commit is contained in:
parent
ba14307319
commit
784583afc6
|
@ -33,17 +33,18 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSlotPool(size int) *sync.Pool {
|
func getSlotPool(size int) (*sync.Pool, bool) {
|
||||||
index := bitCount(size)
|
index := bitCount(size)
|
||||||
return pools[index]
|
if index >= len(pools) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return pools[index], true
|
||||||
}
|
}
|
||||||
|
|
||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
func Allocate(size int) []byte {
|
func Allocate(size int) []byte {
|
||||||
pool := getSlotPool(size)
|
if pool, found := getSlotPool(size); found {
|
||||||
if pool != nil {
|
|
||||||
|
|
||||||
newVal := atomic.AddInt64(&total, 1)
|
newVal := atomic.AddInt64(&total, 1)
|
||||||
glog.V(4).Infof("++> %d", newVal)
|
glog.V(4).Infof("++> %d", newVal)
|
||||||
|
|
||||||
|
@ -54,8 +55,7 @@ func Allocate(size int) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Free(buf []byte) {
|
func Free(buf []byte) {
|
||||||
pool := getSlotPool(cap(buf))
|
if pool, found := getSlotPool(cap(buf)); found {
|
||||||
if pool != nil {
|
|
||||||
newVal := atomic.AddInt64(&total, -1)
|
newVal := atomic.AddInt64(&total, -1)
|
||||||
glog.V(4).Infof("--> %d", newVal)
|
glog.V(4).Infof("--> %d", newVal)
|
||||||
pool.Put(&buf)
|
pool.Put(&buf)
|
||||||
|
|
Loading…
Reference in a new issue