Top Banner
1 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks
47

Outline

Mar 15, 2016

Download

Documents

tanner-humphrey

Outline. Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks. Types of Disks. Magnetic disks Hard disks and floppy disks Reads/writes are equally fast Ideal secondary memory Highly reliable storage Optical disks CD-ROM, CD-R: 600MB DVD: 4.7-17GB. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Outline

1

Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks

Page 2: Outline

2

Types of Disks Magnetic disks

Hard disks and floppy disks Reads/writes are equally fast Ideal secondary memory Highly reliable storage

Optical disks CD-ROM, CD-R: 600MB DVD: 4.7-17GB

Page 3: Outline

Structure of Magnetic Disks

Direction of arm motion

Read/write head (1 per surface)

Surface 0

Surface 1

Track

Sector

Cylinder

1. Cylinders tracks sectors2. Seek time and rotational

delay

Page 4: Outline

4

Cost of Read / Write A Disk Block Seek time

The time to move the arm to the proper cylinder Dominate the other two times for most disks E.g., 0.8 msec for adjacent cylinders

Rotational delay The time for the proper sector to rotate under

the head E.g, 0.03 msec for adjacent sectors

Actual data transfer time E.g., 17 sec for one sector

Page 5: Outline

5

Specifications of Disks Geometry

Physical geometry: more sectors in outer cylinders

To OS: same number of sectors for all cylinders: x cylinders, y heads, and z sectors.

Logical block addressing Disk sectors are numbered consecutively

from 0 to some maximum value

Page 6: Outline

6

Disk Formatting

Preamble

Data ECCA disk sector

• Preamble: recognize the start of the sector. It also contains the cylinder and sector numbers.

• Data: most disks use 512-byte sectors• ECC: can be used to recover from read

errors• Gap between sectors

Gap

Page 7: Outline

7

Cylinder Skew The position of sector 0 on each track is

offset from the previous track. This offset is called cylinder skew.

Allow the disk to read multiple tracks in one continuous operation without losing data

01

23

0

1

2

30

12

3

3

0

1

2

Direction of disk

rotation

Direction of disk

rotation

No skew 1-sector skew

Page 8: Outline

Sector Interleaving• Consider a controller with one sector buffer.

A request of reading two consecutive sectors. When the controller is busy with transferring one sector of data to memory, the next sector will fly by the head.

• Solution: sector interleaving

1

23

0

45

6 74

15

0

26

3 73

61

0

47

2 5

No interleaving

Single interleaving

Double interleaving

Page 9: Outline

9

Disk Arm Scheduling Algorithm Time required to read/write a disk

block Seek time Rotational delay Actual data transfer time

For most disks, the seek time dominates the other two times.

How to reduce the mean seek time? Assume we know the cylinder numbers

of all the pending requests.

Page 10: Outline

10

Optimize Seek Time Fist-come, first-served:

Accept requests one at a time and carry them out in that order

Little can be done Shortest seek first

Handle the closest request next The arm will tend to oscillate between two

cylinders Starvation: with a heavily loaded disk,

requests for cylinders at either extreme get poor service

Page 11: Outline

11

Elevator Algorithm Keep moving the arm in the same

direction until there are no more outstanding requests in that direction, then switch the direction. Upper bound: twice of the number of

cylinders

Page 12: Outline

An Example

1 5 0 7 2 3 6 4Request orderCylinder Number

1 6 9 13

19

Initial position

8 16

18

FCFS: cylinder 811316196189, total 59 motionsSSF: cylinder 896113161819, total 27 motionsEA: cylinder 891316181961, total 29 motionsAssume the direction is initially UP.

Page 13: Outline

13

Stable Storage Model No disk works all the time with no

errors Achievable: either correctly writes

the data or does nothing, leaving the existing data intact.

Possible errors (model assumptions): Incorrect write: detected by ECC Correctly written can go bad. However,

ignore the chance that two independent drives have the same sector going bad

Page 14: Outline

14

Model Hardware: a pair of identical disks

Corresponding blocks works together to form one error-free block

At any time, for any pair of blocks, at least one is in good condition.

Target: If no error, the corresponding blocks on

both drives are the same If error occurs, at least one block can

provide the correct data (either new or old)

Page 15: Outline

15

Model: Stable Writes/Reads Stable writes

Write the block in drive 1read and verify Keep writing until it successes

Write the block in drive 2read and verify Stable reads

Read the block from drive 1. If incorrect (detected by examining ECC), the corresponding block in drive 2 must contain the correct data. Why?

Stable writes leave two good copies Both copies go bad: impossible (assumption 2)

Page 16: Outline

16

Model: Crash Recovery Compare corresponding blocks

Both good: nothing is done One is bad: overwrite the bad copy Both good but different: block 1

overwrites block2. Why?

Old Old

Disk1 2

Crash

Bad

Old

Disk1 2

Crash

New Old

Disk1 2

Crash

New

Bad

