Repository navigation
Conversation
|
You could use a const-generic for this: pub struct FixedSizeBlockAllocator<const MIN_EXPANSION:usize> {
...
}
...
impl<const MIN_EXPANSION:usize> FixedSizeBlockAllocator<MIN_EXPANSION> {
...
}
#[cfg_attr(target_os = "uefi", global_allocator)]
pub(crate) static EFI_BOOT_SERVICES_DATA_ALLOCATOR: UefiAllocator<SIZE_1MB> = UefiAllocator::new(
&GCD,
NonNull::from_ref(GCD.memory_type_info(efi::BOOT_SERVICES_DATA)),
protocol_db::EFI_BOOT_SERVICES_DATA_ALLOCATOR_HANDLE,
DEFAULT_PAGE_ALLOCATION_GRANULARITY,
);
etc. |
1a02589 to
1924899
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
os-d
left a comment
There was a problem hiding this comment.
While we are here, is there already a check (I think not based on the issue that led us to here) to make sure that we aren’t blowing buckets? It would be worth a print and debug assert when a bucketized allocator has to expand. Doesn’t need to be done here, but is related to the issue. That could go with a behavior change such that the bucketized allocators just hold onto the entire bucket memory and then service pool and pages directly from it and are never expected to expand.
As I’m typing this, this is a bigger change, so definitely not for here, but @joschock thoughts on this?
1924899 to
24f2ace
Compare
On the platform side we have https://github.com/microsoft/mu_plus/blob/05554be4a2ee7cc35f401c46492e02746c323c9d/MsCorePkg/Library/MemoryTypeInformationChangeLib/MemoryTypeInformationChangeLib.c#L25 to report bucket changes in log and telemetry, and we write tasks for various projects on the regular to tune the buckets to match. While we definitely need tools to allow us to tune the buckets, these exist. So I'm not sure it is worth making the allocators more complex or adding further constraints on their behavior is worth it. |
|
I'm going to explore simply storing the min expansion size in a field in the allocator to reduce some complexity around the static type management for the const generic in the current PR. As I added the commit for the const generic type parameter onto the original commit in the PR branch, I'll do the same for this to show the delta for the different approaches. |
Pushed in the latest commit |
c04f446 to
a6b246a
Compare
2310302 to
7e9dff4
Compare
Replace the `MIN_EXPANSION` constant with memory-type-specific expansion sizes to optimize memory usage. Boot Services Data allocators now use `HIGH_TRAFFIC_ALLOC_MIN_EXPANSION` (1MB) while other memory types use `LOW_TRAFFIC_ALLOC_MIN_EXPANSION` (4KB). A `min_expansion_for_memory_type()` helper function is used to centralize the mapping logic making it easier to adjust expansion sizes in the future if needed. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Simplify type management by simply storing the minimum expansion value directly in the allocator type.
7e9dff4 to
a78d403
Compare
Description
Replace the
MIN_EXPANSIONconstant with memory-type-specific expansion sizes to optimize memory usage. Boot Services Data allocators now useHIGH_TRAFFIC_ALLOC_MIN_EXPANSION(1MB), runtime memory types useLOW_TRAFFIC_RUNTIME_ALLOC_MIN_EXPANSION(uses runtime granularity), and other types useLOW_TRAFFIC_ALLOC_MIN_EXPANSION(page size / 4KB).A few other changes are included to better separate these allocator types:
UefiAllocatordirectly depend onSpinLockedFixedSizeBlockAllocator. Instead take the parameter as a generic type to decouple the types.PageAllocatortrait that defines the interfaceUefiAllocatorneeds to use an allocator. HaveSpinLockedFixedSizeBlockAllocatorimplement this trait.SpinLockedFixedSizeBlockAllocatortype is no longer fixed (e.g.SpinLockedFixedSizeBlockAllocator<A>vsSpinLockedFixedSizeBlockAllocator<B>), a single static array cannot be used to hold all of the static allocators. This change adds amacromodule to hold macros that make iterating across the diverse allocator types more ergonomic.A follow up change will be made to simplify overall allocator design and management, tracked in #1174.
How This Was Tested
cargo make allIntegration Instructions