Skip to content

implement MappedPageBox - #2688

Open
RajeshRk18 wants to merge 1 commit into
hermit-os:mainfrom
RajeshRk18:feat/mapped-page-box
Open

implement MappedPageBox#2688
RajeshRk18 wants to merge 1 commit into
hermit-os:mainfrom
RajeshRk18:feat/mapped-page-box

Conversation

@RajeshRk18

Copy link
Copy Markdown

Closes #2338

Added MappedPageBox and used it in two call sites.

Also removed #[expect(dead_code)] in src/arch/aarch64/mm/paging.rs because new public API makes it externally reachable.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Results

Details
Benchmark Current: afb2fd0 Previous: 2e23902 Performance Ratio
startup_benchmark Build Time 94.88 s 80.34 s 1.18
startup_benchmark File Size 0.79 MB 0.80 MB 0.99
Startup Time - 1 core 0.72 s (±0.01 s) 0.75 s (±0.02 s) 0.97
Startup Time - 2 cores 0.73 s (±0.02 s) 0.74 s (±0.02 s) 0.99
Startup Time - 4 cores 0.75 s (±0.02 s) 0.74 s (±0.02 s) 1.02
multithreaded_benchmark Build Time 97.09 s 82.11 s 1.18
multithreaded_benchmark File Size 0.88 MB 0.86 MB 1.03
Multithreaded Pi Efficiency - 2 Threads 66.38 % (±7.07 %) 85.89 % (±6.61 %) 0.77
Multithreaded Pi Efficiency - 4 Threads 40.77 % (±3.21 %) 43.43 % (±2.56 %) 0.94
Multithreaded Pi Efficiency - 8 Threads 20.25 % (±1.62 %) 25.76 % (±1.53 %) 0.79
micro_benchmarks Build Time 228.86 s 80.40 s 2.85
micro_benchmarks File Size 0.88 MB 0.86 MB 1.03
Scheduling time - 1 thread 181.75 ticks (±34.28 ticks) 62.65 ticks (±4.06 ticks) 2.90
Scheduling time - 2 threads 112.33 ticks (±19.87 ticks) 34.08 ticks (±4.10 ticks) 3.30
Micro - Time for syscall (getpid) 9.79 ticks (±5.47 ticks) 3.45 ticks (±0.58 ticks) 2.84
Memcpy speed - (built_in) block size 4096 54954.16 MByte/s (±39455.21 MByte/s) 82448.38 MByte/s (±56997.13 MByte/s) 0.67
Memcpy speed - (built_in) block size 1048576 13800.55 MByte/s (±11052.06 MByte/s) 30585.98 MByte/s (±24707.84 MByte/s) 0.45
Memcpy speed - (built_in) block size 16777216 11602.18 MByte/s (±9567.56 MByte/s) 26340.06 MByte/s (±21720.96 MByte/s) 0.44
Memset speed - (built_in) block size 4096 55175.27 MByte/s (±39573.39 MByte/s) 82292.76 MByte/s (±56891.50 MByte/s) 0.67
Memset speed - (built_in) block size 1048576 14141.22 MByte/s (±11220.95 MByte/s) 31323.85 MByte/s (±25145.86 MByte/s) 0.45
Memset speed - (built_in) block size 16777216 11914.80 MByte/s (±9749.06 MByte/s) 27104.68 MByte/s (±22209.94 MByte/s) 0.44
Memcpy speed - (rust) block size 4096 52099.50 MByte/s (±37357.42 MByte/s) 74097.96 MByte/s (±51811.44 MByte/s) 0.70
Memcpy speed - (rust) block size 1048576 15099.14 MByte/s (±13302.15 MByte/s) 30361.60 MByte/s (±24602.37 MByte/s) 0.50
Memcpy speed - (rust) block size 16777216 12266.05 MByte/s (±10429.45 MByte/s) 27625.34 MByte/s (±22806.88 MByte/s) 0.44
Memset speed - (rust) block size 4096 52678.43 MByte/s (±37705.76 MByte/s) 74373.47 MByte/s (±51976.48 MByte/s) 0.71
Memset speed - (rust) block size 1048576 15352.60 MByte/s (±13395.62 MByte/s) 31110.89 MByte/s (±25033.24 MByte/s) 0.49
Memset speed - (rust) block size 16777216 12627.38 MByte/s (±10644.62 MByte/s) 28386.93 MByte/s (±23265.03 MByte/s) 0.44
alloc_benchmarks Build Time 218.77 s 74.76 s 2.93
alloc_benchmarks File Size 0.87 MB 0.87 MB 0.99
Allocations - Allocation success 91.38 % 91.31 % 1.00
Allocations - Deallocation success 100.00 % 100.00 % 1
Allocations - Pre-fail Allocations 61.60 % 61.44 % 1.00
Allocations - Average Allocation time 16115.33 Ticks (±3060.92 Ticks) 5860.58 Ticks (±98.43 Ticks) 2.75
Allocations - Average Allocation time (no fail) 17985.55 Ticks (±3036.26 Ticks) 6554.81 Ticks (±92.86 Ticks) 2.74
Allocations - Average Deallocation time 7625.61 Ticks (±1503.91 Ticks) 1805.01 Ticks (±250.35 Ticks) 4.22
mutex_benchmark Build Time 228.32 s 79.82 s 2.86
mutex_benchmark File Size 0.88 MB 0.86 MB 1.03
Mutex Stress Test Average Time per Iteration - 1 Threads 36.20 ns (±8.62 ns) 12.10 ns (±0.41 ns) 2.99
Mutex Stress Test Average Time per Iteration - 2 Threads 31.36 ns (±9.11 ns) 40.26 ns (±1.68 ns) 0.78