Disk1 2

Crash

New New

Disk1 2

Crash

Page 17: Outline

17

Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks

Page 18: Outline

18

Clocks Essential for multi-programming system

Maintain the time of day Prevent processes from monopolizing the CPU

Hardware components: Crystal oscillator: generate high frequency

periodic signal, typically several hundred MHz Counter: value is decreased by 1 when a signal

is generated. It causes a CPU interrupt when it gets to zero.

Holding register: programmable. Used to control the frequency of interrupt.

Page 19: Outline

19

Operation Modes One-shot mode

Copy the value of the holding register into the counter

Decrease the counter at each pulse (signal) Cause an interrupt if it gets zero Stop

Square-wave mode After causing the interrupt, the holding

register is automatically copied into the counter, and the whole process is repeated again.

Page 20: Outline

20

Summary Hardware Principle

Device controller: between devices and OS

Memory mapped I/O Vs. I/O port number DMA Vs. Interrupt

Software Principle Programmed I/O: waste CPU time Interrupts: overheads DMA: DMA controller may not drive the

device at full speed

Page 21: Outline

21

Summary (Cont.) Four layers of I/O software

Interrupt handlers: context switch, wake up driver when I/O completed

Device drivers: set up device registers, issue commands, check status and errors

Device-independent software: naming, protection, buffering, allocating

User-space software: make I/O call, format I/O, spooling

Page 22: Outline

22

Summary (Cont.) Disks

Structure: cylindertracksector Optimize seek time: elevator

algorithm Stable storage

Clocks One-shot and square-wave modes

Page 23: Outline

CMPT 300 Operating System I

Chapter 6 File Systems

Page 24: Outline

24

Outline Files Directories File system implementation

Page 25: Outline

25

Store Information in Memory? How to store a very large amount of

information? All account info in a bank >> main memory size

How to survive the termination of processes? Store your program when the PC is turned off

How to share information among processes Share airline reservation info among multiple

processes Share information around the world?

Page 26: Outline

26

Files: Long-term Storages Files: info on disk/other external media

Persistent, huge capacity, shared by multiple processes

File system: the part of OS dealing with files Structure, name, access, protection, …

User interface of file systems How do files appear to users? Naming rules and protection File operations

Page 27: Outline

27

File Naming Strings as file names

Letters, digits Special characters are also permitted in some system

File name length, usually less than 255 Case sensitive? Processes access files using file names

File name extensions: file_stem.extension Indicates the type of a file

E.g., code.c, code.o, code.c.Z Register extensions with programs

Specify a program to open files with a specific extension Convention & Enforcement

Page 28: Outline

28

File Structure An unstructured sequence of bytes

Most widely used, e.g., UNIX and Windows User programs impose meaning of files

A sequence of fixed-length records Records have internal structure Read/write in records Not used in any current general-purpose system

A tree of records Search records by keys Used on some large mainframe computers

Page 29: Outline

29

Examples of File Structures

Byte sequence

Name: JackSINAddressAccount #Name: CaroleSINAddressAccount #Name: NicolaSINAddressAccount #Name: AndrewSINAddressAccount #

Record sequence

Tree

Ant

Fox Pig

Cat Cow Do

gGoat Lion Owl

Hen Ibis Lamb

1 byte1 record

Page 30: Outline

30

File Types Regular files – store user’s information

ASCII files (text file): lines of text Can be displayed and printed as is. E.g., source code file

Binary files: binary streams Internal structure know to programs Object file, executable code. Word file?

Directories – maintained by system Maintaining the structure of the file system

UNIX special files: modeling I/O devices Character special files: serial I/O devices Block special files: disks/block devices

Page 31: Outline

31

File Access Sequential access

Read all the bytes in order from the beginning Rewind if read again

Random access files Read the bytes/records by specifying positions Applications: database, etc. All the files are random access nowadays

How to specify the starting point for reading Use seek operation to set the current position

Roll forward/backward for n bytes

Page 32: Outline

32

File Attributes Attribute Meaning

Protection Who can access the file and in what way

Password Password needed to access the fileCreator ID of the person who created the fileOwner Current ownerRead-only flag Read/write or read onlyHidden flag Normal file or the file does not display in

listingsSystem flag Normal file or system fileArchive flag The file has been backed up or notRandom access flag

Sequential access only or random access

ASCII/binary flag ASCII file or binary fileTemporary flag Normal file or file will be deleted on

process exitLock flags Unlocked or lockedRecord length Number of bytes in a recordKey position Offset of the key within each recordKey length Number of bytes in the key fieldCreation time Data and time the file was createdTime of last access

Date and time the file was last accessed

Time of last change

Date and time the file was last changed

Current size Number of bytes in the fileMaximum size Number of bytes the file may grow to

File protection and access

Flags control/enable some specific property

Used in file with records having a key

Time stamps

Size

Page 33: Outline

33

File Operations Store and retrieve information System calls relating to files

