[kernel] E: Batch page allocation in ELF loader#16
Draft
esaurez wants to merge 1 commit into
Draft
Conversation
Restructure the ELF segment loader to batch-allocate contiguous page runs instead of allocating one page at a time via alloc_upages(1). Pages within each segment are grouped by their clear requirement (data pages that will be overwritten vs BSS pages that must be zeroed) and each contiguous run is allocated with a single alloc_upages(nframes) call. This reduces the number of frame-allocator and page-table operations from O(pages) to O(runs), typically 2-3 per segment (one for the data region and one for the BSS region). To support large batch sizes without exhausting the 128 KB kernel slab, alloc_upages is refactored to process frames in fixed-size chunks (MAX_CHUNK = 32). Each chunk allocates a small Vec that is dropped before the next chunk begins. A rollback helper and a free_remaining_frames helper ensure that both mapped pages and unprocessed frames are properly cleaned up on error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replica of nanvix#2042.
Summary
Batch page allocation in the ELF segment loader and chunk-based processing in alloc_upages to reduce the cost of loading large ELF binaries.
Problem
The ELF loader allocates every page individually. For a ~14 MB binary like Python 3.12 (~3,584 pages), this results in ~3,584 separate frame-allocator + page-table operations.
Changes
ELF segment allocation (elf.rs)
Phase 1: Collect contiguous runs of unmapped pages, allocate each run with a single alloc_upages(nframes) call.
Phase 2: Copy segment data into allocated pages.
Chunked alloc_upages (manager.rs)
Process frames in fixed-size chunks (MAX_CHUNK = 32). Improved error handling with rollback_mapped_pages and free_remaining_frames.
Benchmark (Python 3.12 hello world, WHP standalone)