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

New post about heap allocation #625

Merged
merged 38 commits into from Jun 26, 2019

Conversation

2 participants
@phil-opp
Copy link
Owner

commented Jun 26, 2019

This pull request adds a new blog post about heap allocation.

First, it gives an introduction to dynamic memory and shows how the borrow checker prevents common allocation errors. It then implements the basic allocation interface of Rust, creates a heap memory region, and sets up an allocator crate. At the end of this post all the allocation and collection types of the built-in alloc crate will be available to our kernel.

Code update in #626.

phil-opp added some commits Mar 14, 2019

Heap Allocation is the 10th post now
(We combined the two testing posts into one.)
Split off Allocator Designs section into its own post
The post is already long enough and this section is already large enough to fill its own post and far from finished.

@phil-opp phil-opp force-pushed the heap-allocation branch from 0cf4c3e to bb61229 Jun 26, 2019

.allocate_frame()
.ok_or(MapToError::FrameAllocationFailed)?;
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };

This comment has been minimized.

Copy link
@bjorn3

bjorn3 Jun 26, 2019

Contributor

Flushing is only required after the last map, right? That would be faster.

This comment has been minimized.

Copy link
@phil-opp

phil-opp Jun 26, 2019

Author Owner

You can either flush each page individually, or flush the whole TLB after the last map. The former requires more instructions, but the latter flushes everything and thus causes TLB misses. I'm not sure what's faster.

This comment has been minimized.

Copy link
@bjorn3

bjorn3 Jun 26, 2019

Contributor

I didnt know there was an instruction to flush a single page from the tlb. I believe I read somewhere that making a page that hasnt been present since the last full flush present doesnt need a flush afterwards. Because those heap pages have never been present, the MapperFlush can be ignored().

This comment has been minimized.

Copy link
@phil-opp

phil-opp Jun 26, 2019

Author Owner

The problem is that modern CPUs do all kind of speculative prefetching, including page walk results (see http://blog.stuffedcow.net/2015/08/pagewalk-coherence/). So I think it's better to do to many flushes than causing undefined behavior because of a missing flush.

@phil-opp phil-opp marked this pull request as ready for review Jun 26, 2019

@phil-opp phil-opp added the relnotes label Jun 26, 2019

@phil-opp phil-opp added this to the Second Edition milestone Jun 26, 2019

@phil-opp phil-opp added this to In Progress in Roadmap Jun 26, 2019

@phil-opp phil-opp merged commit 9c9ad4a into master Jun 26, 2019

1 check passed

phil-opp.blog_os Build #20190626.33 succeeded
Details

Roadmap automation moved this from In Progress to Done Jun 26, 2019

@bors bors bot deleted the heap-allocation branch Jun 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.