@@ -38,7 +38,6 @@ func WithMinCanarySize(size int) SlabOption {
3838// Memory allocator implementation
3939type slabAllocator struct {
4040 maxSlabSize int
41- stats * MemStats
4241 cfg * SlabAllocatorConfig
4342 allocator * pageAllocator
4443 slabs []* slab
@@ -61,18 +60,15 @@ func NewSlabAllocator(options ...SlabOption) MemAllocator {
6160 // Setup the allocator and initialize the slabs
6261 a := & slabAllocator {
6362 maxSlabSize : cfg .Sizes [len (cfg .Sizes )- 1 ],
64- stats : & MemStats {},
6563 cfg : cfg ,
6664 slabs : make ([]* slab , 0 , len (cfg .Sizes )),
6765 allocator : & pageAllocator {
6866 objects : make (map [int ]* pageObject ),
69- stats : & MemStats {},
7067 },
7168 }
7269 for _ , size := range cfg .Sizes {
7370 s := & slab {
7471 objSize : size ,
75- stats : a .stats ,
7672 allocator : a .allocator ,
7773 }
7874 a .slabs = append (a .slabs , s )
@@ -177,10 +173,6 @@ func (a *slabAllocator) Free(buf []byte) error {
177173 return s .free (buf )
178174}
179175
180- func (a * slabAllocator ) Stats () * MemStats {
181- return a .stats
182- }
183-
184176// *** INTERNAL FUNCTIONS *** //
185177
186178// Page implementation
@@ -232,7 +224,6 @@ func newPage(page []byte, size int) *slabPage {
232224// Slab is a container for all Pages serving the same size
233225type slab struct {
234226 objSize int
235- stats * MemStats
236227 allocator * pageAllocator
237228 pages []* slabPage
238229 sync.Mutex
@@ -255,10 +246,8 @@ func (s *slab) alloc(size int) ([]byte, error) {
255246 // Use the page allocator to get a new guarded memory page
256247 page , err := s .allocator .Alloc (pageSize - s .objSize )
257248 if err != nil {
258- s .stats .PageAllocErrors .Add (1 )
259249 return nil , err
260250 }
261- s .stats .PageAllocs .Store (s .allocator .stats .PageAllocs .Load ())
262251 c = newPage (page , s .objSize )
263252 s .pages = append (s .pages , c )
264253 }
@@ -268,7 +257,6 @@ func (s *slab) alloc(size int) ([]byte, error) {
268257 c .head = c .head .next
269258 c .used ++
270259
271- s .stats .ObjectAllocs .Add (1 )
272260 data := getBufferPart (c .buffer , obj .offset , size )
273261 canary := getBufferPart (c .buffer , obj .offset + size , s .objSize - size )
274262
@@ -309,11 +297,8 @@ func (s *slab) free(buf []byte) error {
309297 return ErrBufferNotOwnedByAllocator
310298 }
311299
312- s .stats .ObjectFrees .Add (1 )
313-
314300 // Wipe the buffer including the canary check
315301 if err := s .wipe (c , offset , len (buf )); err != nil {
316- s .stats .ObjectFreeErrors .Add (1 )
317302 return err
318303 }
319304 obj := & slabObject {
@@ -327,9 +312,7 @@ func (s *slab) free(buf []byte) error {
327312 // free the underlying memory
328313 if c .used == 0 {
329314 err := s .allocator .Free (c .buffer )
330- s .stats .PageFrees .Store (s .allocator .stats .PageFrees .Load ())
331315 if err != nil {
332- s .stats .PageFreeErrors .Add (1 )
333316 return err
334317 }
335318
0 commit comments