• 沒有找到結果。

由於我們的演算法並不複雜,因此在程式實作方面其實也很簡單。並不 需要複雜的運算、也不需要複雜的流程。我們演算法的實作可以分為幾個 部分,分別為 Ranking procedure、Swap procedure、Threshing-avoidance procedure、Re-sampling period adjustment procedure、Lifetime-control procedure、main routine,以及兩個簡單的資料結構。在實作上,我們的 系統並不複雜,整個系統只需要兩個簡單的資料結構以及六個簡單的子程 式,另外需要外部提供兩個 driver,讓我們演算法可以控制系統的硬碟以 及快閃記憶卡。圖表 5 為整個系統的架構圖,箭頭所指方向為 Procedure 會被哪些 Procedure 所使用,如 Lifetime-control procedure 會被 Main routine procedure 所呼叫。

整個系統會分作三個時機分別有不同的流程。首先是一般的讀取資料時,

一開始時會進入 main routine 中,main routine 會決定要到硬碟或快閃記 憶體中取的資料,並且呼叫 Ranking procedure 記錄所有 Cylinder 被讀取 的次數。第二個時機點是當系統判斷 hot period 開始時,main routine 會 呼叫 Lifetime-control procedure 判斷本次 hot period 應該是用 Cylinder 搬 移 次 數 或 是 整 體 效 率 來 調 整 取 樣 週 期 。 當 決 定 調 整 方 式 後 呼 叫 Re-sampling period adjustment procedure 來調整我們的取樣週期。調整 取樣週期後,呼叫 Threshing-avoidance procedure 來取得 filter 值。第 三個時機點是重新取樣,當系統判斷重新取樣時機時,main routine 會呼 叫 Swap procedure 並依據 Hot period 一開始求得的 filter 來搬移預測資 料到快閃記憶體中,在 Swap procedure 會實作取樣演算法以及依據 filter 來決定要搬哪些資料到快閃記憶體。

Block Driver

Main routine

Re-sampling period adjustment procedure

Lifetime-control procedure

Ranking procedure

Threshing-avoidance procedure

Swap procedure

Flash memory card driver

Hard disk driver Cylinder

counter array

Reading request count array of flash

memory

圖表 5 System architecture

Main routine 是我們演算法的主要流程。整個功能分為三部份。當一 般讀取時會判斷從快閃記憶體或是硬碟中拿資料。當 Main routine 判斷 Hot period 開始時,Main routine procedure 會根據 Lifetime-control procedure 來 決 定 要 以 swap 次 數 或 者 以 整 體 效 率 為 考 量 來 啟 動 Re-sampling period adjustment procedure。詳細流程如圖表 6 所示。若 判斷為重新取樣時機時則呼叫 Swap procedure。

圖表 6 Main routine procedure

在 Ranking procedure 需實做兩個部份,第一部份,當平常 reading request 發生時,我們採用 Cylinder 的被讀取次數作為我們的依據值。當 每 Cylinder i 被讀取時,若 Cylinder i 在硬碟中,將 Rd_Hd_count[i]的 Access Count+1,若 Cylinder i 在快閃記憶體中,則將 Rd_flash_count 中 Hd Cylinder=i 的 Read Count+1。第二部份,在每次 resample 時我們必 須統計目前每個 Cylinder 被 Access 的次數,以求出 Cylinders 標準差。

在求出標準差後,我們須判斷標準差是否大於 filter 值(由 filter 演算 法求出)。若大於 filter 時,找出所有 Cylinders 被讀取次數大於標準差 的 Cylinders,並記錄在 CM_Array 中,演算法流程如圖表 7 所示。

CM_array: Cylinder index array that need to be move to flash

Input:

Rd_Hd_count

Calculate SD(stander deviation of CC_array);

i=0;

Element=0;

Output:

CM_ array

