4. Buffer Management Flashcards
Buffer manager main responsibility
The buffer manager is responsible for managing pages in memory and processing page requests from the file and index manager.
When the buffer manager should communicate with the disk space manager?
When pages are evicted from memory or new pages are read into memory
What are frames? How they are tracked?
Memory is converted into a buffer pool by partitioning the space into frames that pages can be placed in. A buffer frame can hold the same amount of data as a page can (so a page fits perfectly into a frame).
To efficiently track frames, the buffer manager allocates additional space in memory for a metadata table.
Buffer manager metadata table - describe
- Frame ID that is uniquely associated with a memory address
- Page ID for determining which page a frame currently contains
- Dirty Bit for verifying whether or not a page has been modified
- Pin Count for tracking the number of requestors currently using a page
Describe how page requests are handled by the buffer manager
When pages are requested from the buffer manager and the page already exists within memory, the page’s pin count is incremented and the page’s memory address is returned.
If the page does not exist in the buffer pool and there is still space, the next empty frame is found and the page is read into that frame. The page’s pin count is set to 1 and the page’s memory address is returned. In the case where the page does not exist and there are no empty frames left, a replacement policy must be used to determine which page to evict.
Additionally, if the evicted page has the dirty bit set, the page is written to disk to ensure that updates are persisted. The dirty bit is set to 1 if and when a page is written to with updates in memory. The dirty bit is set to 0 once the page is written back to disk.
Once the requestor completes its workload, it is responsible for telling the buffer manager to decrement the pin count associated with pages that it previously used.
Page hit, Page miss, hit rate - def
A page hit is when a requested page can be found in memory without having to go to disk. Each page miss incurs an additional IO cost.
The hit rate for an access pattern is defined as # of page hits / (# of page hits + # of page misses) or more simply, # of page hits / # of page accesses.
LRU replacement policy - describe,
main drawback
When new pages need to be read into a full buffer pool, the least recently used unpinned page (pin count = 0) is evicted. To track page usage, a last used column is added to the metadata table and measures the latest time at which a page’s pin count is decremented.
Implementing LRU normally can be costly
Clock replacement policy - describe
Every page access - set ref to 1.
Eviction:
- Iterate through frames within the table, skipping pinned pages and wrapping around to frame 0 upon reaching the end, until the first unpinned frame with ref bit = 0 is found.
- During each iteration, if the current frame’s ref bit = 1, set the ref bit to 0 and move the clock hand to the next frame (this gives the second chance to frequently used pages).
- Upon reaching a frame with ref bit = 0, evict the existing page (and write it to disk if the dirty bit is set; then set the dirty bit to 0), read in the new page, set the frame’s ref bit to 1, and move the clock hand to the next frame.
When LRU behaves in a bad way?
Pages S, where |S| > buffer pool size, are accessed multiple times repeatedly.
Consider a 3 frame buffer pool using LRU and having the access pattern:
MRU replacement - describe
MRU (Most Recently Used). Instead of evicting the least recently used unpinned page, evict the most recently used unpinned page measured by when the page’s pin count was last decremented.