Disk Storage, Basic File Structures, and Hashing: Dr. Hasnaa Raafat Dr. Nora Zakie
Disk Storage, Basic File Structures, and Hashing: Dr. Hasnaa Raafat Dr. Nora Zakie
Chapter 16
Disk Storage,
Basic File Structures, and
Hashing
Dr. Hasnaa Raafat Dr. Nora Zakie
1
Introduction
Primary Storage
can be processed directly by the CPU
e.g., the main memory, cache
fast, expensive, but of limited capacity
Secondary Storage
cannot be processed directly by the CPU
magnetic disks, optical disks, tapes
slow, cost less, but have a large capacity.
2
Storage Hierarchy
Volatile Cache
Primary
storage Memory Unit price
3
Storage of Databases
4
Secondary Storage
Non-volatile
6
Disk Storage Devices (contd.)
7
Disk Storage Devices (contd.)
A read-write head moves to the track that contains the
block to be transferred.
Disk rotation moves the block under the read-write
head for reading or writing.
A physical disk block (hardware) address consists of:
a cylinder number (imaginary collection of tracks of
same radius from all recorded surfaces)
the track number or surface number (within the
cylinder)
and block number (within track).
Reading or writing a disk block is time consuming because
of the seek time s and rotational delay (latency) rd.
Double buffering can be used to speed up the transfer of
contiguous disk blocks.
8
Physical Characteristics of Disks
9
Magnetic Hard Disk Mechanism
NOTE: Diagram is schematic, and simplifies the structure of actual disk drives
10
Components of a Disk
The platters spin (say, 90rps).
The arm assembly is moved in or out to position a
head on a desired track.
Read-write head
Positioned very close to the platter surface
(almost touching it)
Reads or writes magnetically encoded
information.
Only one head reads/writes at any one time.
11
Physical Characteristics of Disks
Track
an information storage circle on the surface of a
disk.
Over 16,000 tracks per platter
each track can store between 4KB and 50KB of
data.
Each track is divided into sectors.
Tracks under heads make a cylinder (imaginary!)
Cylinder
the tracks with the same diameter on all
surfaces of a disk pack.
Cylinder i consists of i-th track of all the
platters
12
Physical Characteristics of Disks
Sector
a part of a track with fixed size
separated by fixed-size inter block gaps
Typical sectors per track
13
Sectors
14
15
Pages and Blocks
16
Pages and Blocks
Track
Gap
Sector
1 page/block = 4 Sectors
17
Page I/O
Page I/O --- one page I/O is the cost (or time needed) to
transfer one page of data between the memory and the disk.
Seek time
time needed to position read/write head on correct
track.
Rotational delay (latency)
time needed to rotate the beginning of page under
read/write head.
Block transfer time
time needed to transfer data in the page/block.
18
Page I/O
Average rotational delay (rd)
rd = ½ * (1/p) min = (60*1000)/(2*p) msec
OR
rd = ½ * cost of 1 revolution
= ½ * (60*1000/p) msec
where
p is speed of disk rotation (how many revolutions
per minute - rpm)
Example
Speed of disk rotation is p = 3600 rpm
60 revolutions/sec
rd = 8.33 ms
19
Page I/O
Transfer rate (tr)
tr = track size / cost of one revolution
= track size / (60*1000/p) in msec
Example:
Track size = 50 KB and p = 3600 rpm
Block size B = 3KB = 3000 bytes
21
Page I/O
22
An Example
A hard disk specifications:
4 platters, 8 Surfaces, 3.5 Inch diameter
213 = 8192 tracks/surface
28 = 256 sectors/track
29 = 512 bytes/sector
Average seek time s = 25 ms
Rotation rate rd = 3600 rpm = 60 rps
1 rev. = 16.66 msec
Transfer rate
tr = 1 KB in 0.117 ms
tr = 1 KB in 0.130 ms with gap
23
An Example
What is the total capacity of this disk
8 GB (8*213*28*29=233)
24
An Example
How long does it take to access one block?
1 2 3 ... 8
1 block = 8 Sectors
26
Buffering
A buffer
is a contiguous reserved area in main memory
available for storage of copies of disk blocks.
to speed up the processes.
27
Accessing Data Through RAM Buffer
RAM
Block transfer
Application Buffer
block
Record
transfer Page frames
28
Buffer Manager
a software component of a DBMS that responds to requests for data and
decides what buffer to use and what pages to replace in the buffer to
accommodate the newly requested blocks.
Programs call on the buffer manager when they need a block from disk.
If the block is already in the buffer,
The requesting program is given the address of the block in main
memory
If the block is not in the buffer,
The buffer manager allocates space in the buffer for the block,
replacing (throwing out) some other block, if required, to make
space for the new block.
The block that is thrown out is written back to disk only if it was
modified since the most recent time that it was written to/fetched
from the disk.
29
Buffer Manager
30
Buffer Replacement Policy:
31