-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: page cache upper level prepopulation #801
Merged
Merged
Changes from all commits
Commits
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
This file contains 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 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,93 @@ | ||
//! Utility for prepopulating the first N layers of the cache. | ||
|
||
use crate::{ | ||
io::IoHandle, | ||
page_cache::{PageCache, PageMut}, | ||
store::{PageLoad, PageLoader, Store}, | ||
}; | ||
|
||
use nomt_core::page_id::{ChildPageIndex, PageId, MAX_PAGE_DEPTH, NUM_CHILDREN, ROOT_PAGE_ID}; | ||
|
||
/// Prepopulate the given number of levels of the page tree into the page cache. | ||
/// | ||
/// This function blocks until the prepopulation has finished. | ||
pub fn prepopulate( | ||
io_handle: IoHandle, | ||
page_cache: &PageCache, | ||
store: &Store, | ||
levels: usize, | ||
) -> anyhow::Result<()> { | ||
let page_loader = store.page_loader(); | ||
let mut loads = Vec::new(); | ||
|
||
let levels = std::cmp::min(levels, MAX_PAGE_DEPTH); | ||
|
||
// dispatch all page loads recursively. | ||
dispatch_recursive(ROOT_PAGE_ID, &page_loader, &io_handle, &mut loads, levels)?; | ||
|
||
let mut completed = 0; | ||
|
||
// wait on I/O results. | ||
while completed < loads.len() { | ||
let complete_io = io_handle.recv()?; | ||
complete_io.result?; | ||
let load_index = complete_io.command.user_data as usize; | ||
let load = &mut loads[load_index]; | ||
|
||
// UNWRAP: all submitted requests are of kind Read(FatPage). | ||
if let Some((page, bucket)) = load.try_complete(complete_io.command.kind.unwrap_buf()) { | ||
completed += 1; | ||
page_cache.insert( | ||
load.page_id().clone(), | ||
PageMut::pristine_with_data(page).freeze(), | ||
bucket, | ||
); | ||
} else { | ||
// misprobe. try again. | ||
if !page_loader.probe(load, &io_handle, complete_io.command.user_data)? { | ||
// guaranteed empty. | ||
completed += 1; | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
// dispatch page loads for all the children of the given page. | ||
fn dispatch_recursive( | ||
page_id: PageId, | ||
page_loader: &PageLoader, | ||
io_handle: &IoHandle, | ||
loads: &mut Vec<PageLoad>, | ||
levels_remaining: usize, | ||
) -> anyhow::Result<()> { | ||
if levels_remaining == 0 { | ||
return Ok(()); | ||
} | ||
|
||
for child_index in 0..NUM_CHILDREN { | ||
// UNWRAP: all indices up to NUM_CHILDREN are allowed. | ||
let child_index = ChildPageIndex::new(child_index as u8).unwrap(); | ||
|
||
// UNWRAP: depth is not out of bounds and child index is valid. | ||
let child_page_id = page_id.child_page_id(child_index).unwrap(); | ||
|
||
let mut page_load = page_loader.start_load(child_page_id.clone()); | ||
|
||
let next_index = loads.len() as u64; | ||
if page_loader.probe(&mut page_load, io_handle, next_index)? { | ||
// probe has been dispatched. | ||
loads.push(page_load); | ||
dispatch_recursive( | ||
child_page_id, | ||
page_loader, | ||
io_handle, | ||
loads, | ||
levels_remaining - 1, | ||
)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
io::Result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will follow up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no can do unless I panic if the I/O pool goes down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that was the idea!
We do that everywhere so might as well do it here for at least consistency sake.