This comment was automatically generated by workflow using github-action-benchmark.

@mkroening mkroening left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Did you use any AI assistance? :)

Comment thread src/mm/mapped_page_box.rs Outdated
Comment on lines +51 to +54
// `paging::unmap` only flushes the TLB of this CPU. Request the flush on
// all other CPUs before the frames can be reused.
#[cfg(all(target_arch = "x86_64", feature = "smp"))]
crate::arch::kernel::apic::ipi_tlb_flush();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems costly. Is this necessary? We do an IPI TLB flush on mapping after all.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will see how i can come with a better drop

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkroening I removed the call now. But the ipi sent on mapping flushes TLB on other cpus only if the entry is present in the page table. since we delete the entry on unmap, stale TLB can still remains on other cpus.

Comment thread src/mm/mapped_page_box.rs Outdated
Comment on lines +60 to +66
impl Deref for MappedPageBox {
type Target = PageRange;

fn deref(&self) -> &Self::Target {
&self.pages
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems non-obvious to me, since there are two types of ranges inside. If we need something like this, I'd prefer accessor methods.

Comment thread src/mm/mapped_page_box.rs Outdated
Comment on lines +68 to +70
fn page_count(pages: &PageBox) -> usize {
pages.len().get() / BasePageSize::SIZE as usize
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this helper function.

Comment thread src/mm/mapped_page_box.rs Outdated
Comment on lines +72 to +79
fn map(pages: &PageBox, phys_addr: PhysAddr, flags: PageTableEntryFlags) {
paging::map::<BasePageSize>(
VirtAddr::from(pages.start()),
phys_addr,
page_count(pages),
flags,
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this helper function.

@RajeshRk18

Copy link
Copy Markdown
Author

Thanks! Did you use any AI assistance? :)

yeah i am clearing unwanted stuff it added here!

@RajeshRk18
RajeshRk18 marked this pull request as draft August 31, 2026 08:55
@RajeshRk18
RajeshRk18 marked this pull request as ready for review September 3, 2026 15:06
@RajeshRk18
RajeshRk18 requested a review from mkroening September 5, 2026 12:23

@mkroening mkroening left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me. One more suggestion, though.

Comment thread src/mm/mapped_page_box.rs
})
}

pub fn pages(&self) -> &PageBox {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn pages(&self) -> &PageBox {
pub fn pages(&self) -> &PageRange {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider introducing MappedPageBox

2 participants