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

zeroize memory copy #78

Merged
merged 1 commit into from
Sep 23, 2020
Merged

Conversation

wu-hanqing
Copy link
Contributor

Change-Id: I2d389b24446623e8f639642a2b354120f20dbe56

What problem does this PR solve?

Issue Number: None

Problem Summary:

What is changed and how it works?

What's Changed: zeroize memory copy between nebd and curve-client

How it Works:

Side effects(Breaking backward compatibility? Performance regression?):

Check List

  • Relevant documentation/comments is changed or added
  • I acknowledge that all my contributions will be made under the project's license

* @return 返回错误码
*/
virtual int AioRead(int fd, CurveAioContext* aioctx);
virtual int AioRead(int fd, CurveAioContext* aioctx, UserDataType dataType);
Copy link
Contributor

Choose a reason for hiding this comment

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

是否要改成const引用?

Copy link
Contributor Author

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.

这个只是个枚举类型,没有必要加。

* @return 返回错误码
*/
virtual int AioWrite(int fd, CurveAioContext* aioctx);
virtual int AioWrite(int fd, CurveAioContext* aioctx,
UserDataType dataType);
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

namespace curve {
namespace client {

const char* OpTypeToString(OpType optype) {
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.

这个文件就一个函数,而且函数逻辑不复杂,就改成inline放到头文件了。

reqlist_.reserve(length_ / Splitor::IOSplitSize() + 1);

int ret = Splitor::IO2ChunkRequests(
this, mc_, &reqlist_, nullptr, offset_, length_, mdsclient, fi);
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么改成了传nullptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

修改之前的splitor,需要传入用户buffer,拆分的sub-io的buffer会指向用户buffer不同的offset。

  • 写请求会把sub-io的buffer中的数据复制到rpc controller中。
  • 读请求读到的数据,会从rpc controller复制到sub-io的buffer中。这里当所有的sub-io完成后,用户buffer里面就存储了需要读取的数据。

修改之后,小io的buffer,改成了IOBuf。

  • 写请求,需要把用户IOBuf中的内容cut到sub-io的iobuf中,然后传给rpc controller。
  • 读请求,只需要把rpc controller中的iobuf复制给sub-io的iobuf中就可以了。当所有sub-io完成后,会把所有sub-io的iobuf按顺序拼接到一起,返回给用户。

IOTracker* temp = new IOTracker(this, &mc_, scheduler_);
temp->SetUserDataType(UserDataType::RawBuffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么是RawBuffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里是直接读快照chunk,接口传入的是char* buf。

return -LIBCURVE_ERROR::FAILED;
}

memcpy(buf, data.to_string().c_str(), length);
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.

需要零拷贝的只有nebd使用的接口。上层nbd/qemu都是使用的异步读写接口,所以同步这里就没修改了。

@wu-hanqing wu-hanqing force-pushed the zeroize-memory-copy branch 3 times, most recently from 5303c14 to c4c20f2 Compare September 21, 2020 06:00
src/client/iomanager4file.cpp Outdated Show resolved Hide resolved
src/client/file_instance.cpp Show resolved Hide resolved
src/client/io_tracker.cpp Outdated Show resolved Hide resolved
src/client/io_tracker.cpp Outdated Show resolved Hide resolved
src/client/io_tracker.cpp Outdated Show resolved Hide resolved
src/client/splitor.cpp Outdated Show resolved Hide resolved
src/client/request_context.h Show resolved Hide resolved
nebd/src/part2/file_service.cpp Show resolved Hide resolved
type_ = OpType::WRITE;
type_ = OpType::WRITE;

DVLOG(9) << "aiowrite op, offset = " << offset << ", length = " << length;
Copy link
Member

Choose a reason for hiding this comment

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

这个日志,不是aiowrite吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Change-Id: I2d389b24446623e8f639642a2b354120f20dbe56
@wu-hanqing wu-hanqing closed this Sep 23, 2020
@wu-hanqing wu-hanqing reopened this Sep 23, 2020
@xu-chaojie xu-chaojie merged commit 3c69933 into opencurve:master Sep 23, 2020
@wu-hanqing wu-hanqing deleted the zeroize-memory-copy branch September 24, 2020 02:57
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