Skip to content

fuse: optimize fuse bufferpool - #54

Open
anysql wants to merge 1 commit into
release-2.5from
optimize_buffer_pool_allocation
Open

anysql wants to merge 1 commit into
release-2.5from
optimize_buffer_pool_allocation

Conversation

@anysql

@anysql anysql commented Jul 15, 2026

Copy link
Copy Markdown

optimize lock contention

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the FUSE bufferPool implementation to reduce lock contention by replacing the mutex-protected slice of pools with a concurrent sync.Map keyed by page-count.

Changes:

  • Replaced bufferPool’s sync.Mutex + []*sync.Pool with a sync.Map.
  • Updated getPool to use Load / LoadOrStore for concurrent pool initialization and retrieval.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fuse/bufferpool.go
Comment on lines 15 to +16
// For each page size multiple a list of slice pointers.
buffersBySize []*sync.Pool
buffersBySize sync.Map
Comment thread fuse/bufferpool.go
Comment on lines 21 to +25
func (p *bufferPool) getPool(pageCount int) *sync.Pool {
p.lock.Lock()
for len(p.buffersBySize) < pageCount+1 {
p.buffersBySize = append(p.buffersBySize, nil)
}
if p.buffersBySize[pageCount] == nil {
p.buffersBySize[pageCount] = &sync.Pool{
New: func() interface{} { return make([]byte, pageSize*pageCount) },
}
if pool_, ok := p.buffersBySize.Load(pageCount); ok {
return pool_.(*sync.Pool)
}
pool := p.buffersBySize[pageCount]
p.lock.Unlock()
return pool
pool_, _ := p.buffersBySize.LoadOrStore(pageCount, &sync.Pool{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants