ECE 569
Database System Engineering
Spring 2003
Yanyong Zhang www.ece.rutgers.edu/~yyzhang
Course URL www.ece.rutgers.edu/~yyzhang/spring03
ECE569 Lecture 03-1.1
Spring 2003
Warm-up Discussion
How do we access files?
I-node, buddy system
ECE569 Lecture 03-1.2
Spring 2003
Questions to answer in this class?
If a query tries to access tuple T, how can the
system locate where T is?
ECE569 Lecture 03-1.3
Spring 2003
Media and File Management
Abstraction
Array of fixed length blocks
Size varies dynamically, space permitting
Notation
Blocks – File system objects
Pages – Units of virtual address space
Slots – Units of storage on disk
All of these items are identical in size and there is a direct
mapping from one to the other.
We will generally use them interchangeably.
ECE569 Lecture 03-1.4
Spring 2003
Data structure for Block
#define EIGHTK 8192
typedef
unsigned int FILENO;
typedef
unsigned int BLOCKID;
typedef
struct {
int
FILENO
BLOCKID
flip;
fileno;
blockno;
} BLOCKHEAD;
typedef struct
{ BLOCKHEAD
header;
char contents[EIGHTK-sizeof(header)-2];
int flop;
} BLOCK, *BLOCKP;
ECE569 Lecture 03-1.5
Spring 2003
File System API
STATUS create(filename, allocparmp)
-- create and allocate a new file
STATUS delete(filename)
-- delete a file and deallocate space for it
STATUS open(filename,ACCESSMODE,FILEID)
-- Open file in desired mode and return file handle
STATUS close(FILEID)
-- Close an open file
STATUS extend(FILEID,allocparamp)
-- extend existing file by specified amount
STATUS read(FILEID,BLOCKID,BLOCKP)
-- read contents of specified block into a buffer
STATUS readc(FILEID,BLOCKID,blockcount,BLOCKP)
-- read a certain number of block into consecutive buffers in memory.
STATUS write(FILEID,BLOCKID,BLOCKP)
-- write a buffer to the specified block on disk.
STATUS writec(FILEID,BLOCKID,blockcount,BLOCKP)
-- write a number of blocks from consecutive pages to disk.
ECE569 Lecture 03-1.6
Spring 2003
Issues in Managing Disk Space
Initial allocation: When a file is created, how many
contiguous slots should be allocated to it?
Incremental expansion: If an existing file grows
beyond the number of slots currently allocated,
how many additional contiguous blocks should be
assigned to that file?
Reorganization: When and how should the free
space on the disk be reorganized?
ECE569 Lecture 03-1.7
Spring 2003
Free Space Management
+ Bit Map
- One bit represents each block
- Easy to find contiguous free spaces for allocation
+ Free List
- Link free blocks together into a free list
- Can use all techniques for memory free-list
management, first-fit, best-fit, etc.
ECE569 Lecture 03-1.8
Spring 2003
Extent-based Allocation
Provides many of the advantages of contiguous
allocation without many of the problems
The Idea
Allocate an initial chunk that is probably big enough
If file runs out of space, allocate another chunk
Successive allocations increase in size
Characteristics
Good clustering allows efficient sequential I/O
More complex address translation than contiguous
allocation
ECE569 Lecture 03-1.9
Spring 2003
Extent-based Allocation
Why do we need extent directory?
ECE569 Lecture 03-1.10
Spring 2003
Mapping Relations to Disks
ECE569 Lecture 03-1.11
Spring 2003
Buffer Management
ECE569 Lecture 03-1.12
Spring 2003
Logic of Buffer Manager
+ Search in buffer: Check if the requested page is in the buffer. If
found, return the address F of this frame to the caller.
+ Find free frame: If the page is not in the buffer, find a frame that
holds no valid page.
+ Determine replacement victim: If no such frame exists, determine a
page that can be removed from the buffer (in order to reuse its
frame).
+ Write modified page: If replacement page has been changed, write
it.
+ Establish frame address: Denote the start address of the frame as F.
+ Determine block address: Translate the requested PAGEID P into a
FILEID and a block number. Read the block into the frame selected.
+ Return: Return the frame address F to the caller.
ECE569 Lecture 03-1.13
Spring 2003
Lost Update Anomoly
This implies that the buffer
should be shared by multiple
processes.
ECE569 Lecture 03-1.14
Spring 2003
The Need for Synchronization
ECE569 Lecture 03-1.15
Spring 2003
The Fix / Use / Unfix Protocol
+ FIX: The client requests access to a page using the
bufferfix interface.
+ USE: The client uses the page and the pointer to the
frame containing the page will remain valid.
+ UNFIX: The client explicitly waives further usage of the
frame pointer; that is, it tells the buffer manager that it
no longer wants to use that page.
ECE569 Lecture 03-1.16
Spring 2003
The Fix / Use / Unfix Protocol
page P
use
page R
fix page P
use
use
unfix page P
use
fix page R
page Q
unfix page R
use
unfix page Q
use
fix page Q
use
use
ECE569 Lecture 03-1.17
Spring 2003
Buffer Control Blocks
typedef struct {
PAGEID
pageid;
/* id of page in file*/
PAGEPTR
pageaddr;
/* base addr. in buffer*/
Int
index;
/* record within page */
Semaphore
*pagesem;
/* pointer to the sem. */
Boolean
modified;
/* caller modif. page*/
Boolean
invalid;
/* destroyed page
*/
} BUFFER_ACC_CB, *BUFFER_ACC_CBP;
ECE569 Lecture 03-1.18
Spring 2003
Buffer Structure
ECE569 Lecture 03-1.19
Spring 2003
Buffer Control Policies
+ Steal policy: When the buffer manager needs
space, it can decide to replace dirty pages.
+ No-Steal policy: Pages can be replaced only if they
are clean.
+ Force policy: At end of transaction, all modified
pages are forced to disk in a series of
synchronous write operations.
+ No-Force policy: No modified page is forced during
commit. REDO log records are written to the log.
ECE569 Lecture 03-1.20
Spring 2003
© Copyright 2026 Paperzz