Buffer Management (PowerPoint) by yurtgc548


									    Buffer Management

  Idea: Minimize the amount of disk
I/O by keeping likely-to-be-requested
   pages in memory (buffer frames)

                             John Sieg, UMass Lowell
Relationship to Other DBMS Modules

1. Request record.
2. Fix page.
3. Retrieve page into buffer.
4. Access memory by memory address.   John Sieg, UMass Lowell
         Buffer Manager API
• mem_loc FIX(in page_id)
  – fixed pages never victimized
  – There can be multiple fixes on a single page.
  – Address translation for page is done once, not
    many times.
• UNFIX(in page_id)
  – issued soon after FIX
  – Page may remain in buffer
• Flush(in list of pages)
                                           John Sieg, UMass Lowell
  – needed for atomic recovery
  Implementing the Buffer Pool

•Header records can be statically allocated as an array,
aligned with buffers.
•Why hash table?                           John Sieg, UMass Lowell
memory_address_type FIX (page_id_type page_id)
  memory_address_type buffer_address;
  buffer_record_type *buffer_record;

    hash page_id via buffer table hash function;
    traverse hash bucket, looking for page_id's buffer record;

    if (page identified by page_id has a buffer record buffer_record)
       buffer_address = use_resident_copy(*buffer_record);
    else if free_list is non-empty
       buffer_address = use_free_buffer(page_id);
    else if look_aside_list is non-empty
       buffer_address = victimize_a_look_aside_buffer(page_id);
    else // There are no unfixed buffers.
         handle overcommitment of buffer pool;
    return buffer_address;
}                                                        John Sieg, UMass Lowell
Buffer Pools Compared to File Caches
• Both services hidden from upper layers
• Both cache disk pages in memory and
  maintain look-aside lists
• File cache managers do not support FIX
• Replacement policies and prefetching
  techniques are more effective in buffer
• File cache managers provide little support
  for recovery.                     John Sieg, UMass Lowell
         Replacement Policies
• Only UNFIXed pages (the look-aside list)
  are subject to replacement.
• Motivation: Keep in buffers the pages most
  likely to be referenced
• Policies:
  – LRU (least recently UNFIXed)
  – Clock
  – newer policies that use DBMS’s knowledge of
    reference string                John Sieg, UMass Lowell
Clock Replacement Policy

                     John Sieg, UMass Lowell
       Why It Pays to be Clever
foreach tuple tr of relation r do
  foreach tuple ts of relation s do
     output concat(tr, ts)

                                      Buffer pool

                                            Relation r

                                        Relation s
                                                     John Sieg, UMass Lowell

To top