// Returns a page that starts at the given file offset.
// Precondition: the chunk containing the file offset must be already
// memory-mapped in `grow_for_deserialization()`.
Returns a page that starts at the given file offset.
Precondition: the chunk containing the file offset must be already
memory-mapped in `grow_for_deserialization()`.
Returns a page that starts at the given file offset . Precondition : the chunk containing the file offset must be already memory - mapped in ` grow_for_deserialization () ` .
fn deserialize_page(
        &self,
        serialized_page: &MmapPageSerialization,
        page_allocator: &Arc<MmapBasedPageAllocator>,
    ) -> MmapBasedPage {
        let page_allocator = match self.backing_file_owner {
            BackingFileOwner::CurrentAllocator => Some(page_allocator),
            BackingFileOwner::AnotherAllocator => None,
        };
        let file_offset = serialized_page.file_offset;
        // Find the memory-mapped chunk that contains the given file offset.
        // For a file of length N bytes, there will be O(lg(N)) chunks because
        // allocation ensures that the chunk size increases exponentially.
        // New pages are likely to be in the last chunk, that's why we iterate
        // the chunks in the reverse order. The expected run-time is O(1).
        for chunk in self.chunks.iter().rev() {
            if chunk.offset <= file_offset && file_offset < chunk.offset + chunk.size as FileOffset
            {
                // If the start of the page is in the chunk, then the entire page must be in the
                // chunk.
                assert!(
                    file_offset + PAGE_SIZE as FileOffset
                        <= chunk.offset + chunk.size as FileOffset
                );
                // SAFETY: The chunk is memory-mapped, so the address range from `chunk.ptr` to
                // `chunk.ptr + chunk.size` is valid. The page is fully contained in that
                // address range.
                let page_start = unsafe { chunk.ptr.add((file_offset - chunk.offset) as usize) };
                return MmapBasedPage {
                    ptr: PagePtr(page_start),
                    offset: file_offset,
                    page_allocator: page_allocator.map(Arc::clone),
                    validation: serialized_page.validation,
                };
            }
        }
        // Unreachable based on the precondition.
        unreachable!(
            "Couldn't deserialize a page at offset {}. Current file length {}.",
            file_offset, self.file_len
        );
    }
fn deserialize_page ( & self , serialized_page : & MmapPageSerialization , page_allocator : & Arc < MmapBasedPageAllocator > , ) -> MmapBasedPage { let page_allocator = match self . backing_file_owner { BackingFileOwner :: CurrentAllocator => Some ( page_allocator ) , BackingFileOwner :: AnotherAllocator => None , } ; let file_offset = serialized_page . file_offset ; // Find the memory-mapped chunk that contains the given file offset. // For a file of length N bytes, there will be O(lg(N)) chunks because // allocation ensures that the chunk size increases exponentially. // New pages are likely to be in the last chunk, that's why we iterate // the chunks in the reverse order. The expected run-time is O(1). for chunk in self . chunks . iter ( ) . rev ( ) { if chunk . offset <= file_offset && file_offset < chunk . offset + chunk . size as FileOffset { // If the start of the page is in the chunk, then the entire page must be in the // chunk. assert ! ( file_offset PAGE_SIZE as FileOffset chunk offset chunk size as FileOffset ) ; // SAFETY: The chunk is memory-mapped, so the address range from `chunk.ptr` to // `chunk.ptr + chunk.size` is valid. The page is fully contained in that // address range. let page_start = unsafe { chunk . ptr . add ( ( file_offset - chunk . offset ) as usize ) } ; return MmapBasedPage { ptr : PagePtr ( page_start ) , offset : file_offset , page_allocator : page_allocator . map ( Arc :: clone ) , validation : serialized_page . validation , } ; } } // Unreachable based on the precondition. unreachable ! ( " " file_offset self file_len ) ; }
Returns a page that starts at the given file offset.
Returns a page that starts at the given file offset .
&self
serialized_page
&MmapPageSerialization
page_allocator
&Arc<MmapBasedPageAllocator>