Skip to content

Commit 742528b

Browse files
committed
misc formatting and comments
1 parent 43efbe3 commit 742528b

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ ifeq ($(graphic), no)
882882
endif
883883

884884
## Set the amount of system memory (RAM) provided to the QEMU guest OS
885-
QEMU_MEMORY ?= 3G
885+
QEMU_MEMORY ?= 512M
886886
QEMU_FLAGS += -m $(QEMU_MEMORY)
887887

888888
## Enable multicore CPUs, i.e., SMP (Symmetric Multi-Processor)

applications/test_1gb_huge_pages/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
22
name = "test_1gb_huge_pages"
33
version = "0.1.0"
4-
authors = ["Noah Mogensen <[email protected]>"]
4+
authors = ["Noah Mogensen <[email protected]>"]
5+
description = "Application for testing allocation, mapping, and memory access for 1gb huge pages."
56

67
[dependencies]
78

@@ -12,4 +13,4 @@ path = "../../kernel/memory"
1213
path = "../../kernel/app_io"
1314

1415
# [dependencies.application_main_fn]
15-
# path = "../../compiler_plugins"
16+
# path = "../../compiler_plugins"

applications/test_1gb_huge_pages/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use memory::{
1414

1515

1616
pub fn main(_args: Vec<String>) -> isize {
17+
println!("NOTE: Before running, make sure you Theseus has been run with enough memory (make orun QEMU_MEMORY=3G).");
1718
let kernel_mmi_ref = memory::get_kernel_mmi_ref()
1819
.ok_or("KERNEL_MMI was not yet initialized!")
1920
.unwrap();

applications/test_huge_pages/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
22
name = "test_huge_pages"
33
version = "0.1.0"
4-
authors = ["Noah Mogensen <[email protected]>"]
4+
authors = ["Noah Mogensen <[email protected]>"]
5+
description = "Application for testing allocation, mapping, and memory access for 2mb huge pages."
56

67
[dependencies]
78

@@ -18,4 +19,4 @@ path = "../../kernel/page_allocator"
1819
path = "../../kernel/app_io"
1920

2021
# [dependencies.application_main_fn]
21-
# path = "../../compiler_plugins"
22+
# path = "../../compiler_plugins"

applications/test_huge_pages/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ use memory::{
1616
allocate_frames_at, allocate_pages_at
1717
};
1818

19-
// For checking valid addresses if necessary
19+
// For checking valid test addresses, if necessary
2020
// use frame_allocator::dump_frame_allocator_state;
2121
// use page_allocator::dump_page_allocator_state;
2222

2323
pub fn main(_args: Vec<String>) -> isize {
24+
println!("NOTE: Before running, make sure you Theseus has been run with enough memory (make orun QEMU_MEMORY=3G).");
2425
let kernel_mmi_ref = memory::get_kernel_mmi_ref()
2526
.ok_or("KERNEL_MMI was not yet initialized!")
2627
.unwrap();
@@ -56,7 +57,7 @@ pub fn main(_args: Vec<String>) -> isize {
5657

5758
// frame allocator has not been modified to deal with huge frames yet
5859
let aligned_4k_frames = allocate_frames_at(
59-
PhysicalAddress::new_canonical(0x60000000), //0x1081A000
60+
PhysicalAddress::new_canonical(0x60000000),
6061
512).expect("Could not allocate frames. Make sure you have enough memory for the kernel (compile with make orun QEMU_MEMORY=3G).");
6162

6263
let mut mapped_2mb_page = kernel_mmi_ref.lock().page_table.map_allocated_pages_to(
@@ -89,7 +90,7 @@ pub fn main(_args: Vec<String>) -> isize {
8990

9091
// Dump entries to see if dropping has unmapped everything properly
9192
drop(mapped_2mb_page);
92-
kernel_mmi_ref.lock().page_table.dump_pte(VirtualAddress::new_canonical(0x20000000));
93+
kernel_mmi_ref.lock().page_table.dump_pte(VirtualAddress::new_canonical(0x20000000));
9394

9495
0
9596
}

kernel/memory_structs/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,10 @@ macro_rules! implement_page_frame_range {
605605
}
606606

607607
#[doc = "Returns the offset of the given [`" $address "`] within this `" $TypeName "`, \
608-
i.e., `addr - self.start_address()`.\n\n \
609-
If the given `addr` is not covered by this range of [`" $chunk "`]s, this returns `None`.\n\n \
610-
# Examples\n \
611-
If the range covers addresses `0x2000` to `0x4000`, then `offset_of_address(0x3500)` would return `Some(0x1500)`."]
608+
i.e., `addr - self.start_address()`.\n\n \
609+
If the given `addr` is not covered by this range of [`" $chunk "`]s, this returns `None`.\n\n \
610+
# Examples\n \
611+
If the range covers addresses `0x2000` to `0x4000`, then `offset_of_address(0x3500)` would return `Some(0x1500)`."]
612612
pub const fn offset_of_address(&self, addr: $address) -> Option<usize> {
613613
if self.contains_address(addr) {
614614
Some(addr.value() - self.start_address().value())
@@ -618,11 +618,11 @@ macro_rules! implement_page_frame_range {
618618
}
619619

620620
#[doc = "Returns the [`" $address "`] at the given `offset` into this `" $TypeName "`within this `" $TypeName "`, \
621-
i.e., `self.start_address() + offset`.\n\n \
622-
If the given `offset` is not within this range of [`" $chunk "`]s, this returns `None`.\n\n \
623-
# Examples\n \
624-
If the range covers addresses `0x2000` through `0x3FFF`, then `address_at_offset(0x1500)` would return `Some(0x3500)`, \
625-
and `address_at_offset(0x2000)` would return `None`."]
621+
i.e., `self.start_address() + offset`.\n\n \
622+
If the given `offset` is not within this range of [`" $chunk "`]s, this returns `None`.\n\n \
623+
# Examples\n \
624+
If the range covers addresses `0x2000` through `0x3FFF`, then `address_at_offset(0x1500)` would return `Some(0x3500)`, \
625+
and `address_at_offset(0x2000)` would return `None`."]
626626
pub const fn address_at_offset(&self, offset: usize) -> Option<$address> {
627627
if offset < self.size_in_bytes() {
628628
Some($address::new_canonical(self.start_address().value() + offset))

kernel/page_allocator/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl AllocatedPages {
543543
}
544544
self.pages = PageRangeSized::Normal4KiB(PageRange::new(*self.start(), *ap.end()));
545545
// ensure the now-merged AllocatedPages doesn't run its drop handler and free its pages.
546-
core::mem::forget(ap);
546+
core::mem::forget(ap);
547547
Ok(())
548548
}
549549

@@ -599,10 +599,18 @@ impl Drop for AllocatedPages {
599599
let pages = match self.page_size() {
600600
MemChunkSize::Normal4K => self.pages.range().unwrap().clone(),
601601
MemChunkSize::Huge2M => {
602-
self.pages.into_range_4k().unwrap().range().unwrap().clone() // NOTE: this is truly hideous :(
602+
self.pages.into_range_4k()
603+
.unwrap()
604+
.range()
605+
.unwrap()
606+
.clone()
603607
},
604608
MemChunkSize::Huge1G => {
605-
self.pages.into_range_4k().unwrap().range().unwrap().clone()
609+
self.pages.into_range_4k()
610+
.unwrap()
611+
.range()
612+
.unwrap()
613+
.clone()
606614
}
607615
};
608616

0 commit comments

Comments
 (0)