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

demand paging for anonymous mmaps #607

Merged
merged 15 commits into from
Mar 19, 2019
Merged

demand paging for anonymous mmaps #607

merged 15 commits into from
Mar 19, 2019

Conversation

wjhun
Copy link
Contributor

@wjhun wjhun commented Mar 18, 2019

This introduces demand paging for non-backed mmaps. The need for this has been exposed by ruby with sinatra which has been doing a number of large anonymous mmaps with each web request (though most are immediately unmapped). In general, we're seeing programs assume that the host OS environment does demand paging and that large anonymous mmaps are inexpensive. So we're following suit by adding a primitive page fault handler to map and zero 4K pages.

There's more work to do on the munmap(2) side, but this will at least allow the ruby/sinatra demo to run with somewhat acceptable performance. Previously, maps and unmaps of several hundred MB would occur several times in succession, leading to extremely slow response (this was with the munmap branch - it wouldn't even run without it). Here, munmap(2) is removed (there's some deeper plumbing that needs to happen to do it right), but the test will at least honor ~100 requests before falling over from exhausting the page tables. That issue will be addressed with the munmap(2) implementation.

Note that a bit of reworking of the context/frame saving was necessary here, and also that there is an alternate stack for the page fault handler (only vector 14; the others remain on the existing stack) so that faults on stack pages may be correctly handled. This is possible thanks to the IST vectors in the long mode TSS.

This could use a runtime test...ideas welcome.

related: #586, #562, #526

@wjhun wjhun requested a review from a team March 18, 2019 20:48
@eyberg eyberg mentioned this pull request Mar 18, 2019
@eyberg eyberg mentioned this pull request Mar 19, 2019
src/unix/mmap.c Outdated
// its really unclear whether this should be extended or truncated
u64 len = pad(size, PAGESIZE) & MASK(32);
u64 where = u64_from_pointer(target);
u64 end = where + size - 1;
boolean fixed = (flags & MAP_FIXED) != 0;
thread_log(current, "mmap: target %p, size %P, prot %P, flags %P, fd %d, offset %P",
boolean mapped = false;
thread_log(current, "mmap: target %p, size %P, prot %P, flags %P, fd %d, offset %P\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

thread_log() appends "\n" historically. This should probably be fixed there.

@wjhun wjhun merged commit e942733 into master Mar 19, 2019
@wjhun wjhun mentioned this pull request Apr 18, 2019
@eyberg eyberg deleted the demand-paging branch April 20, 2019 01:36
@wjhun wjhun mentioned this pull request May 24, 2019
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.

2 participants