Performance optimizations in copy_from_non_confidential_memory by wojciechozga · Pull Request #142 · IBM/ACE-RISCV · GitHub
Skip to content

Performance optimizations in copy_from_non_confidential_memory - #142

Open
wojciechozga wants to merge 1 commit into
mainfrom
woz/perf_improvements
Open

wojciechozga wants to merge 1 commit into
mainfrom
woz/perf_improvements

Conversation

@wojciechozga

Copy link
Copy Markdown
Member

Description of the changes

During confidential VM creation, PageTable::copy_from_non_confidential_memory recursively traverses and copies the hypervisor's page table hierarchy into confidential memory, constructing the logical_representation for each page table level (up to 512 entries per page). Previously, building the entry list using .map(...).collect::Result<Vec, Error>>()? caused Rust's internal ResultShunt to report a lower size hint of 0 due to potential error short-circuiting. Consequently the vector started with capacity 0 and was repeatedly resized and reallocated on the heap as entries were processed. Because copy_from_non_confidential_memory runs recursively across every page table in the VM's address space, these redundant reallocations added noticeable latency to VM initialization and memory setup.

This PR replaced the map().collect::<Result<...>>()? pattern with .try_fold(Vec::with_capacity(), ...) eliminating all intermediate reallocations.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Formal verification
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactorization (non-breaking change which improves code quality)

Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
@wojciechozga wojciechozga changed the title Preallocate vector in copy_from_non_confidential_memory Performance optimizations in copy_from_non_confidential_memory Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant