-
-
Notifications
You must be signed in to change notification settings - Fork 742
std.mmfile - fix multiple issues #3619
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
std.mmfile - fix multiple issues #3619
Conversation
This reverts commit 4f3b3f4. > This fix is incorrect and dangerous. You've removed a potential > InvalidMemoryOperationError, which is deadly but easy to detect, > but retained the possibility of closing the file handle of a > completely unrelated file, if that file handle has since been > reused. With this change, the bug will always be silent and much > harder to find the real cause of.
return; | ||
} | ||
} | ||
errnoEnforce(fd == -1 || fd <= 2 |
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.
enforce still going to InvalidMemoryOperation so maybe just call abort?
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.
That wouldn't be an improvement. enforce
will have to do. Let's not forget that class destructors are not always invoked by the GC (there's e.g. scoped
), so removing enforce
would penalize uses that do not use the GC.
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.
Failure to close a fd which should be open indicates a dangling fd, which is a logic error... I think the response is apt, though a stack trace and better error message would be better, yeah.
Added fixes for 2 more bugs. |
0753da3
to
21a007b
Compare
21a007b
to
290a942
Compare
@sdegtiarev any new issues? Please post them here. |
There is https://issues.dlang.org/show_bug.cgi?id=15013 but it'll take a bit more work. Generally the whole page-size calculation is messed up and has to be reviewed completely. Not blocking this PR. |
Maybe re-writing the underlying implementation is more sensible, in particular decomposing OS syscall abstraction from higher-level wrapper object. Thoughts? |
That wouldn't solve any problems other than cleaning up the code a bit, like any refactoring. |
I disagree, the root problem is, std.mmfile reports more memory allocated than is actually available. I believe, an error is to be thrown at this point. |
I think we all agree that std.perpetual should be built on top of some memory allocator, std.mmfile or similar. To be usable, this allocator class should provide certain guarantees above regular memory allocator, which mostly fall in two categories, concurrent initialization and data mutability.
There might be more and not all of them are orthogonal, so they may be reshuffled.
Also, I don't especially like the ensureMapped() function in std.mmfile, it silently unmaps and maps again the shared memory when requested index is beyond mapped area. This is nice feature to have, but not in generic class because it violates time guarantee for memory access. While accessing shared memory is as fast as any other variable in process address space, remapping makes it as slow as reading from file, it does not make it true random access data. That makes sense for big data, but not for generic use. It also probably should not be transparent for the user. In short, I would think about moving it to the derived class. For std.perpetual module I'm going to exclude functions to be placed in shared memory first, then to handle differently mutable and immutable types and then to sort out all these different variants of creation, and finally, to provide arguments forwarding. |
When you have code like: size_t initial_map = (window && 2*window<size)
? 2*window : cast(size_t)size; it's clear that the original author didn't really know what he was doing and we need to review all related code entirely.
This is beyond the scope of this PR. We should try to fix std.mmfile as much as possible without breaking existing code. New modules are orthogonal to this goal. I'm not really in a position currently to think about an entire new Phobos module. Perhaps it would be better to post this in a new forum thread instead of a bugfix PR.
Generally I'd think page faults would outweigh OS syscall overhead. |
Focusing on the current bugfixes - anything missing - @sdegtiarev ? |
These are not just syscalls, but HD file system requests, they are in general thousands times slower and nothing can possible overweight them.
For std.mmfile or std.perpetual? |
What are you talking about? Why would merely mapping a file incur HD access (when file metadata is cached), and how would this possibly outweigh actual pagefaults when accessing non-paged memory? You realize that simply mapping a file does not load it into memory, right? |
@CyberShadow |
@sdegtiarev Either we are misunderstanding each other, or you should read up on virtual memory before you continue working on std.mmfile or std.perpetual. Mapping files simply allocates memory addresses for them, no physical memory is used and no I/O is done until those memory locations are accessed, which causes a page fault and the kernel pages in file data on demand.
It is exactly as when multiple threads access the same data within the same process. |
@CyberShadow
`
Is that what you mean? |
Okay the discussion goes sideways... Time to merge? @CyberShadow |
17126 ticks is not disk access, it's essentially the cost of the syscall.
Sure why not. |
Auto-merge toggled on |
std.mmfile - fix multiple issues
https://issues.dlang.org/show_bug.cgi?id=14868
https://issues.dlang.org/show_bug.cgi?id=14994
https://issues.dlang.org/show_bug.cgi?id=14995