Skip to content
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

Documentation / user guide #47

Open
5 tasks
dhardy opened this issue Jul 7, 2017 · 7 comments
Open
5 tasks

Documentation / user guide #47

dhardy opened this issue Jul 7, 2017 · 7 comments

Comments

@dhardy
Copy link

dhardy commented Jul 7, 2017

In my opinion, as someone who knows very little about the subject of memory-mapped files, quite a bit more documentation would be useful. This mostly isn't specific to this crate, but having the documentation in one place (ideally within the module documentation) would make the topic easier to learn.

  • What are the main use-cases vs non-memory mapped files — performance, memory usage and behaviour differences with read-only and read-write usage. (E.g. is it useful when reading a file sequentially or only when seeking?)
  • What are the main costs of mem-mapped files: presumably opening, reading a page, and flushing changes?
  • Are there any guarantees when a memory-mapped file is read and modified by another process — e.g. if the writes are only appends, are reads safe? Is it OS-specific?
  • Can mem-mapped files be locked by the OS? This may be a separate topic, but pointers welcome.
  • How does paging work: entirely automatically in response to pointer dereferences? What's the page size (always 4kB?) & how should applications best allocate file memory to take advantage?
@danburkert
Copy link
Owner

I have somewhat mixed feelings about this. More documentation is always good, but it's a fine line between documenting the crate and re-writing system man pages.

For what it's worth, my opinion is that there are very few use cases which justify using file-backed memory maps. The trade-offs of mmap vs the conventional file API are subtle and widely misunderstood.

@burdges
Copy link

burdges commented Aug 1, 2017

I suppose optimal mmap use cases even change depending upon whether your storage is backed by an HDD or an SSD or one of those new Intel flash things. It's possible to add references to a couple good outside resources, like a good blog post.

@PSeitz
Copy link

PSeitz commented Jan 30, 2018

Is it safe to read from multiple threads? (std::fs::File e.g. is not thread-safe)

@setharnold
Copy link

It'd be nice if the docs could describe why some functions have been marked unsafe.

Thanks

@shepmaster
Copy link

Seconding the concerns about documenting unsafety. It would be good to document what the caller needs to ensure to keep the program memory safe.

@newpavlov
Copy link
Contributor

+1 for better explanation of unsafe.

If I understand correctly creation of memory mapped buffer is unsafe primary due the ability to create shared mutable memory. But what about using only immutable Mmaps only (e.g. for reading files), is it safe? If so, shouldn't creation of Mmap::map be safe and in turn Mmap::make_mut become unsafe?

@burdges
Copy link

burdges commented May 6, 2018

I think MAP_ANONYMOUS behave like allocations, so safe even for writing. It's clear MAP_PRIVATE protects readers from your writes, but it's less clear if others could still modify your pages before you read them yourself. And MAP_SHARED would probably never be safe even if read only for the current process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants