2.3 快閃記憶體裝置模擬檔 (disksim_nand.c) 實作
2.3.1 存取時間參數
從各廠商的規格可以發現:愈新的快閃記憶體產品支援愈多的帄行化處理 功能及指令,如 cache read、cache program、multi-plane program、multi-plane block erase 和 Multi-plan copy back program。考量模擬器的設計主要是為了量測性能 數據,因此我們捨棄與性能無關的命令,並選擇廣受各廠商支援的命令,作為 快閃記憶體裝置設計(disksim_nand.c)的主要功能,如表 3。
表 3:快閃記憶體裝置支援命令集及其使用時機 NAND 存取命令 使 用 時 機
Status read Page program, block erase 之後的完成狀 態確認
Page read 支援 disksim 中定義的 block read,或單一 block read
Page program 支援 disksim 中定義的 block write
Block erase 由 disksim_ctlrnand.c 決定之 block erase Cache read Disksim 中的多個 blocks read
Cache program Disksim 中的多個 blocks write
Copy back program 由 disksim_ctlrnand.c 中的 FTL callback 決定
tDH Data hold time tWC Write cycle time tWH /WE high hold time
tR Data transfer time from cell to register tAR ALE to /RE Delay
tADL Address to data loading time tWHR /WE high to /RE low
圖 12:Command Latch Cycle [20]
圖 13:Address Latch Cycle [20]
2. Bulk sector transfer time
定義為傳輸 512 字元所需的時間,如圖 14[20]。tRC為讀取資料匯流排時 傳輸 8 位元或 16 位元的時間,tWC(圖 16)為寫入資料匯流排時傳輸 8 位元或 16 位元的時間,若 NAND 為 8-bit 輸入/輸出界面,則為 512*tRC;若為 16-bit 界面,
則為 256*tRC。雖然讀取(tRC)與寫入(tWC)可能不同,不過在我們所參考的規 格中均為相同,故在此我們簡化視為相同。
圖 14:Sequential Out Cycle after Read[20]
3. Cell to reg time
定義:控制器下完 read 命令後,快閃記憶體內部需花費一些時間將資料由 儲存單元讀取自其內部的暫存緩衝區以備讀取,此時 R/B 訊號為 0 的這段時間 等待時間,即為圖 15 [20]之 tR。
圖 15:Read Page Timing[20]
4. Program time
定義:控制器下完 program 命令(0x10)後,快閃記憶體會開始將資料由內 部的緩衝器寫入儲存單元,此時 R/B 訊號為 0 的這段時間,即為圖 16 [20]之 tPROG。
圖 16:Page Program Timing[20]
5. Block erase time
定義:控制器下完 erase 命令(0xd0)後,快閃記憶體會開始清除內部的儲存 單元,此後 R/B 訊號為 0 的這段時間,為圖 17 [20]之 tBERS。
圖 17:Block Erase Timing[20]
6. Write enable high to busy time
定義:自控制器下完 program 命令(0x10)後,至 R/B 訊號由 1 變 0 的這段 時間,為圖 16 之 tWB。
7. Status read time
定義為圖 18[20]之 tDS+tDH+tCLR+tREA+tRHZ。Status read 應用的時機通常是在 block erase 與 page program 之後,用來輪詢快閃記憶體是否已完成前述動作,
並允許接受下一個命令。然而,對於支援 R/B 界面訊號的控制器,控制器可自 動偵測 erase/program 動作是否完成,而不用另外發出 status read 命令,則此 參數可設為 0。
圖 18:Status Read Timing[20]
8. Cache program busy time
定義:控制器下完 cache program 命令(0x15)後,此後 R/B 訊號為 0 的這段 時間,即為圖 19 [20]之 tBLBHS。
圖 19:Cache Program Operation
9. Address to data loading time
定義:在 program 命令中,當控制器傳完位址後必頇延遲一小段時間才能
開始送資料,此延遲時間即為 address to data loading time,即為圖 16 [20]之 tADL。
除了增加 disksim_ctlrnand.c 外,我們也新增 ioreq_event flags 的定義及增 加 disksim_controller.h 內的參數。
2.4.1 ioreq_event flags 的定義
原本控制器在 Disksim 內只是扮演事件分配者的角色(event dispatcher),
為了加入快閃記憶體特有的命令,我們利用 ioreq_event 的 flags 欄位(圖 20), 讓事件可將所需資訊傳至快閃記憶體裝置。我們共加入四個位元,方便經由 Trace file 輸入,如圖 21 粗體所示。這四個位元分別代表事件的屬性:
1. NANDFLAG_BLOCKERASE: 此事件為 erase 命令,而非讀或寫。
2. NANDFLAG_CACHEREAD: 此事件為使用 cache read 命令,而非一般的 page read。
3. NANDFLAG_CACHEWRITE: 此事件為使用 cache program 命令,而非一 般的 page program。
4. NANDFLAG_COPYBACK: 此事件不是單純的讀或寫,而是執行 copy back,即讀取某一 page 後,寫到另一 page。
typedef struct ioreq_ev { double time;
int type;
struct ioreq_ev *next;
struct ioreq_ev *prev;
int bcount;
int blkno;
u_int flags;
u_int busno;
u_int slotno;
int devno;
int opid;
void *buf;
int cause;
…
} ioreq_event;
圖 20:struct ioreq_event
#define DISKSIM_WRITE 0x00000000
#define DISKSIM_READ 0x00000001
#define DISKSIM_TIME_CRITICAL 0x00000002
#define DISKSIM_TIME_LIMITED 0x00000004
#define DISKSIM_TIMED_OUT 0x00000008
#define DISKSIM_HALF_OUT 0x00000010
#define DISKSIM_MAPPED 0x00000020
#define DISKSIM_READ_AFTR_WRITE 0x00000040
#define DISKSIM_SYNC 0x00000080
#define DISKSIM_ASYNC 0x00000100
#define DISKSIM_IO_FLAG_PAGEIO 0x00000200
#define DISKSIM_SEQ 0x40000000
#define DISKSIM_LOCAL 0x20000000
#define DISKSIM_BATCH_COMPLETE 0x80000000
#define NANDFLAG_BLOCKERASE 0x01000000
#define NANDFLAG_CACHEREAD 0x02000000
#define NANDFLAG_CACHEWRITE 0x04000000
#define NANDFLAG_COPYBACK 0x08000000 圖 21:ioreq_event flags 欄位的定義
2.4.2 控制器的參數
因為不是每個控制器都能支援所有的命令,如 cache read,cache program,
而且快閃記憶體與時俱進,未來可能會新加效能更好的命令,因此我們在原有 的 disksim_controller.c 新增參數(圖 22 之 param)以設定其行為。
typedef struct controller { int ctlno;
圖 22:struct controller
#define CTRLNAND_CACHEREAD 0x00000001
#define CTRLNAND_CACHEWRITE 0x00000002
#define CTRLNAND_COPYBACK 0x00000004 圖 23:controller param 定義
圖 23 的參數是用來設定快閃記憶體控制器的能力,若支援這些命令,控 制器將事件傳給裝置時就會設定圖 21 對應的旗標。圖 24 以 cache read 為例:
static inline int CACHEREAD (controller *currctlr) {
return (currctlr->param & CTRLNAND_CACHEREAD)?1:0;
}
static void ctlrnand_check_cacheread (controller *currctlr, ioreq_event *curr)
{
if (CACHEREAD(currctlr) && (curr->bcount > 1)) { curr->flags |= NANDFLAG_CACHEREAD;
} }
圖 24:控制器能力與事件旗標關係(disksim_ctlrnand.c)示例圖
2.4.3 快閃記憶體轉換層(FTL)
快閃記憶體轉換層是優化快閃記憶體儲存系統時常被討論、改進的地方,
主因其牽涉區塊抹除及資料回搬(copy back),而且這是快閃記憶體存取中較 花 時 間 的 部 份 。 因 此 , 我 們 選 擇 在 控 制 中 增 加 轉 換 層 的 界 面 - ctlrnand_ftl_check(),這個副程式可視 FTL 演算法之需要而修改,若需要觸發區 塊抹除的事件,只要呼叫 ctlrnand_issue_blockerase()即可;另外,若需要執行額 外的 page copy,只要呼叫 cltrnand_issue_copypage(),其內會統計其次數作為性 能量測參考。
2.4.4 效能統計輸出
快閃記憶體控制器可輸出資料回搬頁數 (copy back pages) 統計值作為效 能參考。
三、實驗與結果
3.1 實驗帄台
為了驗證我們模擬器的準確性,我們使用圖 25 之 RTD2950系統晶片帄台 來比較實際硬體帄台效能測試的結果與模擬器輸出的效能結果差異。RTD2950 內建 NAND 快閃記憶體控制器存取 圖 26 為實驗帄台使用之快閃記憶體 Hynix HY27UF082G2B。RTD2950 的性能諸元,請見表 6。
圖 25:RTD2950 實驗帄台
圖 26:HY27UF082G2B 照片
表 6:RTD2950 性能諸元 項 目 規 格
CPU MIPS 4KEc
CPU 工作頻率 189 MHz DDR2 工作頻率 378 MHz DDR2 RAM 容量 128 MB NAND IO 工作頻率 7.375 MHz NAND 記憶體容量 256 MB 3.2 Disksim 環境設定
我們使用如圖 27 的設定作為系統拓撲設定,其示意圖如圖 28。
# system topology
topology disksim_iodriver driver0 [ disksim_bus bus0 [
disksim_ctlr ctlr0 [
disksim_bus bus1 [
disksim_nand nand0 []
# end of bus1 ]
# end of ctlr0 ]
# end of bus0 ]
# end of system topology ]
圖 27:實驗環境拓撲設定
driver0 block erase, page read, page program 這些單一命令測試一百次執行的時間,取其 帄均值,其中的參數計算說明如:。
圖 29:NAND0 specification using typical value (RTD2950.parv)
1. Command overhead = 3*(tCLS+tCLH)+4*(tWP+tWH) = 135 ns * 7 = 0.000945 ns
2. Bulk sector transfer time = 512*135 ns = 0.06912 ms
3. Status read time: 因為 RTD2950 的控制器支援 R/B 的狀態讀取,因此 不需額外花費時間發出 read status 的命令,因此設為 0。
表 7:單一命令之模擬與實驗時間比較表
Command A. Disksim (ms) B. RTD2950 (ms) C. 誤差
Block erase 1.501045 1.324519 11.76%
Page read (512 bytes) 0.095065 0.096593 1.61%
Page program (512 Block erase 1.500000 1.322000 Page read (512 bytes) 0.025000 0.021200 Page program (512
Block erase time = 1.322, WEh to busy time = 0.0001, Status read time = 0,
Cache program busy time = 0.003, Addr to data loading time = 0.0001, Never disconnect = 1,
Print stats = 1,
Max queue length = 1, …
} # end of NAND0 spec
圖 30:NAND0 specification using measured value (RTD2950_fix.parv) 表 9:更新參數後之模擬與實驗時間比較表
Command A. Disksim (ms) B. RTD2950 (ms) C. 誤差
Block erase 1.323045 1.324519 0.11%
Page read (512 bytes) 0.091265 0.096593 5.84%
Page program (512 bytes)
0.253185 0.259259 2.40%
我們分析 Page read 仍有較大的誤差原因在於:使用 Disksim 模擬時,並 未加計軟體的運算時間,而在 RTD2950 上測得的數值包含設定控制器與讀取 計時器的軟體運算時間,此部份難以排除。由於 Page read 所耗時間相對地少,
所以前述之軟體運算時間所佔比例便相對地提高了。
不過另一做法是將驗證帄台的軟體運算時間加至 Disksim 的 iodriver 模 擬,這樣也可以改善誤差,進而提高本研究的精確度。
四、結論
Disksim 在研究儲存系統效能上被廣泛運用,而且被證明是精確、彈性、
有效率的工具。我們沿用其既有之架構、功能,加入快閃記憶體的裝置與控制 器模組,除了保有其優點外,使其功能支援 NAND 快閃記憶體儲存系統,並在 一系統晶片帄台驗證其基本命令的正確性。本研究之彈性設計即使不同的控制 器、記憶體也能適用,並可隨著新世代記憶體演進之規格而擴充,提高其可用 性。
經過實驗證明,實際硬體帄台效能測試的結果與模擬器輸出的效能結果差 異在 5.84% 以內,因此本研究可以作為快閃記憶體儲存系統研究(例如:FTL,
Flash 檔案系統研究)的實驗與效能評估帄台。
參考文獻
[1] T. Bisson, S. A. Brandt and D.E. Long, “NVCache: Increasing the Effectiveness of Disk Spin-own Algorithms with Caching,” Proceedings of the 14th IEEE International Symposium on Modeling, Analysis and Simulation of Computer and Telecommunication Systems, 2006. MASCOTS 2006. 14th IEEE International Symposium on, pp. 422 - 432, 11-14 Sept. 2006.
[2] Y. Hu, T. Nightingale and, Q. Yang, “Rapid-Cache: -A Reliable and Inexpensive Write Cache for High Performance Storage Systems,” IEEE Transactions on Parallel and Distributed System, Volume 13, No. 3,: pp. 290 - 307, March Mar. 2002.
[3] Q. Zhu and Y. Zhou, “Power-aware Storage Cache Management,” IEEE Transactions on Computers, Volume 54, No. 5, pp. 587- 602, May 2005.
[4] G. Memik, M. T. Kandemir and A. Choudhary, “Design and Evaluation of Smart Disk Architecture for DSS Commercial Workloads,” Proceedings of the International Conference on Parallel Processing, pp. 335 - 342, 21-24 Aug. 2000.
[5] Y. Zhang, Sudhanva S. Gurumurthi and M. R. Stan, “SODA: Sensitivity Based Optimization of Disk Architecture”, Proceedings of the Design Automation Conference, pp. 865 – - 870, 4-8 June Jun. 2007.
[6] J. S. Bucy, Jiri J. Schindler, Steven S. W. Schlosser and , Gregory G. R. Ganger,
“The Disksim Simulation Environment Version 4.0 Reference Manual”, http://www.pdl.cmu.edu/PDL-FTP/DriveChar/CMU-PDL-08-101.pdf, 2008.
[7] R. Bez, E. Camerlenghi, A. Modelli and A. Visconti. “Introduction to Flash Memory,” Proceedings of the IEEE, Vol. 91, No. 4, pp.489- 502, Apr. 2003.
[8] Numonyx Semiconductor NAND flash memory datasheet, http://www.numonyx.com/Documents/Datasheets/NAND01GWxA2B-KGD.pdf, 2008
[9] E. Gal and S. Toledo, “Algorithms and Data Structures for Flash Memories,” ACM Computing Surveys, Vol. 37, No. 2, pp. 138-163, Jun. 2005.
[11] C. H. Wu , T. W. Kuo, “An Adaptive Two-Level Management for the Flash Translation Layer in Embedded Systems,” Proceedings of the IEEE International Conference on Computer-Aided Design, pp. 601 - 606, Nov. 2006.
[12] J. Kim, J. M. Kim, S. H. Noh, S. L. Min and Y. Cho, “A Space-Efficient Flash Translation Layer for Compact-Flash Systems,” IEEE Transactions on Consumer Electronics, Vol. 48, No. 2, pp. 366 – 375, May 2002.
[13] Ban, “Flash File System”, U.S. Pat. No. 5,404,485, Apr 1995.
[14] Ban, “Flash File System Optimized for Page-mode Flash Technologies”, U.S. Pat.
No. 5,937,,425, Aug 1999.
[15] Intel Corporation, “Understanding the Flash Translation Layer(FTL) Specification”, available at http://www.embeddedfreebsd.org/Documents/Intel-FTL.pdf, Dec 1998.
[16] Intel Corporation, “FTL Logger Exchanging Data with FTL Systems”, available at http://www.myembed.com/down_list/005009/7510.htm, Aug 1995.
[17] S. E.Wells, “Method for Wear Leveling in a Flash EEPROM Memory. US patent 5,341,339. Filed November 1, 1993; Issued August 23, 1994; Assigned to Intel.
[18] M-systems Corporation, “Tow Technologies Compared: NOR vs. NAND White