add logging for memory allocation
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package mem
|
package mem
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
|
||||||
var pools []*sync.Pool
|
var pools []*sync.Pool
|
||||||
|
|
||||||
@@ -34,11 +38,17 @@ func getSlotPool(size int) *sync.Pool {
|
|||||||
return pools[index]
|
return pools[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var total int64
|
||||||
|
|
||||||
func Allocate(size int) []byte {
|
func Allocate(size int) []byte {
|
||||||
|
newVal := atomic.AddInt64(&total, 1)
|
||||||
|
glog.V(4).Infof("++> %d", newVal)
|
||||||
slab := *getSlotPool(size).Get().(*[]byte)
|
slab := *getSlotPool(size).Get().(*[]byte)
|
||||||
return slab[:size]
|
return slab[:size]
|
||||||
}
|
}
|
||||||
|
|
||||||
func Free(buf []byte) {
|
func Free(buf []byte) {
|
||||||
|
newVal := atomic.AddInt64(&total, -1)
|
||||||
|
glog.V(4).Infof("--> %d", newVal)
|
||||||
getSlotPool(cap(buf)).Put(&buf)
|
getSlotPool(cap(buf)).Put(&buf)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user