Skip to content

Commit

Permalink
Do not cache blocks in TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBright committed Feb 8, 2024
1 parent cc3336f commit c47be11
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/butil/iobuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ inline IOBuf::Block* create_block() {
// release_tls_block_chain() may exceed this limit sometimes.
const int MAX_BLOCKS_PER_THREAD = 8;

inline int max_blocks_per_thread() {
// If IOBufProfiler is enabled, do not cache blocks in TLS.
return IsIOBufProfilerEnabled() ? 0 : MAX_BLOCKS_PER_THREAD;
}

struct TLSData {
// Head of the TLS block chain.
IOBuf::Block* block_head;
Expand Down Expand Up @@ -436,7 +441,7 @@ inline void release_tls_block(IOBuf::Block* b) {
TLSData& tls_data = g_tls_data;
if (b->full()) {
b->dec_ref();
} else if (tls_data.num_blocks >= MAX_BLOCKS_PER_THREAD) {
} else if (tls_data.num_blocks >= max_blocks_per_thread()) {
b->dec_ref();
g_num_hit_tls_threshold.fetch_add(1, butil::memory_order_relaxed);
} else {
Expand All @@ -455,7 +460,7 @@ inline void release_tls_block(IOBuf::Block* b) {
void release_tls_block_chain(IOBuf::Block* b) {
TLSData& tls_data = g_tls_data;
size_t n = 0;
if (tls_data.num_blocks >= MAX_BLOCKS_PER_THREAD) {
if (tls_data.num_blocks >= max_blocks_per_thread()) {
do {
++n;
IOBuf::Block* const saved_next = b->u.portal_next;
Expand Down

0 comments on commit c47be11

Please sign in to comment.