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

Use mmap for allocation #190

Merged
merged 19 commits into from
Jul 8, 2019
Merged

Use mmap for allocation #190

merged 19 commits into from
Jul 8, 2019

Conversation

pepyakin
Copy link
Collaborator

@pepyakin pepyakin commented Jul 3, 2019

This PR uses mmap for allocation of linear memory.
This can be seen that it effectively reverts #115 because the same is done by the system now and we no longer need it in substrate/polkadot.

A little bit of background:

It turns out that creation of a large Vec can actually be really wasteful. There is an specialization for Rust, that leverages calloc for creating zeroed arrays. However, my testing shows that on macOS it uses bzero (or simply it just zeroes the whole allocation right away).

On the other hand, mmap has a good property. The allocated memory starts in uncommited state and it is not backed by any physical or swap memory. Only on the first access to a virtual memory page it is allocated and zeroed (if not is not zeroed already).

Related to #45, but doesn't fix it since we can go further and avoid copying on grow. This is however outside of the scope of this PR to optimize it for reviewing.

src/memory/mmap_bytebuf.rs Outdated Show resolved Hide resolved
src/memory/mmap_bytebuf.rs Outdated Show resolved Hide resolved
src/memory/mmap_bytebuf.rs Outdated Show resolved Hide resolved
src/memory/mmap_bytebuf.rs Show resolved Hide resolved
src/memory/mmap_bytebuf.rs Outdated Show resolved Hide resolved
src/memory/vec_bytebuf.rs Show resolved Hide resolved
src/memory/vec_bytebuf.rs Show resolved Hide resolved
Copy link

@ordian ordian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safety of mmap_bytebuf.rs looks ok to me

src/memory/mmap_bytebuf.rs Outdated Show resolved Hide resolved
src/memory/mmap_bytebuf.rs Outdated Show resolved Hide resolved
pepyakin and others added 4 commits July 3, 2019 17:21
@pepyakin pepyakin merged commit 1a6e5b3 into master Jul 8, 2019
@pepyakin pepyakin deleted the ser-fast-alloc branch July 8, 2019 11:53
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.

4 participants