Outline • Announcements • Final Review

advertisement
Outline
• Announcements
• Final Review
Announcements – cont.
• Regarding the final exam
– The maximum number of points is 165
• 150 corresponds to the full credit
• There is 10 % extra credit
– You may need a calculator to perform some
calculations
– You are allowed to have a double-sided sheet no
larger than the letter size
– You have two hours to work on the final
5/29/2016
COP4610
2
Announcements
• Policy regarding checking the final exam
score
– You can check your final exam score as well as
your final grade after 1:00pm on Friday, Dec. 12
– You cannot pick it up, however
• I will have office hours this Sunday
– From 10:00 am to 5:30 pm
– I may not be able to read emails from Dec. 8 to
Dec. 11
5/29/2016
COP4610
3
System Overview
• A computer system consists of hardware and
software that are combined to provide a tool
to solve specific problems
– Hardware includes CPU, memory, disks, printers,
screen, keyboard, mouse ...
– Software includes
• System software
– A general environment to create specific applications
• Application software
– A tool to solve a specific problem
5/29/2016
COP4610
4
System Overview
5/29/2016
COP4610
5
What is an Operating System?
• The operating system is the part of the
system software that manages the use of the
hardware used by other system software and
all application software
– It is the system program that acts between the
hardware and the user programs
5/29/2016
COP4610
6
What is an Operating System? - continued
• It provides services to user programs
– Through system calls / message passing
• File system services
• Memory services
• I/O services
• It hides hardware from user programs
– When your program shows a message on the monitor, it
does not need to know the details
– When your program generates a new file, it does not need
to where the free space is on your hard drive
5/29/2016
COP4610
7
Operating System Functions
• Resource manager
– manage hardware and software resources
– Resource abstraction and sharing
• A nicer environment
– implement a virtual machine for processes to run in
• A program in execution is called a process
– a nicer environment than the bare hardware
5/29/2016
COP4610
8
Resource Management Functions
• Transform physical resources to logical
resources
– Resource abstraction
• Make the hardware resources easier to use
• Multiplex one physical resource to several
logical resources
– Create multiple, logical copies of resources
• Schedule physical and logical resources
– Decide who gets to use the resources
5/29/2016
COP4610
9
System Call Interface
• System call interface
– Operating system provides a set of operations
called system calls
– A programming interface
5/29/2016
COP4610
10
Trap Instruction
5/29/2016
COP4610
11
von Neumann Architecture
5/29/2016
COP4610
12
Instruction Execution
• Instruction fetch (IF)
MAR  PC; IR  M[MAR]
• Instruction Decode (ID)
A  Rs1; B  Rs2; PC  PC + 4
• Execution (EXE)
– Depends on the instruction
• Memory Access (MEM)
– Depends on the instruction
• Write-back (WB)
5/29/2016
COP4610
13
Device Management Organization
Application
Process
System Interface
File
Manager
Device-Independent
Device-Dependent
Hardware Interface
Command
Status
Data
Device Controller
5/29/2016
COP4610
14
Device Controllers
• A hardware component to control the detailed
operations of a device
– Interface between controllers and devices
– Interface between software and the controller
• Through controller’s registers
5/29/2016
COP4610
15
Device Controllers – cont.
...
busy
Command
done
Error code
Status
...
busy done
0
0 idle
0
1 finished
1
0 working
1
1 (undefined)
Data 0
Data 1
Logic
Data n-1
5/29/2016
COP4610
16
Device Drivers
• The part of OS that implements device
management is called collectively as device
drivers
– Device drivers can be complex
– However, the drivers for different devices
implement a similar interface so that a higherlevel component has a uniform interface for
different devices
5/29/2016
COP4610
17
I/O Strategies
• Direct I/O or DMA for data transferring
• Polling or interrupt-driven
• I/O strategies
– Direct I/O with polling
– DMA I/O with polling
• Not supported in general
– Direct I/O with interrupts
– DMA I/O with interrupts
5/29/2016
COP4610
18
Direct-Memory Access
5/29/2016
COP4610
19
Direct I/O with Polling
read(device, …);
1
System Interface
Data
read function
5
write function
2
3
4
Hardware Interface
Command
Status
Data
Device Controller
5/29/2016
COP4610
20
Interrupts
• An interrupt is an immediate transfer of control caused
by an event in the system to handle real-time events
and running-time errors
–
–
–
–
Interrupt can be either software or hardware
I/O device request (Hardware)
System call (software)
Signal (software)
• Page fault (software)
• Arithmetic overflow
• Memory-protection violation
– Power failure
5/29/2016
COP4610
21
Interrupt-Driven I/O
read(device, …);
1
9
8b
Data
System Interface
Device Status Table
read driver
2
4
7
Device
Handler
write driver
6
3
Interrupt
Handler
8a
5
Hardware Interface
Command
Status
Data
Device Controller
5/29/2016
COP4610
22
Interrupt-Driven Versus Polling
• In general, an interrupt-driven system will
have a higher CPU utilization than a pollingbased system
– The CPU time on polling by one process may be
utilized by another process to perform
computation
5/29/2016
COP4610
23
Process Manager
• Process manager consists of
– Basic algorithms and data structures to
implement the process and resource abstractions
– Managing resources used by processes/threads
– Tools to create/destroy/manipulate processes and
threads
– Scheduling
– Process synchronization
– A deadlock strategy
– Protection strategy
5/29/2016
COP4610
24
Implementing the Process Abstraction
Pi CPU
Pj CPU
Pi Executable
Memory
Pj Executable
Memory
Pk CPU
…
Pk Executable
Memory
OS Address
Space
Pi Address
Space
CPU
ALU
Pk Address
Space
…
Control
Unit
Pj Address
Space
5/29/2016
COP4610
Machine Executable Memory
OS interface
25
Context Switching
Old Thread
Descriptor
CPU
New Thread Descriptor
5/29/2016
COP4610
26
Modern Processes and Threads
5/29/2016
COP4610
27
Processes
• A process is a sequential program in
execution
–
–
–
–
The object program to be executed
The data on which the program will execute
Resources required by the program
The threads in the process
• A host process environment
• The status of each thread’s execution
– Thread-specific data, such as a stack, a PC, and set of
register values
5/29/2016
COP4610
28
The Address Space
Address
Space
Address
Binding
Executable
Memory
Process
Files
Other objects
5/29/2016
COP4610
29
Process Descriptors
• OS creates/manages process abstraction
• Descriptor is data structure for each process
–
–
–
–
–
5/29/2016
Type & location of resources it holds
List of resources it needs
List of threads
List of child processes
Security keys
COP4610
30
Threads
• A thread shares with its peer threads its:
–
–
–
–
code section
data section
operating-system resources
collectively known as a task
• A traditional or heavyweight process is equal
to a task with one thread
5/29/2016
COP4610
31
Threads – cont.
5/29/2016
COP4610
32
Diagram of Process State
5/29/2016
COP4610
33
Process Scheduler Organization
5/29/2016
COP4610
34
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible
• Throughput – # of processes that complete their
execution per time unit
• Turnaround time – amount of time to execute a
particular process
• Response time – amount of time it takes from when
a request was submitted until the first response is
produced, not output (for time-sharing
environment)
5/29/2016
COP4610
35
First-Come-First-Served
• Gantt chart of FCFS Scheduler
5/29/2016
COP4610
36
Shortest-Job-Next Scheduling
• Associate with each process the length of its
next CPU burst.
– Use these lengths to schedule the process with
the shortest time.
• SJN is optimal
– gives minimum average waiting time /
turnaround time for a given set of processes.
5/29/2016
COP4610
37
Round Robin (RR)
• Each process gets a small unit of CPU time
(time quantum), usually 10-100 milliseconds.
After this time has elapsed, the process is
preempted and added to the end of the ready
queue.
• If there are n processes in the ready queue
and the time quantum is q, then each process
gets 1/n of the CPU time in chunks of at most
q time units at once. No process waits more
than (n-1)q time units.
5/29/2016
COP4610
38
Multilevel Queue
• Ready queue is partitioned into separate
queues
– foreground (interactive)
– background (batch)
• Each queue has its own scheduling algorithm
– foreground – RR
– background – FCFS
5/29/2016
COP4610
39
Multilevel Feedback Queue
• A process can move between the various queues
• Multilevel-feedback-queue scheduler defined by the
following parameters:
–
–
–
–
–
number of queues
scheduling algorithms for each queue
method used to determine when to upgrade a process
method used to determine when to demote a process
method used to determine which queue a process will
enter when that process needs service
5/29/2016
COP4610
40
Interacting Processes
• Independent process
– Cannot affect or be affected by the other
processes in the system
– Does not share any data with other processes
• Interacting process
– Can affect or be affected by the other processes
– Shares data with other processes
– We focus on interacting processes through
physically or logically shared memory
5/29/2016
COP4610
41
Race Condition
• Race condition
– When several processes access and manipulate
the same data concurrently, there is a race among
the processes
– The outcome of the execution depends on the
particular order in which the access takes place
– This is called a race condition
5/29/2016
COP4610
42
The Critical-Section Problem
• n processes all competing to use some shared
data
• Each process has a code segment, called
critical section, in which the shared data is
accessed.
• Problem – ensure that when one process is
executing in its critical section, no other
process is allowed to execute in its critical
section, called mutual exclusion
5/29/2016
COP4610
43
The Critical-Section Problem – cont.
• Structure of process Pi
repeat
entry section
critical section
exit section
reminder section
until false;
5/29/2016
COP4610
44
Requirements for Critical-Section Solutions
• Mutual Exclusion.
– If process Pi is executing in its critical section, then no
other processes can be executing in their critical sections.
• Progress
– If no process is executing in its critical section and there
exist some processes that wish to enter their critical
section, then the selection of the processes that will enter
the critical section next cannot be postponed indefinitely.
• Bounded Waiting
– A bound must exist on the number of times that other
processes are allowed to enter their critical sections after
a process has made a request to enter its critical section
and before that request is granted.
5/29/2016
COP4610
45
Synchronization Hardware
• Test and modify the content of a word atomically
(indivisibly)
– The procedure cannot be interrupted until it has completed the
routine
– Implemented as a test-and-set instruction
boolean Test-and-Set (boolean target)
{ boolean tmp
tmp = target;
target = true;
return tmp;
}
5/29/2016
COP4610
46
Semaphores
• Semaphore S – non-negative integer variable
– Binary semaphore – can only be either 0 or 1
– Counting semaphore – can be any positive number
• It can only be changed or tested via two
indivisible (atomic) operations
– P(S) or wait(S)
P(S): while S 0 do no-op;
S := S – 1;
– V(S) or signal(S)
P(S): S := S + 1;
5/29/2016
COP4610
47
Example:Mutual Exclusion using Semaphores
• Shared variables
– semaphore mutex;
• Process Pi
repeat
P(mutex);
critical section
P(mutex);
remainder section
until false;
5/29/2016
COP4610
48
Bounded-Buffer using Semaphores – cont.
5/29/2016
COP4610
49
Readers-writers with active readers – cont.
5/29/2016
COP4610
50
Monitors
• High-level synchronization construct that
allows the safe sharing of an abstract data
type among concurrent processes.
class monitor {
variable declarations
semaphore mutex = 1;
public P1 :(…)
{ P(mutex);
........
V(mutex);
};
........
}
5/29/2016
COP4610
51
Monitors – cont.
• To allow a process to wait within the monitor, a condition
variable must be declared, as
condition x, y;
• Condition variable can only be used with the operations wait
and signal.
– The operation
x.wait;
means that the process invoking this operation is suspended until
another process invokes
x.signal;
– The x.signal operation resumes exactly one suspended process. If no
process is suspended, then the signal operation has no effect.
5/29/2016
COP4610
52
Monitors – cont.
5/29/2016
COP4610
53
Inter-Process Communication
• Inter-Process Communication (IPC)
– Allow running processes to communicate with
each other
• IPC – special cases
– Parent and child
• Parent passes arguments to child
• Parent collect returned status from child using wait
– Processes with common ancestors
• pipe
5/29/2016
COP4610
54
Communication through Messages – cont.
• IPC facility provides two operations:
– send(message) – message size fixed or variable
– receive(message)
• If P and Q wish to communicate, they need to
– establish a communication link between them
– exchange messages via send/receive
5/29/2016
COP4610
55
UNIX Signal
• A signal in UNIX is a mechanism by which
the OS can inform a process of the
occurrence of some event
– A signal can be raised by one process using kill
system call, thus causing another process to be
interrupted and to optionally catch the signal
– Signals can also be used among user processes
5/29/2016
COP4610
56
The Deadlock Problem
• A set of blocked processes each holding a
resource and waiting to acquire a resource
held by another process in the set
5/29/2016
COP4610
57
Deadlock Characterization
• Deadlock can arise only if four conditions hold simultaneously
– Mutual exclusion
• only one process at a time can use a resource.
– Hold and wait:
• a process holding at least one resource is waiting to acquire additional
resources held by other processes.
– No preemption
• a resource can be released only voluntarily by the process holding it, after
that process has completed its task.
– Circular wait
• there exists a set {P0, P1, …, P0} of waiting processes such that P0 is
waiting for a resource that is held by P1, P1 is waiting for a resource that is
held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is
waiting for a resource that is held by P0.
5/29/2016
COP4610
58
Resource-Allocation Graph - cont.
• Process
• Resource Type with 4 instances
• Pi requests instance of Rj
• Pi is holding an instance of Rj
Pi
Rj
Pi
Rj
5/29/2016
COP4610
59
Another Example of a Resource Allocation Graph
5/29/2016
COP4610
60
Dealing with Deadlocks
• Three solutions
– Prevention
• place restrictions on resource request to make
deadlock impossible
– Avoidance
• plan ahead to avoid deadlock.
– Recovery
• detect when deadlock occurs and recover from it
5/29/2016
COP4610
61
Deadlock Prevention
• Restrain the ways that request can be made.
• Mutual Exclusion – not required for sharable
resources; must hold for nonsharable resources.
• Hold and Wait – must guarantee that whenever a
process requests a resource, it does not hold any
other resources.
– Require process to request and be allocated all its
resources before it begins execution, or allow process to
request resources only when the process has none.
– Low resource utilization; starvation possible.
5/29/2016
COP4610
62
Deadlock Prevention - cont.
• No Preemption –
– If a process that is holding some resources
requests another resource that cannot be
immediately allocated to it, then all resources
currently being held are released.
– Preempted resources are added to the list of
resources for which the process is waiting.
– Process will be restarted only when it can regain
its old resources, as well as the new ones that it is
requesting.
5/29/2016
COP4610
63
Deadlock Prevention - cont.
• Circular Wait
– Impose a total ordering of all resource types, and require
that each process requests resources in an increasing order
of enumeration
• In other words, assuming Ri < Rj if i < j, we only a process to
acquire a resource Rj if it has acquired all other resources Ri, for i
<j
– Here we assume F(Ri)=i
– Semaphore example
• semaphores A and B, initialized to 1
P0
P1
wait (A); wait(A)
wait (B);
wait(B)
5/29/2016
COP4610
64
Deadlock Avoidance
• Requires that the system has some additional a
priori information available
• Simplest and most useful model requires that each
process declare the maximum number of resources
of each type that it may need
• The deadlock-avoidance algorithm dynamically
examines the resource-allocation state to ensure that
there can never be a circular-wait condition
• Resource-allocation state is defined by the number
of available and allocated resources, and the
maximum demands of the processes
5/29/2016
COP4610
65
Safe State
• When a process requests an available resource, system must
decide if immediate allocation leaves the system in a safe
state.
• System is in safe state if there exists a safe sequence of all
processes.
• Sequence <P1, P2, …, Pn> is safe if for each Pi, the
resources that Pi can still request can be satisfied by
currently available resources + resources held by all the Pj,
with j < i.
– If Pi resource needs are not immediately available, then Pi can wait
until all Pj have finished.
– When Pj is finished, Pi can obtain needed resources, execute, return
allocated resources, and terminate.
– When Pi terminates, Pi+1 can obtain its needed resources, and so on.
5/29/2016
COP4610
66
Basic Facts
• If a system is in safe state  no deadlocks.
• If a system is in unsafe state  possibility of
deadlock.
• Avoidance  ensure that a system will never
enter an unsafe state.
5/29/2016
COP4610
67
Safety Algorithm
1. Let Work and Finish be vectors of length m and n,
respectively. Initialize:
Work := Available
Finish [i] = false for i - 1, 2, 3, …, n.
2. Find an i such that both:
(a) Finish [i] = false
(b) Needi  Work
If no such i exists, go to step 4.
3. Work := Work + Allocationi
Finish[i] := true
go to step 2.
4. If Finish [i] = true for all i, then the system is in a safe state.
5/29/2016
COP4610
68
Resource-Request Algorithm for Process Pi
Requesti = request vector for process Pi. If Requesti [j] = k
then process Pi wants k instances of resource type Rj.
1. If Requesti  Needi go to step 2. Otherwise, raise error condition,
since process has exceeded its maximum claim.
2. If Requesti  Available, go to step 3. Otherwise Pi must wait, since
resources are not available.
3. Pretend to allocate requested resources to Pi by modifying the state
as follows:
•
•
5/29/2016
Available := Available = Requesti;
Allocationi := Allocationi + Requesti;
Needi := Needi – Requesti;;
If safe  the resources are allocated to Pi.
If unsafe  Pi must wait, and the old resource-allocation state is
restored
COP4610
69
Deadlock Detection and Recovery
• Allow system to enter deadlock state
• Detection algorithm
• Recovery scheme
5/29/2016
COP4610
70
Deadlock Detection Algorithm
• Available: A vector of length m indicates the
number of available resources of each type.
• Allocation: An n x m matrix defines the number of
resources of each type currently allocated to each
process.
• Request: An n x m matrix indicates the current
request of each process. If Request [ij] = k, then
process Pi is requesting k more instances of resource
type. Rj.
5/29/2016
COP4610
71
Detection Algorithm
1. Let Work and Finish be vectors of length m and n, respectively Initialize:
(a) Work := Available
(b) For i = 1,2, …, n, if Allocationi  0, then
Finish[i] := false;otherwise, Finish[i] := true.
2. Find an index i such that both:
(a) Finish[i] = false
(b) Requesti  Work
If no such i exists, go to step 4.
3. (a) Work := Work + Allocationi; (b) Finish[i] := true; go to step 2.
4. If Finish[i] = false, for some i, 1  i  n, then the system is in deadlock
state. Moreover, if Finish[i] = false, then Pi is deadlocked.
Algorithm requires an order of m x n2 operations to detect whether
the system is in deadlocked state.
5/29/2016
COP4610
72
Graph Reduction
• Deadlock state if there is no sequence of
transitions unblocking every process
• A RRG represents a state; can analyze the
RRG to determine if there is a sequence
• A graph reduction represents the (optimal)
action of an unblocked process. Can reduce
by pi if
– pi is not blocked
– pi has no request edges, and there are (Rj, pi) in
the RRG
5/29/2016
COP4610
73
Example RRG
p0
p0
A
C
p1
p1
p2
p2
B
p0
p1
5/29/2016
p0
p1
p2
COP4610
p2
74
Memory Management Background
• Program must be brought into memory and
placed within a process for it to be executed
– A program is a file on disk
– CPU reads instructions from main memory and
reads/writes data to main memory
• Determined by the computer architecture
– Address binding of instructions and data to
memory addresses
5/29/2016
COP4610
75
Memory Management
5/29/2016
COP4610
76
Issues in a memory allocation algorithm
• Memory organization
– how to divide the memory into blocks for allocation?
• Static method: divide the memory once before any bytes
are allocated.
• Dynamic method: divide it up as you are allocating the
memory.
• Memory management
– select which piece of memory to allocate to a request
– First-fit, next-fit, best-fit, and worst-fit
5/29/2016
COP4610
77
Fragmentation
• Without mapping, programs require physically
continuous memory
– External fragmentation
• total memory space exists to satisfy a request, but it is
not contiguous.
– Internal fragmentation
• allocated memory may be slightly larger than requested
memory; this size difference is memory internal to a
partition, but not being used.
5/29/2016
COP4610
78
Compacting memory
5/29/2016
COP4610
79
Segmentation Architecture
• Logical address consists of a two tuple:
<segment-number, offset>,
• Segment table – maps two-dimensional
physical addresses; each table entry has:
– base – contains the starting physical address
where the segments reside in memory.
– limit – specifies the length of the segment.
5/29/2016
COP4610
80
Paging
• Physical address space of a process can be noncontiguous;
process is allocated physical memory whenever the latter is
available.
• Divide physical memory into fixed-sized blocks called frames
(size is power of 2).
• Divide logical memory into blocks of same size called pages.
• Keep track of all free frames.
• To run a program of size n pages, need to find n free frames and
load program.
• Internal fragmentation.
5/29/2016
COP4610
81
Address Translation Architecture
5/29/2016
COP4610
82
TLB lookup
5/29/2016
COP4610
83
Memory Protection in Paging
• Memory protection implemented by
associating protection bit with each frame.
• Valid-invalid bit attached to each entry in the
page table:
– “valid” indicates that the associated page is in the
process’ logical address space, and is thus a legal
page.
– “invalid” indicates that the page is not in the
process’ logical address space.
5/29/2016
COP4610
84
Two-level paging
5/29/2016
COP4610
85
Address-Translation Scheme
• Address-translation scheme for a two-level
32-bit paging architecture
5/29/2016
COP4610
86
Virtual Memory
• Separation of user logical memory from
physical memory.
– Only part of the program needs to be in memory
for execution.
– Logical address space can therefore be much
larger than physical address space.
– Need to allow pages to be swapped in and out.
• Virtual memory can be implemented via:
– Demand paging
– Demand segmentation
5/29/2016
COP4610
87
Demand Paging
• Bring a page into memory only when it is
needed.
–
–
–
–
Less I/O needed
Less memory needed
Faster response
More users
• Page is needed  reference to it
– invalid reference  abort
– not-in-memory  bring to memory
5/29/2016
COP4610
88
Page Fault
• If there is ever a reference to a page, first reference to the page
will trap to
OS  page fault
• OS looks at another table to decide:
– Invalid reference  abort.
– Just not in memory.
• Get empty frame.
– Page replacement – find some page in memory, but not
really in use, swap it out
• Swap page into frame.
• Reset tables, validation bit = 1.
5/29/2016
COP4610
89
Modified bit
• Most paging hardware also has a modified bit
in the page table entry
– which is set when the page is written to
• This is also called the “dirty bit”
– pages that have been changed are referred to as
“dirty”
– these pages must be written out to disk because
the disk version is out of date
• this is called “cleaning” the page
5/29/2016
COP4610
90
Performance of Demand Paging
• Page Fault Rate 0  p  1.0
– if p = 0 no page faults
– if p = 1, every reference is a fault
• Effective Access Time (EAT)
EAT = (1 – p) x memory access
+ p (page fault overhead
+ [swap page out ]
+ swap page in
+ restart overhead)
5/29/2016
COP4610
91
Demand Paging Performance Example
• Memory access time = 1 microsecond
• 50% of the time the page that is being
replaced has been modified and therefore
needs to be swapped out.
• Swap Page Time = 10 msec = 10,000 msec
EAT = (1 – p) x 1 + p (15000)
= 1 + 15000 p (in msec)
5/29/2016
COP4610
92
Page replacement algorithms
• The goal of a page replacement algorithm is
to produce the fewest page faults
• We can compare two algorithms
– on a range of page reference sequences
• Or we can compare an algorithm to the best
possible algorithm
• We will start by considering global page
replacement algorithms
5/29/2016
COP4610
93
Optimal replacement algorithm
• The one that produces the fewest possible
page faults on all page reference sequences
• Algorithm: replace the page that will not be
used for the longest time in the future
• Problem: it requires knowledge of the future
• Not realizable in practice
– but it is used to measure the effectiveness of
realizable algorithms
5/29/2016
COP4610
94
FIFO page replacement
• Algorithm: replace the oldest page
• Theory: pages are used for a while and then
stop being used
• Implementation: easy
• Performance: poor
– because old pages are often accessed, that is, the
theory if FIFO is not correct
5/29/2016
COP4610
95
LRU page replacement
• Least-recently used (LRU)
• Algorithm: remove the page that hasn’t been
referenced for the longest time
• Theory: the future will be like the past, page
accesses tend to be clustered in time
• Implementation: hard, requires hardware
assistance (and then still not easy)
• Performance: very good, within 30%-40% of
optimal
5/29/2016
COP4610
96
Working set algorithm example
w=4
5/29/2016
COP4610
97
Thrashing
• There are too many processes in memory and no process has
enough memory to run. As a result, the page fault is very
high and the system spends all of its time handling page fault
interrupts.
5/29/2016
COP4610
98
Levels in a file system
5/29/2016
COP4610
99
Low-level File System Architecture
Block 0
b0 b1 b2 b3 …
…
bn-1
...
Sequential Device
5/29/2016
Randomly Accessed Device
COP4610
100
Low-Level Files
5/29/2016
COP4610
101
A file system layout
5/29/2016
COP4610
102
Locating file data
• The logical file is divided into logical blocks
• Each logical block is mapped to a physical
disk block
• The file descriptor contains data on how to
perform this mapping
– there are many methods for performing this
mapping
– we will look at several of them
5/29/2016
COP4610
103
Contiguous Allocation
• Each file occupies a set of contiguous blocks on the disk
–
–
–
–
Simple – only starting location and length are required
Random access
Wasteful of space (dynamic storage-allocation problem)
Files cannot grow
• Mapping from logical to physical
Q
LA/512
R
– Block to be accessed = Q + starting address
– Displacement into block = R
5/29/2016
COP4610
104
Keeping a file in pieces
• We need a block pointer for each logical
block, an array of block pointers
– block mapping indexes into this array
– Each file is a linked list of disk blocks
• But where do we keep this array?
– usually it is not kept as contiguous array
– the array of disk pointers is like a second related
file (that is 1/1024 as big)
5/29/2016
COP4610
105
DOS FAT Files
File Descriptor
43
Disk
Block
254
Disk
Block
…
107
Disk
Block
File Descriptor
43
43
107
Disk
Block
254
Disk
Block
…
107
Disk
Block
254
File Access Table (FAT)
5/29/2016
COP4610
106
The UNIX hybrid method
5/29/2016
COP4610
107
File Manager Data Structures
2 Keep the state
of the processfile session
3 Return a
reference to
the data
structure
Process-File
Session
Open File
Descriptor
1 Copy info from
external to the
open file
descriptor
External File Descriptor
5/29/2016
COP4610
108
Opening a UNIX File
fid = open(“fileA”, flags);
…
read(fid, buffer, len);
0
1
2
3
stdin
stdout
stderr
...
On-Device File Descriptor
File structure
inode
Open File Table
Internal File Descriptor
5/29/2016
COP4610
109
Structured Files
5/29/2016
COP4610
110
Directories
• A directory is a set of logically associated
files and other directories of files
– Directories are the mechanism we use to organize
files
• The file manager provides a set of commands
to manage directories
– Traverse a directory
– Enumerate a list of all files and nested directories
5/29/2016
COP4610
111
Directory Structures
• How should files be organized within
directory?
– Flat name space
• All files appear in a single directory
– Hierarchical name space
• Directory contains files and subdirectories
• Each file/directory appears as an entry in exactly
one other directory -- a tree
• Popular variant: All directories form a tree, but a
file can have multiple parents.
5/29/2016
COP4610
112
A directory tree
5/29/2016
COP4610
113
Protection and Security
• Operating system consists of a collection of
objects, hardware or software
• Each object has a unique name and can be
accessed through a well-defined set of
operations
• Protection and security problem - ensure that
each object is accessed correctly and only by
those processes of authorized users that are
allowed to do so
5/29/2016
COP4610
114
Allowing Only Authorized Access
Subject
Authorized
Access
Subject
Unauthorized
Access
5/29/2016
Authentication
Authorization
Secure
Entity
COP4610
115
Access Matrix
5/29/2016
COP4610
116
Use of Access Matrix
• If a process in Domain Di tries to do “op” on
object Oj, then “op” must be in the access
matrix.
• Can be expanded to dynamic protection.
– Operations to add, delete access rights.
– Special access rights:
•
•
•
•
5/29/2016
owner of Oi
copy op from Oi to Oj
control – Di can modify Djs access rights
transfer – switch from domain Di to Dj
COP4610
117
Implementation of Access Matrix
• Each column = Access-control list for one object
Defines who can perform what operation.
Domain 1 = Read, Write
Domain 2 = Read
Domain 3 = Read

