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

std: rework uefi allocators #22818

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

RossComputerGuy
Copy link
Contributor

Split off from #22226 as suggested by @linusg. This reworks the allocators to be more friendly.

Copy link
Collaborator

@linusg linusg left a comment

Choose a reason for hiding this comment

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

Thank you, this is the right size for a PR like this :)

Two high level concerns:

  • All allocators, including platform-specific ones like WasmAllocator currently live in std.heap. If we're moving these around that should be where.
  • Why are we adding additional abstractions on top of the UEFI-provided allocator functions? In general that's a good thing if it improves ergonomics of those APIs from a Zig perspective, but in this case no one but the allocator implementation should touch those, and I feel in that case the extra layer is not justified.

@RossComputerGuy
Copy link
Contributor Author

  • All allocators, including platform-specific ones like WasmAllocator currently live in std.heap. If we're moving these around that should be where.

Will do

  • Why are we adding additional abstractions on top of the UEFI-provided allocator functions? In general that's a good thing if it improves ergonomics of those APIs from a Zig perspective, but in this case no one but the allocator implementation should touch those, and I feel in that case the extra layer is not justified.

I'm not 100% sure, this originally came from @truemedian.

@truemedian
Copy link
Contributor

Why are we adding additional abstractions

Which additional abstractions are you referring to?

PageAllocator.resize requesting new pages at the end of the current allocation happens because it's essentially free and part of the UEFI page allocation interface

PoolAllocator exists because RawPoolAllocator cannot handle the full range of possible alignment values the Allocator interface requires

@RossComputerGuy RossComputerGuy force-pushed the feat/uefi-alloc-rework branch 2 times, most recently from 7efc07c to a9862db Compare February 10, 2025 03:35
@linusg
Copy link
Collaborator

linusg commented Feb 10, 2025

Which additional abstractions are you referring to?

The ones in boot_services.zig.

@truemedian
Copy link
Contributor

Ah, thats because this came out of a branch where the goal was to make std.os.uefi a more idiomatic interface instead of just a loose C library binding.

Copy link
Collaborator

@linusg linusg left a comment

Choose a reason for hiding this comment

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

Please rebase this after #22820 and provide a compelling use case for the custom layer in boot_services.zig or remove it.

/// Allocates memory in pages.
///
/// This allocator is backed by `allocatePages` and is therefore only suitable for usage when Boot Services are available.
pub const PageAllocator = struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The namespacing here is awkward, this ought to be a file-as-struct (UefiPageAllocator.zig).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why file as a struct when there's multiple allocators?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because std.heap.UefiPageAllocator is much nicer than std.heap.uefi_allocators.PageAllocator (which violates https://ziglang.org/documentation/master/#Avoid-Redundant-Names-in-Fully-Qualified-Namespaces). Why do you want both allocators in the same file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because std.heap.UefiPageAllocator is much nicer than std.heap.uefi_allocators.PageAllocator

Wouldn't std.heap.uefi.Page/Pool be nicer?

Why do you want both allocators in the same file?

Just so there isn't 3 more files that could fit into 1.

@RossComputerGuy
Copy link
Contributor Author

Please rebase this after #22820

Already been rebased.

provide a compelling use case for the custom layer in boot_services.zig or remove it.

I don't have one unless @truemedian does. I think it just makes the API easier to use and it's already there. Shouldn't need additional maintenance since UEFI's API doesn't really change in that section. I probably will just remove it.

@linusg
Copy link
Collaborator

linusg commented Feb 20, 2025

Already been rebased.

I see at least one reference to .LoaderData which has been renamed.

@RossComputerGuy
Copy link
Contributor Author

I see at least one reference to .LoaderData which has been renamed.

Fixed, strange that one didn't get caught when I tried compiling lib/init.

@linusg
Copy link
Collaborator

linusg commented Feb 20, 2025

I think it just makes the API easier to use and it's already there. Shouldn't need additional maintenance

For the most part Zig follows YAGNI principles.

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.

3 participants