forked from cloud-hypervisor/cloud-hypervisor
-
Notifications
You must be signed in to change notification settings - Fork 2
Speed up dirty_log() (a lot) #36
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
Merged
phip1611
merged 6 commits into
cyberus-technology:gardenlinux
from
blitz:fast-dirty-log
Nov 10, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb632f4
vm-migration: add helper to iterate over bitmaps
blitz 3969729
vm-migration: add itertools as common dependency
blitz db89877
vm-migration: optimize dirty bitmap scanning
blitz 0b05a5d
virtio-devices: mark a possible improvement
blitz ae51f1e
virtio-devices: avoid creating a temporary vector
blitz 4a233e6
vmm: avoid creating large temporary vector during migration
blitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright © 2025 Cyberus Technology GmbH | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /// An iterator that turns a sequence of u64s into a sequence of bit positions | ||
| /// that are set. | ||
| /// | ||
| /// This is useful to iterate over dirty memory bitmaps. | ||
| struct BitposIterator<I> { | ||
| underlying_it: I, | ||
|
|
||
| /// How many u64's we've already consumed. | ||
| word_pos: usize, | ||
|
|
||
| /// If we already started working on a u64, it's here. Together with the bit | ||
| /// position where we have to continue. | ||
| current_word: Option<(u64, u32)>, | ||
| } | ||
|
|
||
| impl<I> Iterator for BitposIterator<I> | ||
| where | ||
| I: Iterator<Item = u64>, | ||
| { | ||
| type Item = u64; | ||
|
|
||
| fn next(&mut self) -> Option<Self::Item> { | ||
| loop { | ||
| if self.current_word.is_none() { | ||
| self.current_word = self.underlying_it.next().map(|w| (w, 0)); | ||
| } | ||
|
|
||
| let (word, word_bit) = self.current_word?; | ||
|
|
||
| // Continue early if there is no chance to find something. | ||
| if word != 0 && word_bit < 64 { | ||
| let shifted_word = word >> word_bit; | ||
| if shifted_word != 0 { | ||
| let zeroes = shifted_word.trailing_zeros(); | ||
|
|
||
| self.current_word = Some((word, zeroes + word_bit + 1)); | ||
| let next_bitpos = | ||
| u64::try_from(self.word_pos).unwrap() * 64 + u64::from(word_bit + zeroes); | ||
|
|
||
| return Some(next_bitpos); | ||
| } | ||
| } | ||
|
|
||
| self.current_word = None; | ||
| self.word_pos += 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub trait BitposIteratorExt: Iterator<Item = u64> + Sized { | ||
| /// Turn an iterator over `u64` into an iterator over the bit positions of | ||
| /// all 1s. We basically treat the incoming `u64` as one gigantic integer | ||
| /// and just spit out which bits are set. | ||
| fn bit_positions(self) -> impl Iterator<Item = u64> { | ||
| BitposIterator { | ||
| underlying_it: self, | ||
| word_pos: 0, | ||
| current_word: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<I: Iterator<Item = u64> + Sized> BitposIteratorExt for I {} | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn bitpos_check(inp: &[u64], out: &[u64]) { | ||
| assert_eq!(inp.iter().copied().bit_positions().collect::<Vec<_>>(), out); | ||
| } | ||
|
|
||
| #[test] | ||
| fn bitpos_iterator_works() { | ||
| bitpos_check(&[], &[]); | ||
| bitpos_check(&[0], &[]); | ||
| bitpos_check(&[1], &[0]); | ||
| bitpos_check(&[5], &[0, 2]); | ||
| bitpos_check(&[3 + 32], &[0, 1, 5]); | ||
| bitpos_check(&[1 << 63], &[63]); | ||
|
|
||
| bitpos_check(&[1, 1 + 32], &[0, 64, 69]); | ||
| } | ||
| } | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.