1/251
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Deadlock
When processes cannot proceed due to resource contention
4 Conditions of Deadlock
Mutual Exclusion
Hold and Wait
Process holds at least one resource
Waiting to get resources held by other processes
EX. P1 holding R1, P1 wants R2 but it's held by P2.
For P1 to access R2, P2 should release R2. If too much waiting, deadlock
No Preemption
Resources only released by process after completing its task
EX. P1 wants R2, but if OS is non-preemptive, it has to wait for P2 to release R2
Circular Wait
System Resource Allocation Graphs
Graph representing processes and resources with directed edges.
System Resource Allocation Graphs Symbols
Processes - Circle
Resources - Square w/ dots
Request Pi 🡪 Rj
Assignment Rj 🡪 pi
Methods for Handling Deadlocks
Deadlock Prevention
Eliminate at least one condition
Disadvantages:
Low resource utilization
Less throughput (keep getting interrupted)
Prevention for Mutual exclusion
Needed for non-shareable resources but not for shareable ones
Can't prevent mutex for all resources: some intrinsically non-shareable
Prevention for Hold and wait
Guarantee that process does not hold a resource when requesting another
EX. allocate all resource before execution
Prevention for No preemption
When request not granted, process must release all resources it's holding
Restarted only if it regains old and new resources
Prevention for Circular wait
Impose ordering of resources
Require process to request resource in increasing number
If process holds Ri, it can request another, Rj > Ri
If process holds Rj and requests Ri, it must release Rj
Safe state
Deadlock Avoidance
Banker's Algorithm
Deadlock Detection
Single instance resource
Use Wait-For graph
Several instances
Uses time-varying data structures found in Banker's Algorithm
Detection algorithm depends on what 2 factors?
What deadlock detection do we use for single instance resource?
Wait-for graph
What deadlock detection do we use for several instances?
Time-varying data structures found in Banker's Algorithm
Wait-For Graph
Graph showing processes waiting for resources held by others.
What happens when you terminate processes?
What happens when you preempt resources?
Consider victim and starvation
Hybrid Approach
Memory Management
Memory sharing
Several processes in main memory to improve utilization and response
Types of Memory Address
Symbolic Memory Address
Variables
Relocatable Memory Address
offset + 100
Absolute Memory Address
Physical addresses
Ex: 255, 254
3 Forms of Efficient Memory Use
Dynamic loading
EX. Code has math library included (# include math.h). When loaded, it doesn't load whole library, only when called by code
Dynamic linking
EX. Windows has dynamic link library
EX. UNIX has shared objects (dynamic libraries)
Overlays
EX. Code w/ 1000+ lines, don't want to put all that into main memory. So get only needed instructions and keep those in memory
(Overlays) What do you do if no more space?
Overwrite previous instructions that are not needed anymore
Logical address are generated by while Physical Address are generated by _
Logical - CPU
Physical - Memory Management Unit (MMU)
Logical address
Not entirely occupied by physical memory
Abstract or change the view of physical address so virtual code can see addresses in their own way
Another name for logical address
Virtual address
Physical address
Physical location in memory hardware where data is stored
What determines how logical and physical addresses are connected? And what is needed for this?
OS
Mapping scheme requires hardware support (MMU) to convert to physical
Swapping
Why does Roll out (swap out) and roll in (swap to MM) increase context switch time?
Because context-switching is between main memory and CPU so if you context switch AND swap, CPU relies on process being in main memory then it will increase switch time
What happens when a process is swapped out?
Process is removed from main memory and placed on secondary memory by the scheduler
Context Switch vs Swapping
Context Switch - CPU and main memory
Swapping - main memory & secondary memory
What are good candidates for swapping out?
Waiting processes
What is the modified version of swapping used in Unix?
What is the swapping in Microsoft Windows?
Partial swapping
2 Types of Memory Allocation Methods
Contiguous Memory Allocation
Process occupies a single continuous block
Contiguous Memory Allocation Algorithms
Single-partition
OS code either in high or low memory
Must protect from user codes (uses relocatable addressing or offset so it doesn't overlap given reserved memory addresses)
Types of Multiple-partition Algorithms
Fixed (Multiple-partition Algorithms)
Dynamic (Multiple-partition Algorithms)
What are the algorithms for dynamic storage allocation problem?
Which algorithm is the fastest?
First-fit
Which algorithm is best for storage utilization?
Best-fit
2 Types of Fragmentation
External Fragmentation
50% Rule in External Fragmentation
Given N allocated blocks, the next 0.5N blocks will be lost due to fragmentation (1/3 unusable memory)
Internal Fragmentation
Allocated memory has unused space within a block due to fixed-size allocation
How to solve external fragmentation?
Compaction (not always possible)
May be combined with swapping
Compaction Algorithms
Types of Non-contiguous Allocation
Paging
What is the size of the process based on? (paging)
Size of process is based on how many pages
What is the size of a frame?
Frame is same size as page to avoid external fragmentation
Pages translate into _?
Pages (logical) translate into frames (physical)
Physical Address
Actual location in memory hardware.
Fragmentation in Paging
What is the worst case for fragmentation in paging?
n pages + 1 byte
Wasted: page size - 1 byte
Page Table Structure
Shared Pages
What happens to the access when you share a page?
What are examples of shared pages? Where are they used?
compilers, editors
Used in time-sharing environment
Segmentation
Segmentation Hardware
What does an entry in the segment table consist of?
segment base (starting address) and limit (segment length)
Segmentation with paging
Solves external fragmentation problem of pure segmentation
Each segment composed of several equal-sized pages
File System
File Basics: Attribute
Name
Type
Location
Size
Security
Date/Time
User ID
File Basics: Operations
Create
Write
Read
Reposition within file
Delete
Truncate (change contents of file without deleting it or changing its location)
File Basics: Types of Access Methods
Access Methods: Direct
Direct access to a file block
Access Methods: Sequential
In sequential access, what happens if user wishes to read the 1st word of file?
Pointer gives it to them and raises its value to next word
In sequential access, how is the data in the file evaluated?
In order that it appears in file and so it's easy to access a file's data
Access Methods: Indexed
Variant of direct access
Maintains an index w/ address
OS searches for address in index which points to the block
Directory Structure: How are file systems structured?
File system divided into partitions or volumes (PC and Mac)
Each partition contains info about files (directory, FAT, etc.)
Directory Structure: Types of Logical Schemes
Single-level Logical Scheme
In a Single-level Logical Scheme, if multiple users have access, how will you divide the files?
Prefixing file names with usernames to avoid name conflicts
Two-level Logical Scheme
True or False: In Two-level Logical Scheme, you can access files of other users
FALSE
Tree-structured Logical Scheme
Different directories have sub directories
1 parent per child
Root directory on top that spans to other directories
True or False: In a Tree-structured Logical Scheme, you can have subdirectories
TRUE
Can have files or subdirectories under
Acyclic graph Logical Scheme
Which logical scheme permits shared subdirectories? And how does it do it?
Acyclic graph Logical Scheme
via Links
How do Acyclic graphs save space?
Users can share files without duplication