Open: a process must open a file first before using it

Open mode: read, write, append, modify, etc Close it after you use it

Read: read data starting from the current position Write data

Seek: specify where to take the data Other calls

Delete, append, get attributes, set attributes, rename How to copy a file using these system calls?

Page 34: Outline

34

Outline Files Directories File system implementation

Page 35: Outline

35

Organization: Single-level / Two-level

Single-level: one directory for all the files Not good for huge amount of files Not good for multi-user system

Two-level: userdirectory How to access a file? A large number of files from one user,

inconvenientroot

User A:File mymails

User B:File mymails

root

User A User B

File mymails File mymails

Page 36: Outline

36

Hierarchical Directory Systems A general hierarchy: a tree of

directoriesroot

directory

file

directory directory

directory directory

directory

file file

file

file

file

file

User directory

Page 37: Outline

37

Path Names Mechanism to locate files Absolute path name

Path starting from the root directory E.g., /usr/fran/mailbox. ‘/’ is path separator

Relative path name Relative to the current working directory

E.g., if working directory is /usr/fran, then /usr/fran/mailbox = mailbox

Each process has its own working directory Current directory “.” and parent directory “..”

E.g., ../cindy/mailbox, ./mailbox

Page 38: Outline

38

Directory Operations (UNIX) Create: a directory is created

Empty except ‘.’ and “..” entries Delete, rename a directory

Link (hard link) Allow a file to appear in more than one directory One copy of a file, multiple directory entries

Unlink A directory entry is removed Link count > 0

Yes: remove the file (free the i-node and data blocks) No: keep the file

Page 39: Outline

39

Outline Files Directories File system implementation

Page 40: Outline

40

File System Layout Disk is divided up into several partitions

Each partition has one file system MBR – master boot record

boot the computer & contain the partition table

Partition table Starting & ending addresses of each partition One partition is marked as active

Within each partition Boot block – first block, a program loads the

OS Superblock – key parameters about the file

sys.MBR Partition 1 Partition 2

Partition 3

Partition 4

Boot block

Super block

Free space mgmt

I-nodes

Root dir

Files and directories

Page 41: Outline

41

Implementing Files Key issue: how to keep track of which

disk sectors go with which file? E.g., block size= 512B, file size=2014B, so

where are these 2014/514=4 blocks on disk?

Many methods Contiguous allocation Linked list allocation I-nodes Each one has its own pros and cons

Page 42: Outline

42

Contiguous Allocation Store each file as a contiguous run of

disk sectors Advantages

Simple to implement Each file has two numbers, starting address &

length Read performance is excellent

Drawback Holes. Relocate if file grows.

Free blocks

Page 43: Outline

43

Linked List Allocation Keep all the blocks as a linked list

Only the address of the first block is stored

Every sector can be used, no holes Random access is extremely slow The amount of data storage in a sector

is no longer a power of two Read a block of data requires accessing

two sectors File block 0

File block 1

File block 2

0File block 3

Physical sector 4 7 2 10

Page 44: Outline

44

File Allocation Table (FAT) Move the pointer from each block to a

table in memory FAT– shared by all the files Indexed by physical sector number Each entry contains the number of next block E.g., 47210

Random access is much easier FAT is in main memory

FAT must be held in main memory 20 GB disk, 1 KB/block, 4 bytes/entry 80MB FAT

Size of FAT is linear to size of disk

012 1034 7567 289

10 -11112131415

First block

Page 45: Outline

45

Index Nodes (I-nodes) An i-node lists the attributes and

disk addresses of the file’s blocks Only when a file is open, its i-nodes

should be loaded into memory Much smaller than FAT Irrelevant to size of diskFile attributes

Address of disk block 0

Address of disk block 1

Address of disk block 2

Address of disk block 3

Address of block of pointers

Disk block containing

additional disk addresses

Page 46: Outline

46

Implementing Directories Directory system: map the ASCII file

name onto the info needed to locate the data Directory entry

Where are the attributes stored? In the directory entry (MS-DOS/Windows) In the i-nodes (UNIX)Games Attribute

sMail Attribute

sNews Attribute

sWork Attribute

s

DOS/Windows

GamesMailNewsWork

File attributesAddress of disk

block 0Address of disk

block 1…

i-node

UNIX

Page 47: Outline

47

Locate A File: /usr/ast/mbox

1 .1 ..4 bin7 dev14 lib9 etc6 usr8 tm

p

Attr.132…..

6 .1 ..19

dick

30

erik

51

jim

26

ast

45

bal

Attr.406…..

26 .6 ..64 grants92 books60 mbox81 simix17 src

root I-node 6 is for /usr

Block 132 is /usr dir.

I-node 26 is for /usr/ast

Block 406 is /usr/ast dir.

Looking up usr yields i-node 6

/usr is in block 132

/usr/ast is i-node 26

/usr/ast is in block 406 /usr/ast/mbox

is i-node 60