From 97d925dbe685e48ca22618bc1a6c52c5b103a227 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 8 Dec 2014 16:40:12 +0100 Subject: MEDIUM: buffers: make b_alloc_single() use b_fast_alloc() During memory contention, we don't want to call pool_gc2() all the time via b_alloc() to refill one new buffer at a time. Here instead we first verify that there are enough buffers left to call b_fast_alloc() otherwise we refill by the number of missing buffers. Doing so shortens the fast path and factors out some of the calls during new allocations. It results in about 1% performance increase when no memory contention is observed. --- include/common/buffer.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/include/common/buffer.h b/include/common/buffer.h index 07a06a8..aef17c6 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -477,23 +477,18 @@ static inline struct buffer *b_alloc_single(struct buffer **buf) if ((*buf)->size) return *buf; - next = b_alloc(buf); - if (!next || (pool2_buffer->allocated - pool2_buffer->used) >= 2) - return next; + /* fast path */ + if ((pool2_buffer->allocated - pool2_buffer->used) >= 3) + return b_fast_alloc(buf); - /* here we know we have allocated the last entry from the pool, so - * we need to check if it's possible to refill the pool otherwise - * we must return the one we picked. - */ - next = pool_refill_alloc(pool2_buffer, 2); - pool_free2(pool2_buffer, next); - if ((pool2_buffer->allocated - pool2_buffer->used) >= 2) - return *buf; + next = pool_refill_alloc(pool2_buffer, 3 - (pool2_buffer->allocated - pool2_buffer->used)); + if (!next) + return next; - /* cannot allocate a second buffer */ - __b_drop(buf); - *buf = &buf_wanted; - return NULL; + next->size = pool2_buffer->size - sizeof(struct buffer); + b_reset(next); + *buf = next; + return next; } /* Ensures that both and are allocated. Tries to allocated both of -- 1.7.12.1