Difference between revisions of "THashCache"
From Ultibo.org
(Created page with "Return to Unit Filesystem __TOC__ === Description === ---- ''To be documented'' === Class definitions === ---- <div class="toccolours mw-collapsible...") |
(No difference)
|
Revision as of 04:39, 17 May 2018
Return to Unit Filesystem
Description
To be documented
Class definitions
THashCache = class(TObject)
Note: A block cache with hash keys for faster page lookup. | |
constructor Create(ADriver:TFileSysDriver);
|
|
destructor Destroy; override;
|
|
private
| |
FDriver:TFileSysDriver;
|
|
FLock:TCriticalSectionHandle;
|
|
FKeyBits:Byte;
|
|
FKeyMask:LongWord;
|
|
FKeyBuckets:Pointer;
|
|
FBuffer:Pointer;
|
|
FPageSize:LongWord;
|
|
FPageCount:LongWord;
|
|
FCacheSize:LongWord;
|
|
FCacheKeys:LongWord;
|
|
FCacheMode:TCacheMode;
|
|
FCacheState:TCacheState;
|
|
FFlushTimeout:LongWord;
|
|
FDiscardTimeout:LongWord;
|
|
FReadCached:Int64;
|
|
FReadDirect:Int64;
|
|
FWriteBack:Int64;
|
|
FWriteThrough:Int64;
|
|
FWriteDirect:Int64;
|
|
FHitCount:Int64;
|
|
FMissCount:Int64;
|
|
FFailCount:Int64;
|
|
FSuccessCount:Int64;
|
|
FFlushCount:Int64;
|
|
FDiscardCount:Int64;
|
|
FUnknownCount:Int64;
|
|
FFirstPage:TCachePage;
|
First Cache Page (Any State) |
FLastPage:TCachePage;
|
Last Cache Page (Any State) |
FFirstEmpty:TCachePage;
|
First Free Page |
FLastEmpty:TCachePage;
|
Last Free Page |
FFirstClean:TCachePage;
|
First Clean Page (Used with no Write pending) |
FLastClean:TCachePage;
|
Last Clean Page (Used with no Write pending) |
FFirstDirty:TCachePage;
|
First Dirty Page (Used with Write pending) |
FLastDirty:TCachePage;
|
Last Dirty Page (Used with Write pending) |
FTimer:THashCacheTimer;
|
|
FThread:THashCacheThread;
|
|
function AcquireLock:Boolean;
|
|
function ReleaseLock:Boolean;
|
|
function AddPage(APage:TCachePage):Boolean;
|
|
function RemovePage(APage:TCachePage):Boolean;
|
|
function AddEmpty(APage:TCachePage):Boolean;
|
|
function AddClean(APage:TCachePage):Boolean;
|
|
function AddDirty(APage:TCachePage):Boolean;
|
|
function AddUnknown(APage:TCachePage):Boolean;
|
|
function UpdateClean(APage:TCachePage):Boolean;
|
|
function UpdateDirty(APage:TCachePage):Boolean;
|
|
function RoundPageSize(APageSize:LongWord):LongWord;
|
|
function RoundCacheSize(ACacheSize,APageSize:LongWord):LongWord;
|
|
function AdjustCacheKeys(ACacheKeys:LongWord):LongWord;
|
|
function CalculatePageCount(ADevice:TDiskDevice):Word;
|
|
function CalculatePageShift(ADevice:TDiskDevice):Word;
|
|
function CalculatePageMask(ADevice:TDiskDevice):LongWord;
|
|
function KeyLink(APage:THashCachePage):Boolean;
|
|
function KeyUnlink(APage:THashCachePage):Boolean;
|
|
function KeyFirst(AKeyHash:LongWord):THashCachePage;
|
|
function LinkPage(APage:TCachePage):Boolean;
|
|
function UnlinkPage(APage:TCachePage):Boolean;
|
|
function LinkEmpty(APage:TCachePage):Boolean;
|
|
function UnlinkEmpty(APage:TCachePage):Boolean;
|
|
function LinkClean(APage:TCachePage):Boolean;
|
|
function UnlinkClean(APage:TCachePage):Boolean;
|
|
function LinkDirty(APage:TCachePage):Boolean;
|
|
function UnlinkDirty(APage:TCachePage):Boolean;
|
|
public
| |
property PageSize:LongWord read FPageSize;
|
|
property PageCount:LongWord read FPageCount;
|
|
property CacheSize:LongWord read FCacheSize;
|
|
property CacheKeys:LongWord read FCacheKeys;
|
|
property CacheMode:TCacheMode read FCacheMode;
|
|
property CacheState:TCacheState read FCacheState;
|
|
property FlushTimeout:LongWord read FFlushTimeout;
|
|
property DiscardTimeout:LongWord read FDiscardTimeout;
|
|
property ReadCached:Int64 read FReadCached;
|
|
property ReadDirect:Int64 read FReadDirect;
|
|
property WriteBack:Int64 read FWriteBack;
|
|
property WriteThrough:Int64 read FWriteThrough;
|
|
property WriteDirect:Int64 read FWriteDirect;
|
|
property HitCount:Int64 read FHitCount;
|
|
property MissCount:Int64 read FMissCount;
|
|
property FailCount:Int64 read FFailCount;
|
|
property SuccessCount:Int64 read FSuccessCount;
|
|
property FlushCount:Int64 read FFlushCount;
|
|
property DiscardCount:Int64 read FDiscardCount;
|
|
property UnknownCount:Int64 read FUnknownCount;
|
|
function OpenCache(ACacheSize,ACacheKeys,APageSize:LongWord; ACacheMode:TCacheMode):Boolean;
|
|
function CloseCache:Boolean;
|
|
function DeviceRead(ADevice:TDiskDevice; ASector:LongWord; ACount:Word; var ABuffer):Boolean;
|
|
function DeviceWrite(ADevice:TDiskDevice; ASector:LongWord; ACount:Word; const ABuffer):Boolean;
|
|
function DeviceErase(ADevice:TDiskDevice; ASector:LongWord; ACount:Word):Boolean;
|
|
function GetDevicePage(ADevice:TDiskDevice; ASector:LongWord):TCachePage; virtual;
|
|
function GetEmptyPage:TCachePage;
|
|
function AllocDevicePage(ADevice:TDiskDevice; ASector:LongWord; AWrite:Boolean):TCachePage; virtual;
|
|
function DiscardPage(APage:TCachePage):Boolean;
|
|
function DiscardCache(AFirst,AAll:Boolean):Boolean;
|
|
function ReleaseDevicePages(ADevice:TDiskDevice):Boolean;
|
|
function FlushPage(APage:TCachePage):Boolean;
|
|
function FlushPageEx(APage:TCachePage):Boolean;
|
|
function FlushCache(AFirst,AAll:Boolean):Boolean;
|
|
function CheckTimer:Boolean;
|
|
function ProcessTimer:Boolean;
|
|
function SchedulePage(APage:TCachePage; ATimeout:LongWord):Boolean;
|
|
function UnschedulePage(APage:TCachePage):Boolean;
|
Function declarations
constructor THashCache.Create(ADriver:TFileSysDriver);
Description: To be documented
Note | None documented |
---|
destructor THashCache.Destroy;
Description: To be documented
Note | None documented |
---|
function THashCache.AcquireLock:Boolean;
Description: To be documented
Note | None documented |
---|
function THashCache.ReleaseLock:Boolean;
Description: To be documented
Note | None documented |
---|
function THashCache.AddPage(APage:TCachePage):Boolean;
Description: Add a new page to the Page list and the Empty list
Note | None documented |
---|
function THashCache.RemovePage(APage:TCachePage):Boolean;
Description: Remove a Page from the Page list and any other lists then Free the Page
Note | None documented |
---|
function THashCache.AddEmpty(APage:TCachePage):Boolean;
Description: Add a Page to the Empty list, removing from other lists if needed
Note | None documented |
---|
function THashCache.AddClean(APage:TCachePage):Boolean;
Description: Add a Page to the Clean list, removing from other lists if needed
Note | None documented |
---|
function THashCache.AddDirty(APage:TCachePage):Boolean;
Description: Add a Page to the Dirty list, removing from other lists if needed
Note | None documented |
---|
function THashCache.AddUnknown(APage:TCachePage):Boolean;
Description: Make a Page Unknown by removing from any other lists if needed
Note | None documented |
---|
function THashCache.UpdateClean(APage:TCachePage):Boolean;
Description: Move a Page to the end of the Clean list
Note | None documented |
---|
function THashCache.UpdateDirty(APage:TCachePage):Boolean;
Description: Move a Page to the end of the Dirty list
Note | None documented |
---|
function THashCache.RoundPageSize(APageSize:LongWord):LongWord;
Description: Round Page Size to the power of 2 of Sector Size
Note | Caller must hold the lock |
---|
function THashCache.RoundCacheSize(ACacheSize,APageSize:LongWord):LongWord;
Description: Round Cache Size to the next multiple of Page Size
Note | Caller must hold the lock |
---|
function THashCache.AdjustCacheKeys(ACacheKeys:LongWord):LongWord;
Description: Adjust Cache Keys to be within safe limits
Note | Caller must hold the lock |
---|
function THashCache.CalculatePageCount(ADevice:TDiskDevice):Word;
Description: Calculate the power of 2 multiple of sector size which will fit within the page
Note | Caller must hold the lock |
---|
function THashCache.CalculatePageShift(ADevice:TDiskDevice):Word;
Description: Calculate the shift count for Page to Key conversion
Note | Caller must hold the lock |
---|
function THashCache.CalculatePageMask(ADevice:TDiskDevice):LongWord;
Description: Calculate the mask for Sector to Page conversion
Note | Caller must hold the lock |
---|
function THashCache.KeyLink(APage:THashCachePage):Boolean;
Description: Link APage to KeyPrev,KeyNext siblings and Adjust First
Note | Caller must hold the lock |
---|
function THashCache.KeyUnlink(APage:THashCachePage):Boolean;
Description: Unlink APage from KeyPrev,KeyNext siblings and Adjust First
Note | Caller must hold the lock |
---|
function THashCache.KeyFirst(AKeyHash:LongWord):THashCachePage;
Description: To be documented
Note | Caller must hold the lock |
---|
function THashCache.LinkPage(APage:TCachePage):Boolean;
Description: Link APage to PrevPage,NextPage siblings and Adjust FirstPage/LastPage
Note | Caller must hold the lock |
---|
function THashCache.UnlinkPage(APage:TCachePage):Boolean;
Description: Unlink APage from PrevPage,NextPage Siblings and Adjust FirstPage/LastPage
Note | Caller must hold the lock |
---|
function THashCache.LinkEmpty(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstEmpty/LastEmpty
Note | Caller must hold the lock |
---|
function THashCache.UnlinkEmpty(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstEmpty/LastEmpty
Note | Caller must hold the lock |
---|
function THashCache.LinkClean(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstClean/LastClean
Note | Caller must hold the lock |
---|
function THashCache.UnlinkClean(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstClean/LastClean
Note | Caller must hold the lock |
---|
function THashCache.LinkDirty(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstDirty/LastDirty
Note | Caller must hold the lock |
---|
function THashCache.UnlinkDirty(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstDirty/LastDirty
Note | None documented |
---|
function THashCache.PrepareDeviceWrite(ADevice:TDiskDevice; APage:TCachePage; ASector,ACount:LongWord):Boolean;
Description: Prepare a Cache Page for Write by ensuring that required sectors are cached
Sector | Passed Sector will be the starting sector for the write to this Page |
---|---|
Count | Passed Count will be the write count to this Page (Calculated by caller) |
Note | Only called internally by DeviceWrite
Caller must hold the lock |
function THashCache.CalculateDevicePage(ADevice:TDiskDevice; ASector:LongWord; var ACount:LongWord):Boolean;
Description: Calculate the number of sectors remaining in a page given the starting sector
Note | Only called internally by DeviceRead/DeviceWrite/DeviceErase
Caller must hold the lock |
---|
function THashCache.OpenCache(ACacheSize,ACacheKeys,APageSize:LongWord; ACacheMode:TCacheMode):Boolean;
Description: Allocate the Memory, Create the Empty Pages and Open Cache
Note | None documented |
---|
function THashCache.CloseCache:Boolean;
Description: Flush all Dirty Pages, Release the Memory and Close the Cache
Note | None documented |
---|
function THashCache.DeviceRead(ADevice:TDiskDevice; ASector,ACount:LongWord; var ABuffer):Boolean;
Description: Read Data from the Physical Device using either Cached or Direct access
Note | AllocDevicePage does all checks for Size, Sector and Count. |
---|
function THashCache.DeviceWrite(ADevice:TDiskDevice; ASector,ACount:LongWord; const ABuffer):Boolean;
Description: Write Data to the Physical Device using either Cached or Direct access
Note | AllocDevicePage does all checks for Size, Sector and Count. |
---|
function THashCache.DeviceErase(ADevice:TDiskDevice; ASector,ACount:LongWord):Boolean;
Description: Erase Data from the Physical Device and update cached pages accordingly
Note | None documented |
---|
function THashCache.GetDevicePage(ADevice:TDiskDevice; ASector:LongWord):TCachePage;
Description: Get the Clean or Dirty Page that contains this Sector on this Device
Note | None documented |
---|
function THashCache.GetEmptyPage:TCachePage;
Description: Get the First Empty Page, Discard First Clean Page if none Empty
Note | None documented |
---|
function THashCache.AllocDevicePage(ADevice:TDiskDevice; ASector:LongWord; AWrite:Boolean):TCachePage;
Description: Allocate an Empty Page to the Device and mark as Clean or Dirty
Note | None documented |
---|
function THashCache.DiscardPage(APage:TCachePage):Boolean;
Description: Return a Clean Page to Empty
Note | None documented |
---|
function THashCache.DiscardCache(AFirst,AAll:Boolean):Boolean;
Description: Find any Clean Pages older than DiscardTimeout and Discard them
Note | None documented |
---|
function THashCache.ReleaseDevicePages(ADevice:TDiskDevice):Boolean;
Description: Return all Clean or Dirty Pages on the Device to Empty
Note | None documented |
---|
function THashCache.FlushPage(APage:TCachePage):Boolean;
Description: Return a Dirty Page to Clean
Note | None documented |
---|
function THashCache.FlushPageEx(APage:TCachePage):Boolean;
Description: Return a Dirty Page to Clean if it is older than FlushTimeout
Note | Only called by CacheThread with page scheduled from CacheTimer |
---|
function THashCache.FlushCache(AFirst,AAll:Boolean):Boolean;
Description: Find any Dirty Pages older than FlushTimeout and Flush them
Note | None documented |
---|
function THashCache.CheckTimer:Boolean;
Description: To be documented
Note | None documented |
---|
function THashCache.ProcessTimer:Boolean;
Description: To be documented
Note | None documented |
---|
function THashCache.SchedulePage(APage:TCachePage; ATimeout:LongWord):Boolean;
Description: To be documented
Note | None documented |
---|
function THashCache.UnschedulePage(APage:TCachePage):Boolean;
Description: To be documented
Note | None documented |
---|
Return to Unit Reference