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

Initializes keg_alloc_slab #1278

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion kernel/src/uma/keg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use core::num::NonZero;
pub struct UmaKeg {
size: NonZero<usize>, // uk_size
ipers: usize, // uk_ipers
max_pages: u32, // uk_maxpages
pages: u32, // uk_pages
free: u32, // uk_free
recurse: u32, // uk_recurse
flags: UmaFlags, // uk_flags
}
Expand Down Expand Up @@ -156,6 +159,9 @@ impl UmaKeg {
Self {
size,
ipers,
max_pages: 0,
pages: 0,
free: 0,
recurse: 0,
flags,
}
Expand Down Expand Up @@ -183,7 +189,38 @@ impl UmaKeg {
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x141E20|
pub fn fetch_slab(&self, _: &UmaZone, _: Alloc) -> Option<()> {
pub fn fetch_slab(&mut self, _: &UmaZone, flags: Alloc) -> Option<()> {
while self.free == 0 {
if flags.has(Alloc::NoVm) {
return None;
}

#[allow(clippy::while_immutable_condition)] // TODO: Remove this.
while self.max_pages != 0 && self.max_pages <= self.pages {
todo!()
}

self.recurse += 1;
self.alloc_slab();
self.recurse -= 1;

todo!()
}

todo!()
}

/// See `keg_alloc_slab` on the Orbis for a reference.
///
/// # Reference offsets
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x13FBA0|
fn alloc_slab(&self) {
if self.flags.has(UmaFlags::Offpage) {
todo!()
} else {
todo!()
}
}
}
11 changes: 6 additions & 5 deletions kernel/src/uma/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct UmaZone {
bucket_zones: Arc<Vec<UmaZone>>,
ty: ZoneType,
size: NonZero<usize>, // uz_size
kegs: LinkedList<UmaKeg>, // uz_kegs + uz_klink
slab: fn(&Self, Option<&UmaKeg>, Alloc) -> Option<()>, // uz_slab
kegs: Gutex<LinkedList<UmaKeg>>, // uz_kegs + uz_klink
slab: fn(&Self, Option<&mut UmaKeg>, Alloc) -> Option<()>, // uz_slab
caches: CpuLocal<RefCell<UmaCache>>, // uz_cpu
full_buckets: Gutex<VecDeque<UmaBox<UmaBucket<[BucketItem]>>>>, // uz_full_bucket
free_buckets: Gutex<VecDeque<UmaBox<UmaBucket<[BucketItem]>>>>, // uz_free_bucket
Expand Down Expand Up @@ -123,7 +123,7 @@ impl UmaZone {
bucket_zones,
ty,
size: keg.size(),
kegs: LinkedList::from([keg]),
kegs: gg.clone().spawn(LinkedList::from([keg])),
slab: Self::fetch_slab,
caches: CpuLocal::new(|_| RefCell::default()),
full_buckets: gg.clone().spawn_default(),
Expand Down Expand Up @@ -311,8 +311,9 @@ impl UmaZone {
/// | Version | Offset |
/// |---------|--------|
/// |PS4 11.00|0x141DB0|
fn fetch_slab(&self, keg: Option<&UmaKeg>, flags: Alloc) -> Option<()> {
let keg = keg.unwrap_or(self.kegs.front().unwrap());
fn fetch_slab(&self, keg: Option<&mut UmaKeg>, flags: Alloc) -> Option<()> {
let mut kegs = self.kegs.write();
let keg = keg.unwrap_or(kegs.front_mut().unwrap());

if !keg.flags().has(UmaFlags::Bucket) || keg.recurse() == 0 {
loop {
Expand Down