Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

avoid pool memory allocation if too large

chrislu784583afc651
diff --git a/weed/util/mem/slot_pool.go b/weed/util/mem/slot_pool.go
index f7aa86e058..b3493febf2 100644
--- a/weed/util/mem/slot_pool.go
+++ b/weed/util/mem/slot_pool.go
@@ -33,17 +33,18 @@ func init() {
}
}
-func getSlotPool(size int) *sync.Pool {
+func getSlotPool(size int) (*sync.Pool, bool) {
index := bitCount(size)
- return pools[index]
+ if index >= len(pools) {
+ return nil, false
+ }
+ return pools[index], true
}
var total int64
func Allocate(size int) []byte {
- pool := getSlotPool(size)
- if pool != nil {
-
+ if pool, found := getSlotPool(size); found {
newVal := atomic.AddInt64(&total, 1)
glog.V(4).Infof("++> %d", newVal)
@@ -54,8 +55,7 @@ func Allocate(size int) []byte {
}
func Free(buf []byte) {
- pool := getSlotPool(cap(buf))
- if pool != nil {
+ if pool, found := getSlotPool(cap(buf)); found {
newVal := atomic.AddInt64(&total, -1)
glog.V(4).Infof("--> %d", newVal)
pool.Put(&buf)