Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Storage_system Class Reference

A storage system is simply a file system that stores pages of memory instead of files. More...

#include <storage.h>

Collaboration diagram for Storage_system:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void format (unsigned first_block_to_use=0, Size segment_size=0)
bool is_formatted (unsigned first_block_to_use=0)
void init (unsigned first_block_to_use=0)
void write_superblock (unsigned block_directory=0, unsigned segment_directory=0, unsigned curr_empty_segment=0)
void checkpoint ()
unsigned log_page (void *page, bool update_block_map=true, void *actual_page_addr=NULL)
void free_page (void *page)
unsigned log_map (Address_map &map)
unsigned * load_table (Address_map &map, unsigned dir_index, void *virtual_table)
void load_page (void *virtual_page)
void write_segment ()
void write_segment_if_full ()
bool clean (unsigned segments_to_clean)
void get_live_pages (Segment &segment, Array< void * > &live_pages)
void set_device (Block_device *device)
unsigned block_to_segment_index (unsigned segment_block)
unsigned segment_index_to_block (unsigned segment_index)
void enable ()
void disable ()
bool is_checkpointing_dirty_pages ()
void print ()

Protected Attributes

Block_devicedisk
Segment curr_segment
unsigned first_block
Size blocks_per_segment
Size blocks_per_page
unsigned checkpoint_counter
unsigned curr_superblock
Block_map block_map
Segment_map segment_map
Array< unsigned > cleaned_segments
bool checkpointing_dirty_pages
bool enabled

Static Protected Attributes

const unsigned block_map_id_mask = 1 << 11

Detailed Description

A storage system is simply a file system that stores pages of memory instead of files.

Torsion's particular storage system is of the log-structured variety, which is sort of like a journalling file system, except the entire disk is the journal. An introduction to log-structured storage systems is available in A Log-Structured Persistent Store.


Member Function Documentation

unsigned Storage_system::block_to_segment_index unsigned  segment_block  )  [inline]
 

Convert a disk block address to its corresponding segment index.

(The 0th segment is segment index 0, the 1st segment is segment index 1, etc.)

void Storage_system::checkpoint  ) 
 

Perform a full memory checkpoint to disk.

If necessary, the caller should clean the disk first to free up segments and make room for the pages that will be written during the checkpoint.

bool Storage_system::clean unsigned  segments_to_clean  ) 
 

Compact live pages and recover space used by freed/obsolete pages.

Do this by loading live pages from partially used segments into memory. These live pages will be written to disk on the next checkpoint, leaving behind freed/obsolete pages so that their segments can then be reused for logging. segments_to_clean is the number of segments to clean. Returns true if the given number of segments were actually cleaned, and false otherwise.

void Storage_system::disable  )  [inline]
 

Disable the storage system and prevent page loading.

void Storage_system::enable  )  [inline]
 

Enable the storage system and allow page loading.

void Storage_system::format unsigned  first_block_to_use = 0,
Size  segment_size = 0
 

Given the first block and the segment size in bytes, create the initial data structures on disk necessary for a storage system.

This erases all data on the disk starting from first_block_to_use!

void Storage_system::free_page void *  page  )  [inline]
 

Remove the given page from the block map.

void Storage_system::get_live_pages Segment segment,
Array< void * > &  live_pages
 

Determine the live pages in the segment and append them to the given array.

void Storage_system::init unsigned  first_block_to_use = 0  ) 
 

Initialze this storage system object based on an existing system on disk and perform a recovery if necessary.

This is called on boot.

bool Storage_system::is_checkpointing_dirty_pages  )  [inline]
 

Return true if the checkpointer is running and is currently logging dirty pages to disk.

bool Storage_system::is_formatted unsigned  first_block_to_use = 0  ) 
 

Determine whether a valid Torsion storage system begins on disk at the given block number.

void Storage_system::load_page void *  virtual_page  ) 
 

Attempt to load the page with the given virtual address.

unsigned * Storage_system::load_table Address_map map,
unsigned  dir_index,
void *  virtual_table
 

Attempt to load the Address_map table described by the directory entry at the given directory index and return its temporarily mapped virtual address, even if the table cannot be found on disk.

unsigned Storage_system::log_map Address_map map  ) 
 

Add all the dirty tables and the directory of the given address map to the current checkpoint, returning the block number of the directory on disk.

unsigned Storage_system::log_page void *  page,
bool  update_block_map = true,
void *  actual_page_addr = NULL
 

Add the given in-memory page to the current checkpoint, returning the block number on disk where it was written.

If update_block_map is true, record the disk block of the written page in the block map. If given, actual_page_addr is the address of the page to store as the page's permanent virtual address. This is useful if, for instance, the page argument is just a temporary address.

void Storage_system::print  ) 
 

Print basic information about this Storage_system.

unsigned Storage_system::segment_index_to_block unsigned  segment_index  )  [inline]
 

Convert a segment index to its corresponding disk block address.

void Storage_system::set_device Block_device device  )  [inline]
 

Set the block device upon which this storage system resides.

void Storage_system::write_segment  ) 
 

Write the current segment to disk and start a new one.

void Storage_system::write_segment_if_full  ) 
 

If the current segment is full, write it to disk and start a new one.

void Storage_system::write_superblock unsigned  block_directory = 0,
unsigned  segment_directory = 0,
unsigned  curr_empty_segment = 0
 

Write one of the two fixed-position superblocks at the start of the disk, based on checkpoint_counter, curr_superblock, and the given function arguments.


Member Data Documentation

Block_map Storage_system::block_map [protected]
 

keeps track of live pages on disk

const unsigned Storage_system::block_map_id_mask = 1 << 11 [static, protected]
 

Size Storage_system::blocks_per_page [protected]
 

page size in blocks

Size Storage_system::blocks_per_segment [protected]
 

segment size in blocks

unsigned Storage_system::checkpoint_counter [protected]
 

keeps track of last checkpoint

bool Storage_system::checkpointing_dirty_pages [protected]
 

whether a checkpoint is underway

Array<unsigned> Storage_system::cleaned_segments [protected]
 

recently cleaned segment indices

Segment Storage_system::curr_segment [protected]
 

current disk segment being used

unsigned Storage_system::curr_superblock [protected]
 

where checkpoint will be recorded

Block_device* Storage_system::disk [protected]
 

disk where this store resides

bool Storage_system::enabled [protected]
 

unique block map identifier

unsigned Storage_system::first_block [protected]
 

first block of storage system

Segment_map Storage_system::segment_map [protected]
 

keeps track of segments usage


The documentation for this class was generated from the following files:

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman