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

Implements uk_ppera calculation #1248

Merged
merged 1 commit into from
Jan 14, 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
4 changes: 1 addition & 3 deletions kernel/src/config/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
use core::num::NonZero;

pub const PAGE_SIZE: NonZero<usize> = unsafe { NonZero::new_unchecked(0x4000) };
pub const PAGE_SHIFT: usize = 14; // 16K
4 changes: 4 additions & 0 deletions kernel/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
pub use self::arch::*;

use core::num::NonZero;
use macros::elf_note;

#[cfg_attr(target_arch = "aarch64", path = "aarch64.rs")]
#[cfg_attr(target_arch = "x86_64", path = "x86_64.rs")]
mod arch;

pub const PAGE_SIZE: NonZero<usize> = NonZero::new(1 << PAGE_SHIFT).unwrap();
pub const PAGE_MASK: NonZero<usize> = NonZero::new(PAGE_SIZE.get() - 1).unwrap();

#[elf_note(section = ".note.obkrnl.page-size", name = "obkrnl", ty = 0)]
static NOTE_PAGE_SIZE: [u8; size_of::<usize>()] = PAGE_SIZE.get().to_ne_bytes();
4 changes: 1 addition & 3 deletions kernel/src/config/x86_64.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
use core::num::NonZero;

pub const PAGE_SIZE: NonZero<usize> = unsafe { NonZero::new_unchecked(0x1000) };
pub const PAGE_SHIFT: usize = 12; // 4K
53 changes: 48 additions & 5 deletions kernel/src/uma/keg.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::slab::RcFree;
use super::UmaFlags;
use crate::config::PAGE_SIZE;
use crate::config::{PAGE_MASK, PAGE_SHIFT, PAGE_SIZE};
use crate::uma::slab::{Free, SlabHdr};
use crate::uma::Uma;
use core::alloc::Layout;
use core::cmp::max;
use core::cmp::{max, min};
use core::num::NonZero;

/// Implementation of `uma_keg` structure.
Expand All @@ -30,8 +30,28 @@ impl UmaKeg {
flags |= UmaFlags::VToSlab;
}

if flags.has(UmaFlags::CacheSpread) {
todo!()
// Get uk_ppera.
let ppera = if flags.has(UmaFlags::CacheSpread) {
// Round size.
let size = if (size.get() & align) == 0 {
size.get()
} else {
(size.get() & !align) + align + 1
};

// Get uk_rsize.
let align = align + 1;
let rsize = if (size & align) == 0 {
// TODO: What is this?
size + align
} else {
size
};

// Get uk_ppera.
let pages = (PAGE_SIZE.get() / align * rsize) >> PAGE_SHIFT;

min(pages, (128 * 1024) / PAGE_SIZE)
} else {
// Check if item size exceed slab size.
let min = Layout::new::<SlabHdr>();
Expand All @@ -57,6 +77,15 @@ impl UmaKeg {
flags |= UmaFlags::Hash;
}
}

// Get uk_ppera.
let mut ppera = size.get() >> PAGE_SHIFT;

if size.get() > (size.get() & !PAGE_MASK.get()) {
ppera += 1;
}

ppera
} else {
// Get uk_rsize.
let rsize = max(size, Uma::SMALLEST_UNIT);
Expand All @@ -77,8 +106,10 @@ impl UmaKeg {
{
todo!()
}

1
}
}
};

if flags.has(UmaFlags::Offpage) {
if flags.has(UmaFlags::RefCnt) {
Expand All @@ -88,6 +119,18 @@ impl UmaKeg {
}
}

if ppera == 1 {
// TODO: Set uk_allocf and uk_freef.
}

if flags.has(UmaFlags::MtxClass) {
todo!()
}

if !flags.has(UmaFlags::Offpage) {
todo!()
}

todo!()
}
}
2 changes: 2 additions & 0 deletions kernel/src/uma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub enum UmaFlags {
Offpage = 0x8,
/// `UMA_ZONE_MALLOC`.
Malloc = 0x10,
/// `UMA_ZONE_MTXCLASS`.
MtxClass = 0x40,
/// `UMA_ZONE_VM`.
Vm = 0x80,
/// `UMA_ZONE_HASH`.
Expand Down
25 changes: 0 additions & 25 deletions legacy/src/pcpu/mod.rs

This file was deleted.