1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical...
-
Upload
kenneth-cox -
Category
Documents
-
view
218 -
download
1
Transcript of 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical...
1
CENG334Introduction to Operating Systems
Erol Sahin
Dept of Computer Eng.Middle East Technical University
Ankara, TURKEY
URL: http://kovan.ceng.metu.edu.tr/ceng334
Disks and FilesystemsTopics:
Disks
2
Today: Disks and Filesystems
Physical operation of modern disk drives
Operating system access to raw disk and disk I/O scheduling
Overview of filesystem design
Next lecture: Detailed look at filesystem implementation
Adapted from Matt Welsh’s (Harvard University) slides.
3
A Disk PrimerDisks consist of one or more platters divided into tracks
Each platter may have one or two heads that perform read/write operations Each track consists of multiple sectors The set of sectors across all platters is a cylinder
Aperture
Platter
Heads
Track
Sector
Adapted from Matt Welsh’s (Harvard University) slides.
4
Hard Disk EvolutionIBM 305 RAMAC (1956)
First commercially produced hard drive 5 Mbyte capacity, 50 platters each 24”
in diameter!
Adapted from Matt Welsh’s (Harvard University) slides.
5
Hard Disk Evolution
Adapted from Matt Welsh’s (Harvard University) slides.
6
Disk access time-1
Command overhead: Time to issue I/O, get the HDD to start responding, select appropriate head
Seek time: Time to move disk arm to the appropriate track Depends on how fast you can physically move the disk arm
These times are not improving rapidly
Settle time: Time for head position to stabilize on the selected track
Adapted from Matt Welsh’s (Harvard University) slides.
7
Disk access time-2
Rotational latency: Time for the appropriate sector to move under the disk arm Depends on the rotation speed of the disk (e.g., 7200 RPM)
Transfer time Time to transfer a sector to/from the disk controller Depends on density of bits on disk and RPM of disk rotation Faster for tracks near the outer edge of the disk – why?
Modern drives have more sectors on the outer tracks!
Adapted from Matt Welsh’s (Harvard University) slides.
8
Example disk characteristics Seagate Barracuda 7200.10 320GB Hard Drive Capacity (GB): 320 Interface: Serial ATA-300 Spindle Speed (RPM): 7200 Buffer Memory: 16MB Average Latency (msec): 4.16 Maximum External Transfer Rate (Mbits/sec): 300 Data Transfer Rate on Serial ATA: Up to 3000 Mb/sec Logical Cylinders/Heads/Sectors per Track: 16,383/16/63 Bytes Per Sector: 512 form factor: 3.5”
Disk interface speeds SCSI: From 5 MB/sec to 320 MB/sec ATA: from 33 MB/sec to 100 MB/sec Serial ATA (single wire): Starting at 150 MB/sec Firewire: 50 MB/sec
Adapted from Matt Welsh’s (Harvard University) slides.
9
Disk I/O SchedulingGiven multiple outstanding I/O requests, what order to issue them?
Why does it matter?
Major goals of disk scheduling:
Adapted from Matt Welsh’s (Harvard University) slides.
10
Disk I/O SchedulingGiven multiple outstanding I/O requests, what order to issue them?
Why does it matter?
Major goals of disk scheduling:
1) Minimize latency for small transfers Primarily: Avoid long seeks by ordering accesses according to disk head locality
2) Maximize throughput for large transfers Large databases and scientific workloads often involve enormous files and datasets
Note that disk block layout also has a large impact on performance Where we place file blocks, directories, file system metadata, etc.
Adapted from Matt Welsh’s (Harvard University) slides.
11
Disk I/O SchedulingGiven multiple outstanding I/O requests, what order to issue them?
FIFO: Just schedule each I/O in the order it arrives What's wrong with this?
Adapted from Matt Welsh’s (Harvard University) slides.
12
Disk I/O SchedulingGiven multiple outstanding I/O requests, what order to issue them?
FIFO: Just schedule each I/O in the order it arrives What's wrong with this? Potentially lots of seek time!
SSTF: Shortest seek time first Issue I/O with the nearest cylinder to the current one Why might this not work so well???
Adapted from Matt Welsh’s (Harvard University) slides.
13
Disk I/O SchedulingGiven multiple outstanding I/O requests, what order to issue them?
FIFO: Just schedule each I/O in the order it arrives What's wrong with this? Potentially lots of seek time!
SSTF: Shortest seek time first Issue I/O with the nearest cylinder to the current one Favors middle tracks: Head rarely moves to edges of disk
SCAN (or Elevator) Algorithm: Head has a current direction and current cylinder Sort I/Os according to the track # in the current direction of the head If no more I/Os in the current direction, reverse direction
CSCAN Algorithm: Always move in one direction, “wrap around” to beginning of disk when
moving off the end Idea: Reduce variance in seek times, avoid discriminating against the highest and lowest
tracks
Adapted from Matt Welsh’s (Harvard University) slides.
14
SCAN example
Current track
Direction
Adapted from Matt Welsh’s (Harvard University) slides.
15
SCAN example
Current track
Direction
Adapted from Matt Welsh’s (Harvard University) slides.
16
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
17
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
18
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
19
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
20
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
21
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
22
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
23
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
24
SCAN example
Direction
Current track
Adapted from Matt Welsh’s (Harvard University) slides.
25
SCAN example
Direction
Current track
What is the overhead of the SCAN algorithm? Count the total amount of seek time to service all I/O requests In this case, 12 tracks in --> direction 15 tracks for long seek back 5 tracks in <-- direction
Total: 12+15+5 = 32 tracks
Adapted from Matt Welsh’s (Harvard University) slides.
26
ATA and IDE InterfacesIDE stands for Integrated (or “Intelligent”) Drive Electronics
Same as “ATA” (Advanced Technology Attachment) Standard interface to hard drives that integrate a drive controller in the drive itself 1 or 2 drives on a chain
Enhanced IDE (EIDE) and ATA-2 Faster version of ATA/IDE that supports Direct Memory Access (DMA) transfers
Ultra ATA: Speed enhancements to ATA standard Versions running at 33, 66, and 100 Mbytes/sec
Serial ATA: Emerging standard using a serial (not parallel) interface Speeds starting at 150 Mbyte/sec Can drive longer cables at much higher clock speeds than parallel cable
Serial ATA
Rounded parallel ATA
Parallel ATA
27
SCSI InterfaceStandard hardware interface to wide range of I/O devices
Disks, CDs, DVDs, tapes, etc. Bus-based design: single shared set of I/O lines that all devices connect to
Access model using logical blocks on disk On-disk controller maps logical block # to sector/track/head combination
SCSI-1: 8-bit bus, 5 Mhz = 5 Mbytes/sec max speed Supported up to 8 devices on a single bus Lots of problems with termination: required physical connector on end of cable to avoid
signal refraction!
SCSI-2: The next generation Fast SCSI: 10 Mhz clock speed Wide SCSI: 16 bit bus width Fast wide SCSI: 10 Mhz + 16 bit bus = 20 MB/sec throughput
SCSI-3: Ramping up on speed and bus width Highest speed now is “Ultra320 SCSI”: 160 Mhz x 16 bits = 320 MB/sec max speed
28
Relative Interconnect Speeds(from macspeedzone.com)
USB 3.0 standard established in 2007 supports speeds upto 5GBps
29
CENG334Introduction to Operating Systems
Erol Sahin
Dept of Computer Eng.Middle East Technical University
Ankara, TURKEY
Filesystems and their interfaceTopics:
30
Filesystems
A filesystem provides a high-level application access to disk As well as CD, DVD, tape, floppy, etc...
Masks the details of low-level sector-based I/O operations
Provides structured access to data (files and directories)
Caches recently-accessed data in memory
Adapted from Matt Welsh’s (Harvard University) slides.
31
Filesystems
Essential requirements for long term storage: It must be possible to store a very large amount of information. The information must survive the termination of the process using it. Multiple processes must be able to access the information concurrently.
Think of a disk as a linear sequence of fixed-size blocks and supporting reading and writing of blocks. Questions that quickly arise:
How do you find information? How do you keep one user from reading another’s data? How do you know which blocks are free?
Slide adapted from: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
33
File ConceptFile is a logical storage unit abstraction provided by the
operating system.
Files are mapped by the operating system onto physical devices (disks, tapes, CDs, etc..)
From the user point of view, file is the only unit through which data can be written onto storage devices.
The information in a file as well as the attributes of the file is determined by its creator.
Data Numeric/character/binary
Program
When a file is created, it becomes independent of the process, the user and even the system that created it.
34
File OperationsOS provides a number of minimal operations on a file.
Create Allocate space and then make an entry in the directory
Write Requires name of the file, and the information to be written Search the directory to find file’s location. Keep a write-pointer to the location in the file Update the pointer after each write
Read Requires name of the file, and the information to be read Search the directory to find file’s location. Keep a read-pointer to the location in the file Update the pointer after each read
Reposition within file Change the value of the file-position pointer
Delete Deallocate the space and remove the entry
Truncate Change the allocated space to zero, and deallocate its space
File-position pointer
35
File Attributes
Name – only information kept in human-readable form
Identifier – unique tag (number) identifies file within file system
Type – needed for systems that support different types
Location – pointer to file location on device
Size – current file size
Protection – controls who can do reading, writing, executing
Time, date, and user identification – data for protection, security, and usage monitoring
Information about files are kept in the directory structure, which is maintained on the disk
36
File Types – Name, Extension
The file type provides information on what can be done with that file to the OS.
Typically implemented as the extension of the filename.
In UNIX systems, a crude “magic number” is stored at the beginning of some files to indicate the type of the file (executable/shell script..)
In Mac OS X, each file has a type TEXT/APPL. Each file also has a creator attribute that is set to the program that created it.
37
File Structure
None - sequence of words, bytes This is the structure supported by UNIX systems
Simple record structure Lines Fixed length Variable length
Complex Structures Formatted document Relocatable load file
Can simulate last two with first method by inserting appropriate control characters
Who decides: Operating system Program
38
Access MethodsSequential Access
read next
write next
reset
no read after last write
(rewrite)
Direct Access (available when the file is made up of fixed-length logical records, useful in databases)
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
39
Open Files
Most file operations require searching the directory for the entry associated with the file. To avoid this constant search, most systems require that file be “open”ed, before its use.
Open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory
Close (Fi) – move the content of entry Fi in memory to directory structure on disk
Several pieces of data are needed to manage open files: File pointer: pointer to last read/write location, per process that has the file
open File-open count: counter of number of times a file is open – to allow removal of
data from open-file table when last processes closes it Disk location of the file: cache of data access information Access rights: per-process access mode information
40
Open File Locking
Provided by some operating systems and file systems
Mediates access to a file
Mandatory or advisory: Mandatory – access is denied depending on locks held and requested Advisory – processes can find status of locks and decide what to do
41
Example Program Using File System Calls (1)
Figure 4-5. A simple program to copy a file.
42
Example Program Using File System Calls (2)
Figure 4-5. A simple program to copy a file.
44
Operations Performed on Directory
A directory is effectively a symbol table that translates file names into their directory entries.
Search for a file Given a name or a pattern of names, we should be able to find all the files
that use it. Create a file
touch assignment3.c Delete a file
rm assignment3.c List a directory
ls Rename a file
mv assignment3.c odev3.c Traverse the file system
cd include
45
Organize the Directory (Logically) to Obtain
Efficiency – locating a file quickly
Naming – convenient to users Two users can have same name for different files The same file can have several different names
Grouping – logical grouping of files by properties, (e.g., all Java programs, all games, …)
46
Single-Level Directory
A single directory for all users
Naming problem:Who will use the name assignment3.c?Each student has to use a different name: e123456-assignment3.c
Grouping problemListing would be very crowdy.
47
Two-Level DirectorySeparate directory for each user
Path name In MS-DOS, C:\userx\test.bat In VMS, volume:[userx.home]test.bat;1
Can have the same file name for different user Efficient searching No grouping capability
48
Tree-Structured Directories
A directory is simply another file that needs to be treated in a special way.
49
Tree-Structured Directories (Cont)
Efficient searchingdirectory entry sizes would be manageable
Grouping Capability
Current directory (working directory) cd /spell/mail/prog type list
50
Tree-Structured Directories (Cont)Absolute or relative path name
Creating a new file is done in current directory
Delete a file
rm <file-name>
Creating a new subdirectory is done in current directorymkdir <dir-name>
Example: if in current directory /mail
mkdir count
prog copy prt exp count
Deleting “mail” deleting the entire subtree rooted by “mail”
51
Acyclic-Graph DirectoriesHave shared subdirectories and files
52
Acyclic-Graph Directories (Cont.)
Two different names (aliasing)
If dict deletes list dangling pointer
Solutions: Backpointers, so we can delete all pointers
Variable size records a problem Backpointers using a daisy chain organization Entry-hold-count solution
New directory entry type Link – another name (pointer) to an existing file Resolve the link – follow pointer to locate the file
53
General Graph Directory
54
File System Mounting
A file system must be mounted before it can be accessed
A unmounted file system is mounted at a mount point
55
Access Lists and GroupsMode of access: read, write, execute
Three classes of usersRWX
a) owner access 7 1 1 1RWX
b) group access 6 1 1 0RWX
c) public access 1 0 0 1
Ask manager to create a group (unique name), say G, and add some users to the group.
For a particular file (say game) or subdirectory, define an appropriate access.
owner group public
chmod 761 game
Attach a group to a file chgrp G game
56
Quotas are kept track of on a per-user basis in a quota table.
Disk Quotas