• 沒有找到結果。

Review 04

N/A
N/A
Protected

Academic year: 2021

Share "Review 04"

Copied!
44
0
0

加載中.... (立即查看全文)

全文

(1)

Operating Systems (Fall/Winter 2019)

Review 04

Yajin Zhou (http://yajin.org) Zhejiang University

Acknowledgement: Some slides are based on Zhi Wang (FSU)’s slides.

(2)

11: storage

(3)

Disk Scheduling

OS is responsible for using hardware efficiently

for the disk drives: a fast access time and high disk bandwidth

access time: seek time (roughly linear to seek distance) + rotational latency

disk bandwidth is the speed of data transfer, data /time

data: total number of bytes transferred

time: between the first request and completion of the

last transfer

(4)

Disk Scheduling

Disk scheduling chooses which pending disk request to service next

concurrent sources of disk I/O requests include OS, system/user processes

idle disk can immediately work on a request, otherwise os queues requests

each request provide I/O mode, disk & memory address, and # of sectors

OS maintains a queue of requests, per disk or device

optimization algorithms only make sense when a queue exists

In the past, operating system responsible for queue management, disk drive head scheduling

Now, built into the storage devices, controllers - firmware

Just provide LBAs, handle sorting of requests

Some of the algorithms they use described next

(5)

Disk Scheduling

Disk scheduling usually tries to minimize seek time

rotational latency is difficult for OS to calculate

There are many disk scheduling algorithms

FCFS

SSTF

SCAN

C-SCAN

C-LOOK

We use a request queue of “98, 183, 37, 122, 14, 124, 65, 67” ([0, 199]), and initial head position 53 as the example

(6)

FCFS

First-come first-served, simplest scheduling algorithm

Total head movements of 640 cylinders

(7)

SSTF

SSTF: shortest seek time first

selects the request with minimum seek time from the current head position

SSTF scheduling is a form of SJF scheduling, starvation may exist

unlike SJF, SSTF may not be optimal

Total head movement of 236 cylinders

(8)

SCAN

SCAN algorithm sometimes is called the elevator algorithm

disk arm starts at one end of the disk, and moves toward the other end

service requests during the movement until it gets to the other end

then, the head movement is reversed and servicing continues.

(9)

C-SCAN

Circular-SCAN is designed to provides a more uniform wait time

head moves from one end to the other, servicing requests while going

when the head reaches the end, it immediately returns to the beginning

without servicing any requests on the return trip

it essentially treats the cylinders as a circular list

(10)

LOOK/C-LOOK

SCAN and C-SCAN moves head end to end, even no I/O in between

in implementation, head only goes as far as last request in each direction

LOOK is a version of SCAN, C-LOOK is a version of C-SCAN

(11)

RAID

RAID – redundant array of inexpensive disks

multiple disk drives provides reliability via redundancy

Increases the mean time to failure

(12)

12: I/O Systems

(13)

A Typical PC Bus Structure

(14)

Application I/O Interface

I/O system calls encapsulate device behaviors in generic classes

in Linux, devices can be accessed as files; low-level access with ioctl

Device-driver layer hides differences among I/O controllers from kernel

each OS has its own I/O subsystem and device driver frameworks

new devices talking already-implemented protocols need

no extra work

(15)

Direct Memory Access

DMA transfer data directly between I/O device and memory

OS only need to issue commands, data transfers bypass the CPU

no programmed I/O (one byte at a time), data transferred in large blocks

it requires DMA controller in the device or system

OS issues commands to the DMA controller

a command includes: operation, memory address for data, count of bytes…

usually it is the pointer of the command written into the command register

when done, device interrupts CPU to signal completion

(16)

13: File System Interface

(17)

File Concept

File is a contiguous logical address space for storing information

database, audio, video, web pages…

There are different types of file:

data: numeric, character, binary

program

special one: proc file system - use file-system interface

to retrieve system information

(18)

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

Many variations, including extended file attributes such as file checksum

(19)

Access Methods

Sequential access

a group of elements is access in a predetermined order

for some media types, the only access mode (e.g., tape)

Direct access

access an element at an arbitrary position in a sequence in (roughly) equal time, independent of sequence size

it is possible to emulate random access in a tape, but access time varies

sometime called random access

(20)

Directory Structure

Directory is a collection of nodes containing information about all files

F 1! F 2!

F 3! F 4!

F n!

Directory!

Files!

both the directory structure and the files reside on disk

(21)

Single-Level Directory

A single directory for all users

naming problems and grouping problems

Two users want to have same file names

Hard to group files

(22)

Two-Level Directory

Separate directory for each user

different user can have the same name for different files

Each user has his own user file directory (UFD), it is in the master file directory (MFD)

efficient to search, cannot group files

How to share files between different users, and how to share the system files?

(23)

Tree-Structured Directories

Files organized into trees

efficient in searching, can group files, convenient naming -

solving file name conflicts for different users!

(24)

Tree-Structured Directories

File can be accessed using absolute or relative path name

absolute path name: /home/alice/..

relative path is relative to the current directory (pwd)

creating a new file, delete a file, or create a sub-directory

e.g., if current directory is /mail, a mkdir count will create /mail/count

echo $(pwd)

Quick quiz: what ’s the functionality of the set shell command?

->to set or get environment variables

(25)

Protection

File owner/creator should be able to control

what can be done

by whom

Types of access

read, write, append

execute

delete

list

(26)

Symbolic links

What happens if one file is deleted for the symbolic link?

(27)

14: File System Implementation

(28)

File-System Structure

File is a logical storage unit for a collection of related information

There are many file systems; OS may support several simultaneously

Linux has Ext2/3/4, Reiser FS/4, Btrfs…

Windows has FAT, FAT32, NTFS…

new ones still arriving – ZFS, GoogleFS, Oracle ASM, FUSE

File system resides on secondary storage (disks)

disk driver provides interfaces to read/write disk blocks

fs provides user/program interface to storage, mapping logical to physical

file control block – storage structure consisting of information about a file, created when a file is created!

File system is usually implemented and organized into layers

(29)

File-System Implementation

partition == volume == file system storage space

File-system needs to maintain on-disk and in-memory structures

on-disk for data storage, in-memory for data access

On-disk structure has several control blocks

boot control block contains info to boot OS from that volume - per volume

only needed if volume contains OS image, usually first block of volume

volume control block (e.g., superblock) contains volume details - per volume

total # of blocks, # of free blocks, block size, free block pointers, free FCB count, free FCB pointers

directory structure organizes the directories and files - per file system

A list of (file names and associated inode numbers)

per-file file control block contains many details about the file - per file

permissions, size, dates, data blocks or pointer to data blocks

(30)

In-Memory File System Structures

In-memory structures reflects and extends on-disk structures

Mount table storing file system mounts, mount points, file system types

In-memory directory-structure cache: holds the directory information about recently accessed directories

system-wide open-file table contains a copy of the FCB of each file and other info.

per-process open-file table contains pointers to appropriate entries in system-wide open-file table as well as other info

I/O Memory Buffers: hold file-system blocks while they are being read from or written to disk

(31)

File Creation

application process requests the creation of a new file

logical file system allocates a new FCB, i.e., inode structure in linux

appropriate directory is updated with the new file name and FCB, i.e., inode

(32)

Operations - open()

search System-Wide Open-File Table to see if file is currently in use

if it is, create a Per-Process Open-File table entry pointing to the existing System-Wide Open-File Table

if it is not, search the directory for the file name; once found, place the FCB in the System-Wide Open-File Table

make an entry, i.e., Unix file descriptor, Windows file handle in the Per-Process Open-File Table, with pointers to the entry in the System-Wide Open-File Table and other fields which include a pointer to the current location in the file and the access mode in which the file is open

(33)

Operations - open()

increment the open cont in the System-Wide Open-File Table

returns a pointer to the appropriate entry in the Per-Process Open- File Table

all subsequent operations are performed with this pointer

process closes file -> Per-Process Open-File Table entry is removed;

open count decremented

all processes close file -> copy in-memory directory information to disk and System-Wide Open-File Table is removed from memory

(34)
(35)
(36)

Disk Block Allocation

Files need to be allocated with disk blocks to store data

different allocation strategies have different complexity and performance

Many allocation strategies:

contiguous

linked

indexed

(37)

Contiguous Allocation

Contiguous allocation: each file occupies set of contiguous blocks

best performance in most cases

simple to implement: only starting location and length are required

Contiguous allocation is not flexible

how to increase/decrease file size?

need to know file size at the file creation?

external fragmentation

how to compact files offline or online to reduce external fragmentation

need for compaction off-line (downtime) or on-line

appropriate for sequential disks like tape

Some file systems use extent-based contiguous allocation

extent is a set of contiguous blocks

a file consists of extents, extents are not necessarily adjacent to each other

(38)

Contiguous Allocation

(39)

Linked Allocation

Linked allocation: each file is a linked list of disk blocks

each block contains pointer to next block, file ends at nil pointer

blocks may be scattered anywhere on the disk (no external fragmentation, no compaction)

Disadvantages

locating a file block can take many I/Os and disk seeks

Pointer size: 4 of 512 bytes are used for pointer - 0.78%

space is wasted

Reliability: what about the pointer has corrupted!

(40)

Linked Allocation

(41)

Indexed Allocation

Indexed allocation: each file has its own index blocks of pointers to its data blocks

index table provides random access to file data blocks

no external fragmentation, but overhead of index blocks

allows holes in the file

Index block needs space - waste for small files

index table

What about two levels?

(42)

Indexed Allocation

ext2: combined scheme

First 15 pointers are in inode

Direct block: first 12 pointers

Indirect block: next 3 pointers

What’s the biggest file for ext2 (block size 4k)?

How many

blocks: 12 + (4K/

4) + (4K/4)^2 + (4K/4)^3

(43)

Free-Space Management

File system maintains free-space list to track available blocks/clusters

The space of deleted files should be reclaimed

Many allocation methods:

bit vector or bit map

linked free space

(44)

Bitmap Free-Space Management

Use one bit for each block, track its allocation status

relatively easy to find contiguous blocks

bit map requires extra space

example: block size = 4KB = 212 bytes disk size = 240 bytes (1 terabyte)

n = 240/212 = 228 bits (or 256 MB)

if clusters of 4 blocks -> 64MB of memory

!

0! 1! 2! n-1!

bit[i] =!

!"#

!

1 ! block[i] free!

0 ! block[i] occupied!

參考文獻

相關文件

– If your virus can infect all .COM files under the same folder, and when you open the infected file, it infects all other files, you get a nice score. • If your virus can do all

– Each time a file is opened, the content of the directory entry of the file is moved into the table.. • File Handle (file descriptor, file control block): an index into the table

„ Kernel keeps state info for I/O components, including open file tables, network connections, character device state. „ Many, many complex data structures to track buffers, memory

– File and index layers organize records on files, and manage the indexing data

Place the code elements in order so that the resulting Java source file will compile correctly, resulting in a class called “com.sun.cert.AddressBook”。..

[r]

(A) File Transfer Protocol, FTP (B) Electronic Mail, E-Mail (C) World Wide Web, WWW (D) Word Wide Web,

存放檔案的 inode 資訊, inode 一旦滿了也一樣會 無法儲存新檔案, inode 會告知檔案所使用的 data block 位置。. Q :如何知道那些 inode 和