Memory Hierarchy(from primary, faster to secondary and slower memory)
Cache
Main memory
Flash memory
Non volatile
Flash memory will store data even it is powered off.
NAND
Cheaper for a given storage capacity. Used a lot in cameras, phones.
USB(Universal serial bus)
A lot of USB sticks use flash drive.
SSD
Solid state drives.
Magnetic-disk
Optical storage(CD, DVD)
Use laser to read.
Tape
Can only be read sequentially.
Magnetic disk
Each magnetic disk will contain several platter. They are flat, circular. Their surfaces are covered with magnetic material. Plates are usually made of glass or metal.
units on disk
Each disk platter is divided into tracks, and then divided into sectors.
Tracks
Usually a platter contains 50,000 – 100,000 tracks. Inner tracks usually have smaller length(smaller number of sector).
Sectors
Sectors are usually 512 bytes. Each track usually have 500 to 1000 sectors in the inner track. sectors are the smallest “addressable” unit on the disk
Read-write head:
The motor spins the disk at 60, 90, 120 rps(revolution per second).
How read-write head stores information through reversing the direction of the magnetic field.
The head floats above the disk
The head doesn’t touch the plate. The spinning creates breeze that lift the head.
Head crash
Head crash would remove the storage medium. Further more, the removed medium will fly around, causing more crash.
Disk controller
Interface between the disk and the computer system. It is usually with in the disk drive. It accepts read-write command over a sector. controller also moves heads around.
Remapping of bad sectors.
If controller sees a sector become bad, an attempt to write to this sector will let controller logically map the sector to a different physical sector.
Interfaces to OS
SATA(serial ATA)
ATA is a connection standard from 80’s
SCSI(smaller-computer-system interconnect)
SAS(serial attached SCSI
Fibre channel
SAN(Storage area network
Large numbers of disks are connected by a high speed network. The disks are usually organized using RAID (redundant arrays of independent disks). to give a logical view of a very large disk
NAS(network attached storage
It provides a file system interface using networked file system protocols such as NFS
Optimizing disk-block access
Requests for Disk I/O are from vm manager and file system
Blocks
A block is a logical unit consisted of fixed number of contiguous sectors. Sometimes page is used to refer to blocks.
Access disks
Sequential
For successive block numbers. The disk will seek the first block. Then successive request will not require seek. It is a lot faster.
Random access
Just as the name imply
Buffering
Blocks read are stored in an in-memory buffer for future requests.
Read ahead
When reading a block, read in consecutive blocks from the same track.(great for sequential)
Scheduling
When requesting different block, we might benefit from ordering the block requests.
Elevator algorithm
File organization
We can organize blocks such that it corresponds closely to the way the data will be accessed. OS will often allocate multiple consecutive blocks at a time to a file to increase the chance of sequential write.
Fragment
A file that have multiple small appends might become fragmented. The system can make a backup copy of the data and restore the entire disk. This restoration will write back the file sequentially to decrease the fragmentation.
Log disk
Use a disk devoted to writing sequential log. Several consecutive blocks can be written at once. Since log disk can do writes later, the DB don’t have to wait for the write to complete.