-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sync: reduce memory allocation when write into files #1644
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1644 +/- ##
==========================================
+ Coverage 61.49% 61.55% +0.06%
==========================================
Files 133 133
Lines 22475 22565 +90
==========================================
+ Hits 13820 13889 +69
- Misses 7088 7116 +28
+ Partials 1567 1560 -7
Continue to review full report at Codecov.
|
|
@201341 Could you provide some detailed explanation? |
For file2file, io.CopyBuffer -> readfrom->io.Copy, it doesn't use the bufpool. |
|
*os.File has the method |
In order to use the buffer, not to alloc the memory, we need to convert to WriteCloser. |
|
@201341 io.CopyBuffer() will use copy_file_range (zero copy or in kernel) in linux, and fallback to io.Copy() in other OS, where do you saw the allocation? |
From pprof, |
|
What's the OS and version you are using? |
The version is Centos7(kernel 3.x), And it seems not support the |
|
This change makes sense since |
|
I see, the pool is not used when the We should check the difference when src and dst are disk and copy_file_range is available. |
|
@201341 It looks like this commit won't change the behavior at all, cuz |
|
@SandyXSD Yes, it doesn't change the behavior. I have changed the code. Now it can use the buffer, By the way, copy_file_range has the dataloss risk (syncthing/syncthing#4271) |
|
Cool, and we need a method to check kernel version. After a quick look at the issue you linked, it looks that the bug is only NFS related? |
Signed-off-by: swj <[email protected]>
|
@201341 Thanks! This patch disable the copy_file_range when both source and destination are same file system, we will find a way to enable it when it's safe. |
|
From golang official webpage: https://pkg.go.dev/io#CopyBuffer If either src implements WriterTo or dst implements ReaderFrom, buf will not be used to perform the copy. |
Signed-off-by: swj [email protected]