Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow IOBuf::append_user_data specifying any valid address in registered rdma memory region #1999

Closed
wants to merge 1 commit into from

Conversation

Tuvie
Copy link
Contributor

@Tuvie Tuvie commented Nov 16, 2022

What problem does this PR solve?

Issue Number: 1995

Problem Summary: When using IOBuf::append_user_data, if the application specify a buffer with an offset over the base address registered with rdma::RegisterMemoryForRdma, brpc reports a failure for invalid memory region.

What is changed and the side effects?

Changed: Use a fixed-length array to manage the user-defined memory regions. To lookup the lkey for a buffer specified in append_user_data, brpc scans the array to find the correct region. To guarantee the performance of lkey lookup, we avoid using mutex for the lookup in this array.

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性): To guarantee the performance of lkey (linear) lookup, brpc only support at most 16 user-defined memory regions. The application should maintain the user-defined buffer with a memory pool and register the pool one time. And since the lookup is not guarded with a mutex, the application should try not to register or deregister memory during rpc processing.


Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

@Tuvie Tuvie changed the title allow IOBuf::attach_user_data specifying any valid address in registered rdma memory region allow IOBuf::append_user_data specifying any valid address in registered rdma memory region Nov 16, 2022
@@ -99,37 +99,41 @@ static ibv_device** g_devices = NULL;
static ibv_context* g_context = NULL;
static SocketId g_async_socket;
static ibv_pd* g_pd = NULL;
static std::vector<ibv_mr*>* g_mrs = NULL;
static std::vector<ibv_mr*>* g_mrs = NULL; // mr registered by brpc
Copy link
Contributor

Choose a reason for hiding this comment

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

可以按照地址排列成有序集合,用二分法查找更快

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以按照地址排列成有序集合,用二分法查找更快

这么用是为了避免在后续GetLkey的时候上锁,数组虽然效率不好但是线程间竞争影响可忽略。高级一点的数据结构无锁化高效实现没想好怎么做。或者就是把线程竞争的处理留给上层的应用去考虑。有什么建议么?

Copy link
Contributor

Choose a reason for hiding this comment

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

读多写少的场景,可以用DBD?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

其实针对这个问题,我有点想把IOBuf的结构改改。每一段user_data可能对应不同的lkey。如果这个lkey能存放在IOBuf的元数据里面,就不需要这个lookup了。你觉得如何?

Copy link
Contributor

Choose a reason for hiding this comment

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

append_user_data加个lkey的参数么?我觉得ok,可以问问那个用户

@@ -1061,7 +1068,10 @@ TEST_F(RdmaTest, server_miss_after_ack) {
usleep(100000);
ASSERT_EQ(rdma::RdmaEndpoint::ESTABLISHED, s->_rdma_ep->_state);
ASSERT_EQ(4, read(acc_fd, data, 4));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
Copy link
Contributor

Choose a reason for hiding this comment

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

(uint32_t*)data改成(uint32_t*)(void*)data应该就不会报错了

@Tuvie Tuvie closed this Nov 20, 2022
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