forked from theseus-os/Theseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow page allocation requests to specify a desired alignment (theseu…
…s-os#1029) * The new `AllocationRequest::AlignedAt` variant can accept an alignment value, specified in number of 4K pages (not bytes). * This is needed to support easier allocation of huge pages, which have a large alignment requirement, e.g., a 2MiB huge page requires a contiguous 512-page allocation aligned to that same boundary of 512 normal 4K pages (512 * 4KiB = 2MiB).
- Loading branch information
1 parent
379c2f3
commit 06d9dbf
Showing
8 changed files
with
139 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "test_aligned_page_allocation" | ||
version = "0.1.0" | ||
description = "Tests the `AllocationRequest::AlignedTo` variant, which is needed for huge pages" | ||
authors = ["Kevin Boos <kevinaboos@gmail.com>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
log = "0.4.8" | ||
|
||
[dependencies.memory] | ||
path = "../../kernel/memory" | ||
|
||
[dependencies.app_io] | ||
path = "../../kernel/app_io" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! A set of basic tests for the [`AllocationRequest::AlignedTo`] variant. | ||
|
||
#![no_std] | ||
|
||
extern crate alloc; | ||
|
||
use alloc::{ | ||
vec::Vec, | ||
string::String, | ||
}; | ||
use app_io::println; | ||
use memory::AllocationRequest; | ||
|
||
static TEST_SET: [usize; 9] = [1, 2, 4, 8, 27, 48, 256, 512, 1024]; | ||
|
||
pub fn main(_args: Vec<String>) -> isize { | ||
match rmain() { | ||
Ok(_) => 0, | ||
Err(e) => { | ||
println!("Error: {}", e); | ||
-1 | ||
} | ||
} | ||
} | ||
|
||
fn rmain() -> Result<(), &'static str> { | ||
for num_pages in TEST_SET.into_iter() { | ||
for alignment in TEST_SET.into_iter() { | ||
println!("Attempting to allocate {num_pages} pages with alignment of {alignment} 4K pages..."); | ||
match memory::allocate_pages_deferred( | ||
AllocationRequest::AlignedTo { alignment_4k_pages: alignment }, | ||
num_pages, | ||
) { | ||
Ok((ap, _action)) => { | ||
assert_eq!(ap.start().number() % alignment, 0); | ||
assert_eq!(ap.size_in_pages(), num_pages); | ||
println!(" Success: {ap:?}"); | ||
} | ||
Err(e) => println!(" !! FAILURE: {e:?}"), | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters