Storing Data: Disks and Files

Download Report

Transcript Storing Data: Disks and Files

Buffer Management
Storage Technology: Topic 2
Introduction to Database Systems
1
Effective Use of Main Memory
Memory is used as a cache for data on disk
 Issue: Granularity?
 Issue: Updates?
 Issue: Replacement?
 Issue: Efficient lookup?
 Issue: Concurrency?

Introduction to Database Systems
2
Buffer Management in a DBMS
Page Requests from Higher Levels
BUFFER POOL
disk page
free frame
MAIN MEMORY
DISK
DB
choice of frame dictated
by replacement policy
Data must be in RAM for DBMS to operate on it!
 Table of <frame#, pageid> pairs is maintained.

Introduction to Database Systems
3
When a Page is Requested ...

If the page is in the BP, go to 4
 Why would this happen? can it be
encouraged?

Choose a frame to read into.
 How does one do this?
Read page into chosen frame.
 Pin the page and return to caller.

 To avoid thrashing

The caller eventually unpins the page
 Has the page been modified?
Introduction to Database Systems
4
Picking a Frame
If there is a free frame, use it
 Use the page replacement policy to find
a victim frame.
 If victim frame is dirty, write it to disk
(look at the next slide -- Update policy)

Introduction to Database Systems
5
Buffer Manager Details
Granularity : disk page size (4K, 8K)
 Updates : “write-back” not “write-through”
 Efficient lookup : hash table mapping pages
to frames (hash function applied to what?)
 Concurrency : what if several pages are
requested at the same time?
 What if the same page is requested multiply?

Introduction to Database Systems
6
Buffer Replacement Policy
Optimal policy needs to know future
accesses.
 At each stage, the victim should be the page
used furthest into the future.
 Practical repl. policies use a crystal ball.
 Driven by knowledge of application
behavior.
 Least-recently-used (LRU), Clock, MRU, etc.
 Pre-fetch, delayed-write, and other smarts.

Introduction to Database Systems
7
DBMS vs. OS File System
OS does disk space & buffer mgmt: why not
let OS manage these tasks?
 Differences in OS support: portability issues
 Some limitations, e.g., files can’t span disks.
 Buffer management in DBMS requires:
– pinning a page in buffer pool, forcing a page to
disk (important for implementing CC & recovery)
– adjust replacement policy and pre-fetch pages based
on access patterns in typical DB operations
Introduction to Database Systems
8
Summary

Buffer manager brings pages into RAM.
– Page stays in RAM until released by requestor.
– Written to disk when frame chosen for replacement
(which is sometime after requestor releases the page).
– Choice of frame to replace based on replacement policy.
– Tries to pre-fetch several pages at a time.

DBMS vs. OS File Support
– DBMS needs features not found in many OS’s,
Introduction to Database Systems
9