1 / 24

CS422 Principles of Database Systems Buffer Management

CS422 Principles of Database Systems Buffer Management. Chengyu Sun California State University, Los Angeles. Memory Hierarchy. CPU. Cache. Memory. Disk. Buffers in a Computer. Disk cache Memory buffer L1, L2, and L3 caches. Why OS Memory Buffer Is Not Enough.

lorichrist
Download Presentation

CS422 Principles of Database Systems Buffer Management

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS422 Principles of Database SystemsBuffer Management Chengyu Sun California State University, Los Angeles

  2. Memory Hierarchy CPU Cache Memory Disk

  3. Buffers in a Computer • Disk cache • Memory buffer • L1, L2, and L3 caches

  4. Why OS Memory Buffer Is Not Enough • DBMS knows its data better • Database buffer management must be coordinated with failure recovery mechanisms

  5. Buffer Manager • A buffer manager is a software component of a DBMS that manages a fixed set of pages, called a buffer pool • Each page in the buffer pool is called a buffer page

  6. Buffer Pool Memory pg1 pg2 pg3 pg4 Buffer pool blk1 blk2 blk3 Disk

  7. Access Data on Disk • Other DBMS components (i.e. client code) access data on disk through the buffer manager // load block #1 into a buffer page Page page = bufferManager.pin( 1 ); // read the int value at position 100 int i = page.getInt( 100 ); // set the int value at position 100 page.setInt( 100, i+10 ); // indicate this page is no longer used bufferManager.unpin( page ); // save the changed data to disk bufferManager.flush( page );

  8. About Disk Access • Disk access has to go through buffer manager • Disk access is by block • Read • Write • Buffer Manager API • pin, unpin, flush

  9. Pin and Unpin • Pin • Load a block into a buffer page • Indicate the buffer page is being used by some client code (i.e. pinned) – how?? • Unpin • Indicate the buffer page is no longer used by the client (i.e. not pinned, or unpinned)

  10. Four Possible Cases for Pin • The block to be pinned is already in the buffer pool • The buffer is not pinned • The buffer is pinned • The block to be pinned is not in the buffer pool • There is at least one unpinned buffer • There is no unpinned buffer

  11. Dirty and Flush • If the data in a page is changed, the page is called a dirty page • Flush • Write a dirty page to disk • When to flush • Before the page is pinned to a different block • At the request of the failure recovery mechanism

  12. Example: Buffer Replacement • Size of buffer pool: 4 • What does the buffer pool looks like after the following requests: pin(1), pin(2), pin(3), pin(4), unpin(3), unpin(1), unpin(2), pin(5), pin(3)

  13. Buffer Replacement Policies • Naïve • Sequentially scan the buffer pool and replace the first unpinned page • Clock • FIFO (First In First Out) • LRU (Least Recently Used)

  14. Naïve Policy Example … After pin(1), pin(2), pin(3), pin(4) pin count: 1 pin count: 1 pin count: 1 pin count: 1 Block 1 Block 2 Block 3 Block 4 Page 1 Page 2 Page 3 Page 4

  15. … Naïve Policy Example … After unpin(3), unpin(1), unpin(2) pin count: 0 pin count: 0 pin count: 0 pin count: 1 Block 1 Block 2 Block 3 Block 4 Page 1 Page 2 Page 3 Page 4

  16. … Naïve Policy Example After pin(5), pin(3) pin count: 1 pin count: 0 pin count: 1 pin count: 1 Block 5 Block 2 Block 3 Block 4 Page 1 Page 2 Page 3 Page 4

  17. Problem of the Naïve Policy • pin(1), unpin(1), pin(2), unpin(2), pin(1), unpin(1), pin(2), unpin(2)…

  18. Clock Policy • Sequentially scan the buffer pool and choose the first unpinned page • Start the next scan at the page after the previous replacement

  19. Clock Policy Example After pin(1), pin(2), pin(3), pin(4) scan start index=1 pin count: 1 pin count: 1 pin count: 1 pin count: 1 Block 1 Block 2 Block 3 Block 4 Page 1 Page 2 Page 3 Page 4

  20. Implementing FIFO and LRU • FIFO • For each buffer page, keeps the time when the block is pinned in • LRU • For each buffer page, keeps the time when the page is unpinned

  21. FIFO Policy Example After pin(1), pin(2), pin(3), pin(4) pin time: 1 pin time: 2 pin time: 3 pin time: 4 pin count: 1 pin count: 1 pin count: 1 pin count: 1 Block 1 Block 2 Block 3 Block 4 Page 1 Page 2 Page 3 Page 4

  22. LRU Policy Example … After pin(1), pin(2), pin(3), pin(4) unpin time: unpin time: unpin time: unpin time: pin count: 1 pin count: 1 pin count: 1 pin count: 1 Block 1 Block 2 Block 3 Block 4 Page 1 Page 2 Page 3 Page 4

  23. … LRU Policy Example After unpin(3), unpin(1), unpin(2) unpin time: 6 unpin time: 7 unpin time: 5 unpin time: pin count: 0 pin count: 0 pin count: 0 pin count: 1 Block 1 Block 2 Block 3 Block 4 Page 1 Page 2 Page 3 Page 4

  24. Readings • Chapter 13.4 and 13.5 of the textbook

More Related