Presentation is loading. Please wait.

Presentation is loading. Please wait.

The very Essentials of Disk and Buffer Management.

Similar presentations


Presentation on theme: "The very Essentials of Disk and Buffer Management."— Presentation transcript:

1 The very Essentials of Disk and Buffer Management

2 421B: Database Systems - Storing Data 2 Disks and Main Memory q DBMS stores information on (“hard”) disks. q This has major implications for DBMS design! I READ: transfer data from disk to main memory (RAM). I WRITE: transfer data from RAM to disk. I Both are high-cost operations, relative to in-memory operations, so must be planned carefully! q Why disks? I Cheaper than Main Memory I Higher Capacity I Main Memory is volatile q Typical storage hierarchy: I Main memory (RAM) for currently used data. I Disk for the main database (secondary storage). I Tapes for archiving older versions of the data (tertiary storage).

3 421B: Database Systems - Storing Data 3 Disks q Secondary storage device of choice. q Data is stored and retrieved in units called disk blocks or pages. q Time to read/write data block: I 2- 20 msec for random data block (main factor is seek time) I If blocks are sequentially on disk, each additional block only 1 msec I Compare main memory access: in nanoseconds

4 421B: Database Systems - Storing Data 4 Architecture Upper Layer Cache/Buffer Manager Buffer (volatile) Secondary Storage (stable)

5 421B: Database Systems - Storing Data 5 Page Formats: Variable Length Records  Record id (rid) = internal identifier of a record:.  Can move records on page without changing rid; Page i Rid = (i,N) Rid = (i,2) Rid = (i,1) Pointer to start of free space SLOT DIRECTORY N... 2 1 20 16 24 N # slots Record Length

6 421B: Database Systems - Storing Data 6 Buffer Management in a DBMS q Data must be in RAM for DBMS to operate on it! q Table of pairs is maintained. q Some more information about each page in buffer is maintained DB MAIN MEMORY DISK disk page free frame Page Requests from Higher Levels BUFFER POOL choice of frame dictated by replacement policy

7 421B: Database Systems - Storing Data 7 When a Page is Requested... q If requested page is not in pool: I If there is an empty frame l Choose empty frame I Else (no empty frame) l Choose a frame for replacement l If frame is dirty (page was modified), write it to disk I Read requested page into chosen frame q Pin the new page and return its address.

8 421B: Database Systems - Storing Data 8 More on Buffer Management q After operation has finished I Requestor unpins pages I Set dirty bit if page has been modified: I Page in pool may be requested many times: pin count l Page is requested: increase pin count l Unpin: decrease pin count q Frame is chosen for replacement by a replacement policy: I Only unpinned page can be chosen (pin count = 0) I Least-recently-used (LRU), Clock, MRU etc. q Pages are a common lock granularity for the lock manager

9 421B: Database Systems - Storing Data 9 DBMS vs. OS File System OS does disk space & buffer mgmt: why not let OS manage these tasks? q Differences in OS support: portability issues q Some limitations, e.g., files can’t span disks. q Buffer management in DBMS requires ability to: I pin a page in buffer pool, force a page to disk (important for implementing CC & recovery), I adjust replacement policy, and pre-fetch pages based on access patterns in typical DB operations.


Download ppt "The very Essentials of Disk and Buffer Management."

Similar presentations


Ads by Google