Skip to content

iobuf support reserve_aligned#2942

Merged
wwbmmm merged 1 commit intoapache:masterfrom
yanglimingcn:feature/iobuf_support_reserve_aligned
Apr 24, 2025
Merged

iobuf support reserve_aligned#2942
wwbmmm merged 1 commit intoapache:masterfrom
yanglimingcn:feature/iobuf_support_reserve_aligned

Conversation

@yanglimingcn
Copy link
Copy Markdown
Contributor

@yanglimingcn yanglimingcn commented Apr 7, 2025

What problem does this PR solve?

IOBuf通过reserve_aligned(size_t n, size_t alignment)函数在IOBuf内部预分配一些符合对齐规则的内存,后续可以通过unsafe_assign函数或者IOBufAsZeroCopyInputStream等函数把这些内存段解析出来,让用户填充数据。
这样做的好处是,统一使用IOBuf的内存管理机制,典型的如RDMA这种内存需要注册的场景,用户自己去注册会比较麻烦,RDMA已经提供给IOBuf内存分配器,直接使用非常方便。

Issue Number:

#993

Problem Summary:

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性):


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.(请遵循贡献者准则).

@yanglimingcn yanglimingcn force-pushed the feature/iobuf_support_reserve_aligned branch from 9238244 to ea60451 Compare April 7, 2025 06:07
Comment thread src/butil/iobuf.cpp Outdated
Comment thread src/butil/iobuf.cpp Outdated
@yanglimingcn yanglimingcn force-pushed the feature/iobuf_support_reserve_aligned branch 2 times, most recently from c0052e4 to 5ece6d7 Compare April 8, 2025 05:28
Comment thread src/butil/iobuf.cpp Outdated
@yanglimingcn yanglimingcn force-pushed the feature/iobuf_support_reserve_aligned branch 7 times, most recently from 23b31f7 to c24eb6f Compare April 10, 2025 02:44
Comment thread src/butil/iobuf.cpp Outdated
@yanglimingcn yanglimingcn force-pushed the feature/iobuf_support_reserve_aligned branch from c24eb6f to 420f36b Compare April 10, 2025 11:30
Copy link
Copy Markdown
Contributor

@chenBright chenBright left a comment

Choose a reason for hiding this comment

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

LGTM

@yanglimingcn yanglimingcn force-pushed the feature/iobuf_support_reserve_aligned branch from 420f36b to 92d262d Compare April 16, 2025 09:45
@yanglimingcn
Copy link
Copy Markdown
Contributor Author

重构了这个方案,定义了一个IOReserveAlignedBuf结构,这样对IOBuf的影响是最小的,有需求的用户可以使用,IOReserveAlignedBuf内部使用了不同大小的对齐的内存,所以没有放到tls链表里面。目前只实现了一个reserve方法。
后续有更多需求可以持续迭代。

@chenBright
Copy link
Copy Markdown
Contributor

释放的内存会放到tls链表?

@yanglimingcn
Copy link
Copy Markdown
Contributor Author

释放的内存会放到tls链表?

现在这个实现,释放内存不会放到tls链表。我是担心影响现在的tls链表。

Copy link
Copy Markdown
Contributor

@chenBright chenBright left a comment

Choose a reason for hiding this comment

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

LGTM

@yanglimingcn
Copy link
Copy Markdown
Contributor Author

@wwbmmm 再看一下吧

@wwbmmm wwbmmm merged commit 3eb4041 into apache:master Apr 24, 2025
21 checks passed
yanglimingcn added a commit to yanglimingcn/brpc that referenced this pull request May 19, 2025
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