54
1 CENG334 Introduction 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 Filesystems Topics: Disks

1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

Embed Size (px)

Citation preview

Page 1: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 2: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 3: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 4: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 5: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

5

Hard Disk Evolution

Adapted from Matt Welsh’s (Harvard University) slides.

Page 6: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 7: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 8: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 9: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 10: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 11: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 12: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 13: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 14: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

14

SCAN example

Current track

Direction

Adapted from Matt Welsh’s (Harvard University) slides.

Page 15: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

15

SCAN example

Current track

Direction

Adapted from Matt Welsh’s (Harvard University) slides.

Page 16: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

16

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 17: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

17

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 18: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

18

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 19: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

19

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 20: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

20

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 21: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

21

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 22: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

22

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 23: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

23

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 24: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

24

SCAN example

Direction

Current track

Adapted from Matt Welsh’s (Harvard University) slides.

Page 25: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 26: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 27: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 28: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

28

Relative Interconnect Speeds(from macspeedzone.com)

USB 3.0 standard established in 2007 supports speeds upto 5GBps

Page 29: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

29

CENG334Introduction to Operating Systems

Erol Sahin

Dept of Computer Eng.Middle East Technical University

Ankara, TURKEY

Filesystems and their interfaceTopics:

Page 30: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 31: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 32: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 33: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 34: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 35: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 36: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 37: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 38: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 39: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 40: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

41

Example Program Using File System Calls (1)

Figure 4-5. A simple program to copy a file.

Page 41: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

42

Example Program Using File System Calls (2)

Figure 4-5. A simple program to copy a file.

Page 42: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 43: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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, …)

Page 44: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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.

Page 45: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 46: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

48

Tree-Structured Directories

A directory is simply another file that needs to be treated in a special way.

Page 47: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

49

Tree-Structured Directories (Cont)

Efficient searchingdirectory entry sizes would be manageable

Grouping Capability

Current directory (working directory) cd /spell/mail/prog type list

Page 48: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

mail

prog copy prt exp count

Deleting “mail” deleting the entire subtree rooted by “mail”

Page 49: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

51

Acyclic-Graph DirectoriesHave shared subdirectories and files

Page 50: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 51: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

53

General Graph Directory

Page 52: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 53: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

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

Page 54: 1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:

56

Quotas are kept track of on a per-user basis in a quota table.

Disk Quotas