github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/xact/xs/pool_lso.go (about) 1 // Package xs is a collection of eXtended actions (xactions), including multi-object 2 // operations, list-objects, (cluster) rebalance and (target) resilver, ETL, and more. 3 /* 4 * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 5 */ 6 package xs 7 8 import ( 9 "sync" 10 11 "github.com/NVIDIA/aistore/api/apc" 12 "github.com/NVIDIA/aistore/cmn" 13 ) 14 15 const maxEntries = apc.MaxPageSizeAIS 16 17 var ( 18 lstPool sync.Pool 19 entry0 cmn.LsoEnt 20 ) 21 22 func allocLsoEntries() (entries cmn.LsoEntries) { 23 if v := lstPool.Get(); v != nil { 24 entries = *v.(*cmn.LsoEntries) 25 } 26 return 27 } 28 29 func freeLsoEntries(entries cmn.LsoEntries) { 30 // gc 31 l := min(len(entries), maxEntries) 32 entries = entries[:cap(entries)] 33 for i := l; i < cap(entries); i++ { 34 entries[i] = nil 35 } 36 // truncate 37 entries = entries[:l] 38 // cleanup 39 for _, e := range entries { 40 *e = entry0 41 } 42 // recycle 43 lstPool.Put(&entries) 44 }