Repository navigation
Conversation
openCASBackedFileForRead asks for a buffer without a null terminator, so MemoryBuffer maps every file of 16 KB or more. The buffer is hashed once by storeFromString and dropped, so every page of the mapping faults in once and is unmapped right after. On Windows that is a fault per 4 KB page; on Linux fault-around maps up to 16 pages per fault. Read files up to 1 MB instead. shouldUseMmap() skips mmap for a volatile file only when a null terminator is requested, so pass both flags. The terminator lies past the end of getBuffer() and does not change the stored object; the new test checks that the ref of a real file is the ref of its contents on both sides of the limit. Larger files stay mapped: a read buffer would commit their whole size, and on Linux mapping them is cheaper. The size comes from status() of the open file, which takes the place of the fstat MemoryBuffer makes itself. Measured per file, from open to release: for files of 16 KB to 1 MB, reading is 22-52% faster than mapping on Windows. On Linux it is up to 17% faster for small files and about even (within 2%) at 512 KB-1 MB.
|
Hello @tagolog 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
Why 1MB? Maybe it is better just update We can define something like or even Are you sure we still have any advantages of using mmap in Windows for files larger than 1MB at all, not only for CAS hash? |
openCASBackedFileForRead asks for a buffer without a null terminator, so MemoryBuffer maps every file of 16 KB or more. The buffer is hashed once by storeFromString and dropped, so every page of the mapping faults in once and is unmapped right after. On Windows that is a fault per 4 KB page; on Linux fault-around maps up to 16 pages per fault.
Read files up to 1 MB instead. shouldUseMmap() skips mmap for a volatile file only when a null terminator is requested, so pass both flags. The terminator lies past the end of getBuffer() and does not change the stored object; the new test checks that the ref of a real file is the ref of its contents on both sides of the limit. Larger files stay mapped: a read buffer would commit their whole size, and on Linux mapping them is cheaper. The size comes from status() of the open file, which takes the place of the fstat MemoryBuffer makes itself.
Measured per file, from open to release: for files of 16 KB to 1 MB, reading is 22-52% faster than mapping on Windows. On Linux it is up to 17% faster for small files and about even (within 2%) at 512 KB-1 MB.