While((CC_array[i]>SD)&&(i<sizeof(CC_array))

Rd_Hd_count : Cylinder Counter

array

Reading request of cylinder i income

Rd_Hd_count[i][1]++;

Output:

Rd_Hd_count

圖表 7 ranking procedure

Swap procedure 的功能是決定要搬哪些資料到外閃記憶體中,這個 procedure 將在系統 resample 時被 main routine 呼叫,它的 Input 是 ranking algorithm 所 產 生 的 CM_Array 以 及 Rd_flash_count 。 這 個 procedure 主 要 是 處 理 硬 碟 與 快 閃 記 憶 體 的 Swap 。 Procedure 會 由 Threshing avoidance 演算法取得 filter 值,並根據這個值判斷是否要 將 CM_Array 中的 Cylinders 搬進快閃記憶體中。當要將 Cylinder i 搬到 快 閃 記 憶 體 時 會 將 , 將 Rd_Hd_count[i] 的 Access Count 值 寫 到 Rd_flash_count 中 Hd Cylinder=i 相對應的 Read count 中,當系統將 Cylinder i 從快閃記憶體移除時,將 Rd_flash_count 中 Hd Cylinder=i 的 Read Count 值寫到 Rd_Hd_count[i]相對應的 Access count 中。流程圖 如圖表 8。

procedure Get Filter

Filter : filter from Threshing procedure

While(i<sizeof(CM_array)

Find the element K from Rd_flash_counT with minimum read count;

Cy=Hd Cylinder of emement k rd_count=Read count of emement k

True

False If

((Rd_Hd_count[i][0]-rd_count)>Filter)

Rd_Hd_count[i][0]=rd_count;

Read count of emement k=Rd_Hd_count[i][0];

Hd Cylinder of emement k=I;

Move Cylinder I data to flash;

Rd_Hd_count[i][0]:

Access Count Of cylinder i

True i++;

False

end i++;

我 們 演 算 法 的 第 三 部 份 是 Threshing avoidance procedure , 這 個 procedure 主要的作用在求出 filter 值,在 hot period 一開始時被 main routine 所呼叫,傳入參數為搬入一個 Cylinder 到快閃記憶體的時間,平 均讀取硬碟的時間,平均讀取快閃記憶體的時間。目前這些參數我們參考 硬碟以及快閃記憶體的規格來求出理論值。

我們演算法的第四部份為 Re-sampling period adjustment procedure。

這個 procedure 用來決定下次 hot period 的 resample period 長短。在 hot period 一開始時被 main routine 所呼叫。有兩個部份需要實作,分別 是根據整體效率(圖表 9) 或根據 swap 次數(圖表 10)來動態調整取樣週期 長短。

當我們以整體效率(圖表9)來動態調整resample period長短時,main routine 會傳入參數為前兩次的讀取平均反應時間(Time_respond(T_now),

Time_respond( T_previous ))、目前取樣週期 (Period(resample)) 、最 大的取樣週期(Period(Max))、最小取樣週期(Period(Min))、調整值(K:程 式中設為2,會將取樣週期以2倍或1/2倍的方式調整)。程式會依據演算法 來求得最佳效率的取樣週期。

當我們以整體效率(圖表 10)來動態調整 resample period 長短時,main routine 會傳入參數為前兩次的 Cylinder 搬移次數(SwapCount(T_now),

(SwapCount ( T_previous ))、目前取樣週期 (Period(resample)) 、最 大的取樣週期(Period(Max))、最小取樣週期(Period(Min))、調整值(K:程 式中設為 2,會將取樣週期以 2 倍或 1/2 倍的方式調整)。程式會依據演算 法來求得最符合快閃記憶體寫入限制的取樣週期。

Input:

Time_respond(T_now) : average responds time of read requests at now

Time_respond(T_previous) : Average responds time of read requests at pervious hot period.

Period(Resample) : current re-sampling period

K: parameter of adjusting Period(Resample) , in our algorithm we let k=2.

Period(Max) : the maximum resampling period

Period(Min) :the minimum resampling period Time_respond(T_previous)<Time_respond(T_now)

SwapCount(T_now) : swap count from first read request to current read request today SwapCount(T_previous) : Swap count from first read request to current read request of the day before today

Period(Resample) : current re-sampling period

K: parameter of adjusting Period(Resample) , in our algorithm we let k=2.

Period(Max) : the maximum resampling period

Period(Min) :the minimum resampling period

Period(Resample)=Period(Resample)*K

圖表 10 Re-sampling period adjustment procedure (2) 圖表 9 Re-sampling period adjustment procedure(1)

我們演算法的第五部份是 Lifetime-control procedure(throttling algorithm) 。 這 個 procedure 會 實 作 Lifetime-control algorithm 。 Lifetime-control procedure 中是由 main routine 呼叫,main routine 會 將 系 統 參 數 系 統 使 用 年 限 (Life_time) 、 快 閃 記 憶 體 寫 入 次 數 (Endurance)、快閃記憶體可容納的 Cylinder 數(F_capacity)、今天開始 到目前已經寫入的次數,本次 Hot period 開始的時間(ReadTime(today),

ReadTime(Hour)),然後重新計算。流程如圖表 11

相關文件