-
Notifications
You must be signed in to change notification settings - Fork 97
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
feat(filestore): add mmap reader option #665
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #665 +/- ##
==========================================
+ Coverage 60.39% 60.41% +0.02%
==========================================
Files 243 244 +1
Lines 31025 31054 +29
==========================================
+ Hits 18737 18761 +24
- Misses 10621 10629 +8
+ Partials 1667 1664 -3
|
791dc5f
to
6e22b09
Compare
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.
Thank you @Dreamacro!
Triage notes:
- this seems to solve Windows-specific perf. problem, and should not be applied to all platforms.
- please refactor to leverage build flags, see prior art in https://github.com/ipfs/boxo/blob/main/files/filewriter_windows.go
@lidel Yes, mmap was introduced to solve the Windows-specific problem, but |
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.
Triage notes:
- overall sounds good, as long it remains opt-in
- we will dogfood this in Kubo, will circle back to this as part of 0.31 activities Release 0.31 kubo#10499
- because mmap impl. is in
golang.org/x/exp
plan is to have it as opt-in flag for now, similar toIPFS_FD_MAX
- small ask to rename func inline
done |
4fc228c
to
44fa940
Compare
@lidel Hi, should I do anything else? |
44fa940
to
06b91df
Compare
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.
Eyeballed this and it looks good to me. I defer to @lidel for merging.
Motivation
I have a custom IPFS implementation based on boxo, which uses
FileManager
on Windows because I need to store files directly rather than file blocks. The pull logic is roughly as follows:ProtoNode
tree.RawNode
file blocks and write them to the system. Meanwhile, this Windows node also communicates and synchronizes with other nodes.When hundreds of Windows nodes are working simultaneously, I noticed that the system's memory consumption becomes very high, and the memory is immediately released once the file download is complete. Interestingly, the memory consumption is not by the program itself but by the operating system. After some investigation, I found the root cause: Windows caches the read file blocks (even if the *os.File is already closed).
This can be reproduced with the following code:
Solution
Using mmap can solve this problem (implemented with
CreateFileMapping
on Windows). To maintain backward compatibility, aWithMMapReader
option has been added toFileManager
. Enabling this option on Windows can prevent excessive memory consumption.The downside is that it relies on the exp package, but it only changes from an indirect dependency to a direct dependency. Alternatively, the code from this package can be copied directly into the project.