mirror of
https://github.com/pgsty/minio.git
synced 2026-03-16 17:53:43 +01:00
allow pre-allocating buffers to reduce frequent GCs during growth (#18686)
This PR also increases per node bpool memory from 1024 entries to 2048 entries; along with that, it also moves the byte pool centrally instead of being per pool.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2023 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package bpool
|
||||
|
||||
import "github.com/klauspost/reedsolomon"
|
||||
|
||||
// BytePoolCap implements a leaky pool of []byte in the form of a bounded channel.
|
||||
type BytePoolCap struct {
|
||||
c chan []byte
|
||||
@@ -27,6 +29,12 @@ type BytePoolCap struct {
|
||||
// NewBytePoolCap creates a new BytePool bounded to the given maxSize, with new
|
||||
// byte arrays sized based on width.
|
||||
func NewBytePoolCap(maxSize int, width int, capwidth int) (bp *BytePoolCap) {
|
||||
if capwidth > 0 && capwidth < 64 {
|
||||
panic("buffer capped with smaller than 64 bytes is not supported")
|
||||
}
|
||||
if capwidth > 0 && width > capwidth {
|
||||
panic("buffer length cannot be > capacity of the buffer")
|
||||
}
|
||||
return &BytePoolCap{
|
||||
c: make(chan []byte, maxSize),
|
||||
w: width,
|
||||
@@ -34,18 +42,25 @@ func NewBytePoolCap(maxSize int, width int, capwidth int) (bp *BytePoolCap) {
|
||||
}
|
||||
}
|
||||
|
||||
// Populate - populates and pre-warms the byte pool, this function is non-blocking.
|
||||
func (bp *BytePoolCap) Populate() {
|
||||
for _, buf := range reedsolomon.AllocAligned(cap(bp.c), bp.wcap) {
|
||||
bp.Put(buf[:bp.w])
|
||||
}
|
||||
}
|
||||
|
||||
// Get gets a []byte from the BytePool, or creates a new one if none are
|
||||
// available in the pool.
|
||||
func (bp *BytePoolCap) Get() (b []byte) {
|
||||
select {
|
||||
case b = <-bp.c:
|
||||
// reuse existing buffer
|
||||
// reuse existing buffer
|
||||
default:
|
||||
// create new buffer
|
||||
// create new aligned buffer
|
||||
if bp.wcap > 0 {
|
||||
b = make([]byte, bp.w, bp.wcap)
|
||||
b = reedsolomon.AllocAligned(1, bp.wcap)[0][:bp.w]
|
||||
} else {
|
||||
b = make([]byte, bp.w)
|
||||
b = reedsolomon.AllocAligned(1, bp.w)[0]
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user