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

feat: use buddy alloc #176

Merged
merged 6 commits into from
Dec 16, 2024
Merged

feat: use buddy alloc #176

merged 6 commits into from
Dec 16, 2024

Conversation

JonasKruckenberg
Copy link
Owner

@JonasKruckenberg JonasKruckenberg commented Dec 16, 2024

This PR makes the loader and kernel actually use the new BuddyAllocator for frame allocation. This has a number of benefits:

  1. Better support for super/hugepages - The memory mapping routines already try mapping at the largest possible page sizes. This currently is limited however by the alignment (or lack thereof) of physical frames. Both BumpAllocator and BitMapAllocator can only guarantee 4kib alignments and adding support for aligned regions would be difficult, wasteful or both. Since the whole spiel of BuddyAllocator is its support for power-of-two alignments, allocating regions with a specific alignment is trivial. The new NonContiguousFrames implementation even allows for non-contiguous but still well aligned allocations of frames.
  2. Better support for non-contiguous physical memory - Physical memory might not always be contiguous, different banks can be wired at different addresses resulting in unusable holes in the address space. This is something we have been trying to handle from the start, but the approach used by BumpAllocator was more than lackluster: With a single offset you simply can't bump-allocate properly from multiple regions. And even with multiple pointers, you end up with wasteful inefficient allocations when requesting large chunks such as for the kernel heap.

This change allows users of `FrameAllocator` to pass a desired alignment in addition to the size of allocation. This alignment *must* be respected by allocator implementation.
This change adds a convenience `memories` method to `BootInfo` that allows accessing the slice of MemoryRegions without having to manually construct it every time.
This change makes the loader use the new `BuddyAllocator` instead of the `BumpAllocator`. The main reason is to benefit from the better alignment handling of the BuddyAllocator when allocating memory for the kernel stacks, TLS region, and heap so that super/hugepages can be used more often.

Previously we would fall back often on  mapping using regular 4k pages which is quite inefficient for e.g. the kernel heap.
This change makes the kernel virtmem handling code use the new buddy allocator instead of the `BitMap` one, to allow us to make better use of aligments in the future.
@JonasKruckenberg JonasKruckenberg merged commit f41ebf3 into main Dec 16, 2024
16 checks passed
@JonasKruckenberg JonasKruckenberg deleted the jonas/feat/use-buddy-alloc branch December 16, 2024 17:07
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.

1 participant