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

Added MmapOptions::no_reserve method #115

Closed
wants to merge 3 commits into from

Conversation

flier
Copy link

@flier flier commented Jan 31, 2024

Added MmapOptions::no_reserve method to support not to reserve swap space for this mapping. Linux only.

@flier
Copy link
Author

flier commented Jan 31, 2024

I'd also like to add support for windows, but its API is not designed to be completely transparent, need use VirtualAlloc to commit the pages, it may need commit the view before use it, any suggestions?

Creating a shared memory block that can grow in size

@RazrFalcon
Copy link
Owner

any suggestions?

I have zero expertise about VirtualAlloc and winapi in general. But I would suggest calling commit implicitly.

@flier
Copy link
Author

flier commented Feb 2, 2024

any suggestions?

I have zero expertise about VirtualAlloc and winapi in general. But I would suggest calling commit implicitly.

Ok, I guess we need introduce a new Index layer 0c6cd0e to calling commit implicitly.

@adamreichold
Copy link

I think for feature parity, it would suffice to just commit the whole range during creation on Windows, not lazily during access. This will avoid all the abstractions and indirections into during dereferencing.

@flier
Copy link
Author

flier commented Feb 2, 2024

I think for feature parity, it would suffice to just commit the whole range during creation on Windows, not lazily during access. This will avoid all the abstractions and indirections into during dereferencing.

Agreed, for most scenarios it's possible to commit all memory at creation time.

However, for some special scenarios, such as the need for a huge sparse array or the need to be able to scale the memory size at runtime, it is not possible to predict exactly how much memory will be needed at creation time.

@adamreichold
Copy link

But since this crate is a portable layer as much as possible, we do not need to support everything the underlying OS do. We can choose a sane common denominator and since we canot avoid increasing the complexity of this crate significantly if we interpret no_reserve to always apply to whole mapping, I think we can relegate these special cases to using the underlying OS API directly.

@flier
Copy link
Author

flier commented Feb 2, 2024

But since this crate is a portable layer as much as possible, we do not need to support everything the underlying OS do. We can choose a sane common denominator and since we canot avoid increasing the complexity of this crate significantly if we interpret no_reserve to always apply to whole mapping, I think we can relegate these special cases to using the underlying OS API directly.

That's why my 9326e4e commit just add a Mmap::commit method for the no_reserve case.

It's okay. If you don't like the feature, I can close the PR.

@flier flier closed this Feb 2, 2024
@adamreichold
Copy link

It's okay. If you don't like the feature, I can close the PR.

I did not say that. I dislike the additional complexity introduced by the third commit. Either requiring explicit action by the caller or implicit commit upon creation are fine in my opinion.

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

Successfully merging this pull request may close these issues.

None yet

3 participants