Difference between revisions of "TIncrementalCache"
From Ultibo.org
(Created page with "Return to Unit Filesystem __TOC__ === Description === ---- ''To be documented'' === Class definitions === ---- <div class="toccolours mw-collapsible...") |
|||
Line 637: | Line 637: | ||
|- | |- | ||
! Note | ! Note | ||
− | | Caller must hold the lock | + | | Caller must hold the lock |
|- | |- | ||
|} | |} |
Revision as of 04:47, 17 May 2018
Return to Unit Filesystem
Description
To be documented
Class definitions
TIncrementalCache = class(TObject)
Note: An expanded THashCache with incremental read ahead and dirty region write back. | |
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:TIncrementalCacheTimer;
|
|
FThread:TIncrementalCacheThread;
|
|
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;
|
|
function PrepareDeviceRead(ADevice:TDiskDevice; APage:TCachePage; var ASector:LongWord; var ACount:Word):Boolean;
|
|
function PrepareDeviceWrite(ADevice:TDiskDevice; APage:TCachePage; var ASector:LongWord; var ACount:Word):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 TIncrementalCache.Create(ADriver:TFileSysDriver);
Description: To be documented
Note | None documented |
---|
destructor TIncrementalCache.Destroy;
Description: To be documented
Note | None documented |
---|
function TIncrementalCache.AcquireLock:Boolean;
Description: To be documented
Note | None documented |
---|
function TIncrementalCache.ReleaseLock:Boolean;
Description: To be documented
Note | None documented |
---|
function TIncrementalCache.AddPage(APage:TCachePage):Boolean;
Description: Add a new page to the Page list and the Empty list
Note | None documented |
---|
function TIncrementalCache.RemovePage(APage:TCachePage):Boolean;
Description: Remove a Page from the Page list and any other lists then Free the Page
Note | None documented |
---|
function TIncrementalCache.AddEmpty(APage:TCachePage):Boolean;
Description: Add a Page to the Empty list, removing from other lists if needed
Note | None documented |
---|
function TIncrementalCache.AddClean(APage:TCachePage):Boolean;
Description: Add a Page to the Clean list, removing from other lists if needed
Note | None documented |
---|
function TIncrementalCache.AddDirty(APage:TCachePage):Boolean;
Description: Add a Page to the Dirty list, removing from other lists if needed
Note | None documented |
---|
function TIncrementalCache.AddUnknown(APage:TCachePage):Boolean;
Description: Make a Page Unknown by removing from any other lists if needed
Note | None documented |
---|
function TIncrementalCache.UpdateClean(APage:TCachePage):Boolean;
Description: Move a Page to the end of the Clean list
Note | None documented |
---|
function TIncrementalCache.UpdateDirty(APage:TCachePage):Boolean;
Description: Move a Page to the end of the Dirty list
Note | None documented |
---|
function TIncrementalCache.RoundPageSize(APageSize:LongWord):LongWord;
Description: Round Page Size to the power of 2 of Sector Size
Note | Caller must hold the lock |
---|
function TIncrementalCache.RoundCacheSize(ACacheSize,APageSize:LongWord):LongWord;
Description: Round Cache Size to the next multiple of Page Size
Note | Caller must hold the lock |
---|
function TIncrementalCache.AdjustCacheKeys(ACacheKeys:LongWord):LongWord;
Description: Adjust Cache Keys to be within safe limits
Note | Caller must hold the lock |
---|
function TIncrementalCache.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 TIncrementalCache.CalculatePageShift(ADevice:TDiskDevice):Word;
Description: Calculate the shift count for Page to Key conversion
Note | Caller must hold the lock |
---|
function TIncrementalCache.CalculatePageMask(ADevice:TDiskDevice):LongWord;
Description: Calculate the mask for Sector to Page conversion
Note | Caller must hold the lock |
---|
function TIncrementalCache.KeyLink(APage:THashCachePage):Boolean;
Description: Link APage to KeyPrev,KeyNext siblings and Adjust First
Note | Caller must hold the lock |
---|
function TIncrementalCache.KeyUnlink(APage:THashCachePage):Boolean;
Description: Unlink APage from KeyPrev,KeyNext siblings and Adjust First
Note | None documented |
---|
function TIncrementalCache.KeyFirst(AKeyHash:LongWord):THashCachePage;
Description: To be documented
Note | Caller must hold the lock |
---|
function TIncrementalCache.LinkPage(APage:TCachePage):Boolean;
Description: Link APage to PrevPage,NextPage siblings and Adjust FirstPage/LastPage
Note | Caller must hold the lock |
---|
function TIncrementalCache.UnlinkPage(APage:TCachePage):Boolean;
Description: Unlink APage from PrevPage,NextPage Siblings and Adjust FirstPage/LastPage
Note | Caller must hold the lock |
---|
function TIncrementalCache.LinkEmpty(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstEmpty/LastEmpty
Note | Caller must hold the lock |
---|
function TIncrementalCache.UnlinkEmpty(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstEmpty/LastEmpty
Note | Caller must hold the lock |
---|
function TIncrementalCache.LinkClean(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstClean/LastClean
Note | Caller must hold the lock |
---|
function TIncrementalCache.UnlinkClean(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstClean/LastClean
Note | Caller must hold the lock |
---|
function TIncrementalCache.LinkDirty(APage:TCachePage):Boolean;
Description: Link APage to PrevLink,NextLink siblings and Adjust FirstDirty/LastDirty
Note | Caller must hold the lock |
---|
function TIncrementalCache.UnlinkDirty(APage:TCachePage):Boolean;
Description: Unlink APage from PrevLink,NextLink Siblings and Adjust FirstDirty/LastDirty
Note | Caller must hold the lock |
---|
function TIncrementalCache.PrepareDeviceRead(ADevice:TDiskDevice; APage:TCachePage; ASector,ACount:LongWord):Boolean;
Description: Prepare an incremental Cache Page for Read by ensuring that all required sectors are cached
Sector | Passed Sector will be the starting sector for the read from this Page |
---|---|
Count | Passed Count will be the read count from this Page (Calculated by caller) |
Note | Only called internally by DeviceRead
Caller must hold the lock |
function TIncrementalCache.PrepareDeviceWrite(ADevice:TDiskDevice; APage:TCachePage; ASector,ACount:LongWord):Boolean;
Description: Prepare an incremental 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 TIncrementalCache.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 TIncrementalCache.OpenCache(ACacheSize,ACacheKeys,APageSize:LongWord; ACacheMode:TCacheMode):Boolean;
Description: Allocate the Memory, Create the Empty Pages and Open Cache
Note | None documented |
---|
function TIncrementalCache.CloseCache:Boolean;
Description: Flush all Dirty Pages, Release the Memory and Close the Cache
Note | None documented |
---|
function TIncrementalCache.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 TIncrementalCache.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 TIncrementalCache.DeviceErase(ADevice:TDiskDevice; ASector,ACount:LongWord):Boolean;
Description: Erase Data from the Physical Device and update cached pages accordingly
Note | None documented |
---|
function TIncrementalCache.GetDevicePage(ADevice:TDiskDevice; ASector:LongWord):TCachePage;
Description: Get the Clean or Dirty Page that contains this Sector on this Device
Note | None documented |
---|
function TIncrementalCache.GetEmptyPage:TCachePage;
Description: Get the First Empty Page, Discard First Clean Page if none Empty
Note | None documented |
---|
function TIncrementalCache.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 TIncrementalCache.DiscardPage(APage:TCachePage):Boolean;
Description: Return a Clean Page to Empty
Note | None documented |
---|
function TIncrementalCache.DiscardCache(AFirst,AAll:Boolean):Boolean;
Description: Find any Clean Pages older than DiscardTimeout and Discard them
Note | None documented |
---|
function TIncrementalCache.ReleaseDevicePages(ADevice:TDiskDevice):Boolean;
Description: Return all Clean or Dirty Pages on the Device to Empty
Note | None documented |
---|
function TIncrementalCache.FlushPage(APage:TCachePage):Boolean;
Description: Return a Dirty Page to Clean
Note | None documented |
---|
function TIncrementalCache.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 TIncrementalCache.FlushCache(AFirst,AAll:Boolean):Boolean;
Description: Find any Dirty Pages older than FlushTimeout and Flush them
Note | None documented |
---|
function TIncrementalCache.CheckTimer:Boolean;
Description: To be documented
Note | None documented |
---|
function TIncrementalCache.ProcessTimer:Boolean;
Description: To be documented
Note | None documented |
---|
function TIncrementalCache.SchedulePage(APage:TCachePage; ATimeout:LongWord):Boolean;
Description: To be documented
Note | None documented |
---|
function TIncrementalCache.UnschedulePage(APage:TCachePage):Boolean;
Description: To be documented
Note | None documented |
---|
Return to Unit Reference