• Each Row = Capability List (like a key)
Fore each domain, what operations allowed on what
objects.
– Object 1 – Read
– Object 4 – Read, Write, Execute
– Object 5 – Read, Write, Delete, Copy
5/29/2016
COP4610
118
Access Control Example
S1
S1
S2
S3
control
S2
S3
F1
F2
block
wakeup
owner
control
owner
read*
write*
control
stop
owner
update
control
delete
execute
owner
D1
D2
seek
owner
owner
seek*
Access List of F2
{S2, {update}} {S3,{execute, owner}}
5/29/2016
COP4610
119
Capability List Example
S1
S1
S2
S3
control
S2
S3
F1
F2
block
wakeup
owner
control
owner
read*
write*
control
stop
owner
update
control
delete
execute
owner
D1
D2
seek
owner
owner
seek*
Capability list of S2
{S2, {control}} {S3, {stop}} {F1, {owner}}
{F2, {update}} {D1, {owner}} {D2, seek*}}
5/29/2016
COP4610
120
Unix Protection Scheme
• Mode of access: read, write, execute
• Three classes of users
RWX
5/29/2016
a) owner access
7

b) groups access
6

c) public access
1

COP4610
111
RWX
110
RWX
001
121
Thank You
• I greatly appreciate your feedbacks, your
suggestions, and your comments
– I have benefited from your efforts
• I have enjoyed teaching the class
– I hope the class has met your expectations and you
have learned operating system related topics
• Good luck on your finals
• Have a pleasant holiday season
5/29/2016
COP4610
122
Download