The Desig f a Flash-based Liux Swap System Yeseug Ryu Mygji Uiversity Octber, 2008
Ctets Overview f liux Swap System Hw des the swap system perates? What are the prblems f flash based swap system? New Swap System Segmet-based swap space maagemet ad fast start-up Blck-aliged read-ahead swap-i scheme Perfrmace evaluati 2
Itrducti All mder geeral-purpse OS use virtual memry techiques. Mst f virtual memry implemetatis divide the virtual address space f a applicati prgram it pages; Page size is usually 4KB i liux. Whe a applicati executes, its ctets (cde ad data) are laded demad it page frames f mai memry. The stack ad heap f the prcess are created i the mai memry demad. 3
Itrducti Whe the free memry is almst used up, the Liux kerel perfrms page frame reclaimig. Page frame reclaimig prcedure picks up victim page frames ad makes them free. If a victim page frame is mapped t a prti f a disk file ad the page is dirty, the kerel writes the ctet f the page frame t the crrespdig disk file. If a victim page frame is t mapped t a disk file like stack ad heap (it is called as aymus pages), the kerel saves the page ctets i a dedicated disk partiti (r a disk file) called swap area. 4
Liux Swap System task pgd page table pte swap ut ivalid slt Swap slt swap i RAM Swap Area (file r partiti) A swap area csists f a sequece f swap slts: 4KB blcks used t ctai a swapped-ut page. Whe a aymus page is selected fr page reclamati, it is swapped ut t the swap area. Swap-i perati ccurs whe a prcess attempts t address a page that has bee swapped ut. Whe a page is swapped-i frm swap area t mai memry, we call its slt ivalid slt. 5
Swap-ut Liux swap system has bee ptimized t reduce disk seek time. I rder t miimize disk seek time, the kerel tries t stre swap-ut pages i ctiguus slts ad thus allcates slts frm the last allcated slt. This simple apprach, hwever, ca icrease the average seek time durig swap-i peratis because may ccupied swap slts may be scattered far away frm e ather. 6
Swap-ut I rder t address this prblem liux kerel restarts allcati frm the begiig f the swap area wheever 256 free slts were allcated after the last restart frm the begiig f the swap area. S, kerel uses slts agai that became free due t swap-i requests. Hwever, whe flash memry is used as swap device, reusig these free slts requires erase peratis. Mrever, sice flash memry des t require seek perati, kerel des t eed t restart allcati frm the begiig f the swap area. 7
Swap-i A swap-i perati tries t read ctiguus eight pages icludig the requested e. Why read-ahead? Lcality prperty : eighbr pages ted t be accessed s. Seek time: sme csecutive pages are read at a time. Whe flash memry is used as swap device, hwever, swap-i perati with read-ahead ca ivalidate the swap slts that lie ver tw erase blcks. I rder t reuse these eight slts t stre swapped-ut pages, we eed tw blck erase peratis. Liux swap-i 8
New swap system Csideratis Fast start-up Miimizig garbage cllecti cst Wear-levelig 9
fast start-up? Whe the system is bted, kerel eeds t clea etire swap space sice the previus data i the swap area are bslete. This cleaig perati makes system start-up time lger.. Wrst cleaig time vs. swap area size 30000 blck size: 128KB blck erase time: 1.5ms erase time (ms) 25000 20000 15000 10000 5000 0 25 secds 512M 1G 1.5G 2G swap area size 10
Swap space maagemet Patet: Segmet based swap space maagemet, Octber, 2008 Swap space is divided it segmets. Swap area (Flash memry), slt erase blck segmet 11
Segmet-based swap space maagemet Each segmet csists f a set f erase blcks. Each segmet has a segmet header which ctais segmet status (used/free) ad erasure cuter. A segmet is a uit f erase. That is, all the blcks i a segmet are erased tgether at a time. Whe the segmet is erased, segmet status becmes free ad erasure cuter is icreased by 1. 12
Segmet-based swap space maagemet Durig the start-up, kerel scas all segmet headers ad cstructs data structure abut segmets i the RAM. After cstructig segmet data structure, kerel determies the umber f segmets which must be erased by start-up prcedure. If there is a give limit f start-up time, start-up prcedure ca clea ly a few segmets. Legth f start-up time vs. amut f free swap space If the kerel des t clea all ivalid segmets, remaiig ivalid segmets will be erased by garbage cllecti prcess afterwards. This space maagemet scheme ca limit start-up time. 13
Segmet-based swap space maagemet We are studyig... Segmet size Start-up time limit Hw may segmets are erased by start-up prcedure Garbage cllecti algrithm Wear-levelig etc 14
Blck-aliged read-ahead swap-i Patet: Read-ahead swap-i methd csiderig flash memry erasure blck, May. 2008 Liux swap-i Blck-aliged swap-i Prpsed scheme reads ahead pages that lie i the same blck. We eed ly e erase perati t reuse swapped-i slts. By reducig the umber f ivalid blcks t be erased, we ca decrease the garbage cllecti (GC) cst. 15
Aalysis f Liux swap I/O traces I rder t evaluate perfrmace, we cllected sme swap I/O traces frm liux kerel. Mst f all, we wat t kw the swap-i behaviur. S, we tured ff read-ahead pti f swap-i befre cllectig the traces. Because we disabled read-ahead pti, all swapped-i pages were laded demad ad we ca examie the pure swap-i behaviur. We examied if the lcality exists i the swap slt accesses due t swap-i peratis. We fud that the tempral/spatial lcality exist i the swap-i refereces 16
Lcality f Swap-i patter These figures shw the slt umbers accessed by swap-i peratis f a particular prcess. slt umber slt umber 6000 5000 4000 3000 2000 1000 0 6000 5000 4000 3000 2000 1000 0 sedmail 0 20 40 60 80 100 120 140 160 180 200 sequece f swap-i Xrg 0 10 20 30 40 50 60 70 sequece f swap-i 17
Read ahead?? Due t lcality, read-ahead is a gd apprach t reduce the disk seek time. Flash memry des t require seek time but read-ahead ca result i better perfrmace. Read-ahead ca decrease the umber f page faults 18
Perfrmace Evaluati We have perfrmed trace-drive simulati t ivestigate the perfrmace f read-ahead swap-i schemes ad garbage cllecti algrithms. Swap-ut : allcates slts sequetially Swap-i: read-ahead 8 pages by liux swap scheme 8 pages by blck-aliged scheme 16 pages by blck-aliged scheme 32 pages by blck-aliged scheme Garbage cllecti algrithms Greedy (GR) Cst-Beefit (CB) Cst-Age-Time (CAT) Cst Beefit with Age (CBA) 19
Perfrmace Evaluati Garbage cllecti algrithms Greedy (GR) : selects a blck with the largest amut f ivalid slts Cst-Beefit (CB) : selects a blck that maximize the frmular: age (1 - u ) 1 + u age : the time sice the mst recet mdificati u : the fracti f space ccupied by valid slts Cst-Age-Time (CAT) : selects a blck that maximize the frmular: 1-1+ u u age erase 1 _ cut Cst Beefit with Age (CBA) : selects a blck like CB ad srts valid slts with ages ad mves the ldest pages first 20
Perfrmace Evaluati Thrugh the simulati, we measured the fllwig perfrmace metrics t calculate the garbage cllecti cst. read cut erase cpy cut : the umber f writes due t GC erase cut Garbage cllecti must cpy the valid slts i the victim blck t the free space befre erasig it. Cpy perati requires read ad write perati. Garbage cllecti cst Cst = read_cut + cpy_cut*10 + erase_cut*75 the write perati is 10 times slwer tha the read perati ad the erase perati is 75 times slwer tha the read perati. 21
erase_cpy_cut Sme Results 250 200 150 100 50 0 GR CB 8_erase_cpy 32_erase_cpy CAT GC algrithms have little effect. The umber f read-ahead has little effect. Blck-aliged read-ahead utperfrms -blck-aliged read-ahead. CBA 16_erase_cpy liux_erase_cpy 22
Sme Results GC Cst As a result, GC cst f prpsed blck-aliged swap-i scheme is almst three times smaller tha liux scheme.
Cclusis Segmet based swap space maagemet ca reduce the start-up time. Blck-aliged read-ahead scheme ca reduce the garbage cllecti cst. We are yet studyig.. 24
Thak yu.. ysryu@mju.ac.kr 25
Swap-i request 26