Skip to content

update butil::default_block_size when rdma_recv_block_type is set#3303

Open
randomkang wants to merge 4 commits into
apache:masterfrom
randomkang:opt_default_block_size
Open

update butil::default_block_size when rdma_recv_block_type is set#3303
randomkang wants to merge 4 commits into
apache:masterfrom
randomkang:opt_default_block_size

Conversation

@randomkang
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: 3301

Problem Summary:

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

The bandwith of rdma perf will be increased 10%(in my case, from 21GB/s to 23GB/s ).

  • Breaking backward compatibility:

Check List:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (1)

src/brpc/rdma/rdma_endpoint.cpp:1634

  • GlobalInitialize() stores the result of GetRdmaBlockSize() - IOBUF_BLOCK_HEADER_LEN into uint32_t. If GetRdmaBlockSize() signals errors via size_t(-1) (or returns a value smaller than the header), this will underflow/wrap and the <= 0 check won’t catch it. Validate the GetRdmaBlockSize() result before subtraction/cast (and ensure the type can represent errors).
    g_rdma_recv_block_size = GetRdmaBlockSize() - IOBUF_BLOCK_HEADER_LEN;
    if (g_rdma_recv_block_size <= 0) {
        LOG(ERROR) << "rdma_recv_block_type incorrect "
                   << "(valid value: default/large/huge)";
        errno = EINVAL;
        return -1;

Comment on lines 329 to 331
if (ExtendBlockPool(FLAGS_rdma_memory_pool_initial_size_mb,
BLOCK_DEFAULT) != NULL) {
GetRdmaBlockType()) != NULL) {
return true;
Comment thread src/brpc/rdma/block_pool.cpp Outdated
} else {
LOG(ERROR) << "rdma_recv_block_type incorrect "
<< "(valid value: default/large/huge)";
return -1;
Comment on lines 97 to +105
// Return the block size of given block type
// type=1: BLOCK_DEFAULT(8KB)
// type=2: BLOCK_LARGE(64KB)
// type=3: BLOCK_HUGE(2MB)
size_t GetBlockSize(int type);

size_t GetRdmaBlockSize();

int GetRdmaBlockType();
Comment thread src/butil/iobuf.cpp
Comment on lines +45 to +56
static size_t default_block_size = 8192;

size_t GetDefaultBlockSize() {
return default_block_size;
}

void SetDefaultBlockSize(size_t block_size) {
if (block_size / 4096 * 4096 != block_size) {
LOG(FATAL) << "block_size " << block_size << " should be multiply of 4096!!!";
}
LOG(INFO) << "Update default_block_size from " << default_block_size << " to " << block_size;
default_block_size = block_size;
Comment thread src/butil/iobuf.cpp
Comment on lines +52 to +54
if (block_size / 4096 * 4096 != block_size) {
LOG(FATAL) << "block_size " << block_size << " should be multiply of 4096!!!";
}
Comment thread src/butil/iobuf.h
Comment on lines +55 to +58
size_t GetDefaultBlockSize();

void SetDefaultBlockSize(size_t block_size);

Comment on lines 552 to 555
// Initialize RDMA memory pool (block_pool)
butil::SetDefaultBlockSize(GetRdmaBlockSize());
if (!InitBlockPool(RdmaRegisterMemory)) {
PLOG(ERROR) << "Fail to initialize RDMA memory 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.

2 participants