Mt bm1

244 views

Published on

aatt

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
244
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mt bm1

  1. 1. Multithreading aware Storage PATCH DESCRIPTION
  2. 2. Goals Make Storage and Buffering Managers multithreading-safe Improve performance by allowing simultaneous operations Provide flexible compile-time options to select optimal behavior
  3. 3. Problem overview Multiple  Buffer and Storage areAccess manager etc threads global shared objects  All above can run inBuffer Manager multiple parallel threads  Needs thread control!Storage Manager ? File
  4. 4. Fine-grained controlAccess manager etc  From bottom to top:  Physical storage is already controlled by OSBuffer Manager  Storage manager can use ??? simple SWMR due SWMR immutability on readStorage Manager concurency  Buffer manager needs something else… OS-based File
  5. 5. Fine-grained control Multiple  Global lock provides onlyAccess manager etc threads safety  No performance benefit!Buffer ManagerStorage Manager Locked! File
  6. 6. Deep down in the Buffer Manager  Underneath BM consists of: External interfaceAccess manager etc Buffer Manager Buffer Buffer Control Block list  Buffer Pool object Pool  List of BufferControl Blocks PagesStorage Manager  Chunk of memory for cached Pages File
  7. 7. Buffer Manager APIclass KAIROSMOBILE_API CBufferManager{  We can identify 3 groups: // ACTUAL API BM_RESULT readPage(TBSID tbsID, PAGEID pageNum, PAGEP&retPage);  read, write and page BM_RESULT writePage(TBSID tbsID, PAGEID pageNum); BM_RESULT fixPage(TBSID tbsID, PAGEID pageNum, PAGEP& retPage); BM_RESULT unFixPage(TBSID tbsID, PAGEID pageNum); pinning API // ALLOCATION API OF Storage Manager BM_RESULT allocPage( TBSID tbsID, PAGEID& pageID );  Allocation API from BM_RESULT freePage( TBSID tbsID, PAGEID pageID ); Storage manager // Unused API BM_RESULT checkPage(TBSID tbsID, PAGEID pageNum); BM_RESULT touchPage(TBSID tbsID, PAGEID pageNum);  Unused part of API BM_RESULT invalidatePage(TBSID tbsID, PAGEID pageNum);} // …  Our goal is first group  More on this later…
  8. 8. Existing algorithm fixPage fixPage( pageId ): // lookup page in BP pageBcb = bp.lookup( pageId ) lookup( page ) if pageBcb found: // in buffer return pageBcb.buf found? // need to read pageBcb = bp.getLRU() getLRU page if pageBcb.isDirty: sm.flushPage( … ) sm.readPage( pageBcb.buf ) return pageBcb.buf dirty? YES flushPage not foundYES readPage
  9. 9. Race condition T1: Read N T2: Read N Not found, read Not found, Reading... read Reading... Read complete Read completeSimple lock can’t solve race conditions in multiple requests, need anothersolution.
  10. 10. New approach Provides per-request lock granularity Solves inconsistency But requires few more changes…
  11. 11. Now  Existing BufferControl block structure  Buffer Pool maintains set Buffer Pool of the BCB in linear and page* prev* LRU listsBCB BCB BCB BCB next* lruprev*  BCB contains lrunext* flags managementPage Page Page information for Page buffers
  12. 12. Changes  Bcb flags have two more states: reading, waiting  Bcb extended with the Buffer Pool page* prev* new field to refer a wait-BCB BCB BCB BCB next* object* lruprev* lrunext*  wait-object is sort of flagsPage Page Page wob conditional variable WOB
  13. 13. New algorithm  Starts with the local lock fixPage LOCK  Looksup page in BP… lookup( page ) YES found? NO getLRU page  If page found, check read reading? dirty? flag in BCB wob assigned? NO assign wob writePage NO  If read we are the first who yields to wait, setup and assign Wait-object mark (waiting) reset flags,found NO set reading  Wait for read to complete not wait on (wob) UNLOCK found free wob readPage  Free Wait-object UNLOCK LOCK  Return page signal (wob) YES waiting? reset flags, set reading UNLOCK return
  14. 14. New algorithm 2  Starts with the local lock fixPage LOCK lookup( page )  Looksup page in BP … YES found? NO getLRU page  If page not found, check reading? dirty flag in BCB dirty? wob  Flush page NO assign wob Withdraw lock assigned? writePage NO found NO mark (waiting) reset flags, set reading  Request read wait on (wob) UNLOCK not found  Hold lock free wob readPage  If waiting flag is set: UNLOCK LOCK  Signal ‘wait complete’ signal (wob) YES waiting?  Reset flags reset flags, set reading  Return page UNLOCK return
  15. 15. New algorithm 3  Note, only requests to fixPage LOCK lookup( page ) the page which is already YES found? NO getLRU page reading are put on hold reading? dirty?  Also, withholding lock wob assigned? NO assign wob writePage NO around ‘read’ call allows NO mark (waiting) reset flags, another threads to proceed non-blockingfound set reading not wait on (wob) UNLOCK found readPage free wob LOCK UNLOCK signal (wob) YES waiting? reset flags, set reading UNLOCK return
  16. 16. Time diagram T1: Read N T2: Read N T3: Read M Not found, read Found, Reading... "reading" Reading... Read Read Waiting on Wob complete complete Signal completion Acquired* Readers can proceed if they request different page and wait if page isloading.
  17. 17. Summary of changes Extending Buffer Control Block with flags and WOB index field Waiting Object (sort of counted conditional variable) and fast-mutex cross-platform primitives Upgrade Buffer Manager algorithm Possible Buffer Manager API consolidation
  18. 18. API Consolidation Consistent BM API:  Currently:  fixPage( id, flags )  readPage is same as:  unfixPage( id )  fixPage + copy + unfix  flushPage( id )  writePage is actually flush  + unused API
  19. 19. Alternatives Access manager etc  Per thread buffer manager does not require anything of the BufferManager Buffer Manager Per thread above  Also can positively affect SWMR thread cache fighting Storage Manager concurency (thrashing)  Only requires SWMR lock on Storage Manager OS-based File
  20. 20. Questions? -

×