Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Reflink(Copy On Write)支持 #39
Reflink(Copy On Write)支持 #39
Changes from 3 commits
d466e2f
ea2134e
ed48c50
50aa01c
fb2718a
f850e00
b50e331
f0ee4d2
a3e6c4b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
仍然存在的魔法数字
如果是你自己写的,请给出理由;如果是参照得出的,请给出引用源
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于反复出现的魔法数字,请定义常量统一维护
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy_file_range无论多大的单个文件,最多都只能复制2**31 - 4096字节
https://stackoverflow.com/questions/70368651/why-cant-linux-write-more-than-2147479552-bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请在代码注释中注明出处链接,以便后续维护
对于这一个上限,根据上述链接中所述,其定义为(https://elixir.bootlin.com/linux/v4.8/source/include/linux/fs.h#L2130)
其中,
PAGE_CACHE_MASK
与PAGE_SIZE
直接相关,而后者与可能与具体的系统有关。因此,假定PAGE_SIZE
是 4096 也并不是一个稳妥的做法考虑到
os.copy_file_range
可以返回实际操作的字节数,不妨使用一个较小的值作为每次拷贝的字节数,如 1GiB,并动态维护当前已拷贝的字节数,循环调用直到已拷贝的字节数达到期望值。这样的实现是无需考虑PAGE_SIZE
的值的,能保证稳定的可用性。并且若实现正确,也不需要在执行 COW 前判一下文件大小是否超过COW_COPY_LIMIT
,均使用同一种实现即可There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也许并不用记录已拷贝字节,只要判定返回是否为0或-1(出错)就行了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
翻了一下glibc的实现,这个数其实大了没事
https://github.com/bminor/glibc/blob/db9b47e9f996bbdb831580ff7343542a017c80ee/support/support_copy_file_range.c
71-76
无论多大缓冲区都是8192
读取完了直接返回
count设为1gb应该是比较好的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unix 风格的系统调用并不一定使用了 glibc 的实现,并且 glibc 的实现也并不一定稳定。我不建议使用依赖系统调用实现的做法,用记录已拷贝字节数的方案总是最稳妥的方案。
除此之外,你也在 #39 (comment) 提到过,“对小文件可能会导致内存占用过高”。如果这是真实的例子,那么选择一个 MiB 量级的每次拷贝数也是更优的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glibc只会增加功能,不会删除已有的功能
内存占用过高只是直觉,没有测试
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返回值似乎总是比文件大小小一个字节,记录意义不大