PMM: add simple buddy allocator (splitting and merging frames) #244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The split_frame() breaks given frame into two smaller frames.
Original frame's frame_t struct is reused, frame order is decremented
and the struct is re-assigned to lower order free frame list.
Another, new frame is created for the second half of the original frame.
The get_free_frame(), when cannot find free frame of requested order,
keeps finding first free higher-order frame and split it, until desired
order frame becomes available.
The merge_frames() attempts to merge two consecutive frames into a higher
order frame. It only merges higher-order aligned frame with its following
frame. To do so, it checks if the frame being returned is higher-order
aligned frame and attempts to find its following frame. If the frame
being returned is not higher-order aligned, it tries to find its preceding
frame, which will be properly aligned.
When the two frames are found, the first frame's struct is reused, order
is incremented and the struct is relinked to higher order free frames list.
The second frame struct is destroyed.
The merge_frames() calls itself recursively in attempt to merge all merge-
able higher-order frames for all orders.
The put_free_frames() find corresponding frame struct for given MFN and
order. If the frame is fully returned (there is no more references) and
relinked from busy_frames to free_frames, it attempts to merge the frame.
After creating early frames, the process_memory_range() finds highest
available frame order (i.e. frame order whose size fits into available
physical memory size).
Instead of creating 2M frames by default, it creates frames of the
detected order and uses the rest of available space to create 2M frames
and 4K frames.
Implements #7.