Deadlock Avoidance Determine whether, by allowing allocation, we could get a deadlock, i.e. check if by allowing allocation the system could enter a state.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Management Chapter 7.
Allocating Memory.
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Chapter 5.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Memory Management Chapter 7.
Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
Exam2 Review Bernard Chen Spring Deadlock Example semaphores A and B, initialized to 1 P0 P1 wait (A); wait(B) wait (B); wait(A)
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
MEMORY MANAGEMENT Operating System. Memory Management Memory management is how the OS makes best use of the memory available to it Remember that the OS.
Memory Management Chapter 5 Advanced Operating System.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Deadlock. Stepping on each other’s feet - I Thread T 1 b1:= allocate(); b2:= allocate(); …… release(b1); release(b2); Thread T 2 b1:= allocate(); b2:=
Memory Management One of the most important OS jobs.
Process Management Deadlocks.
Memory Management Chapter 7.
Chapter 7 Memory Management
Memory Management Chapter 7.
Memory Management.
ITEC 202 Operating Systems
Chapter 2 Memory and process management
Requirements, Partitioning, paging, and segmentation
Day 19 Memory Management.
Day 19 Memory Management.
Memory management.
Chapter 9 – Real Memory Organization and Management
Chapter 8 Main Memory.
Day 18 Memory Management.
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Multistep Processing of a User Program
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
So far… Text RO …. printf() RW link printf Linking, loading
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Introduction to Memory Management
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Memory Management (1).
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
Chapter 7 Memory Management
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

Deadlock Avoidance Determine whether, by allowing allocation, we could get a deadlock, i.e. check if by allowing allocation the system could enter a state that is not safe Simple way to do it: have each process declare the maximum number of resources of each type that it may need

Claims Graph Claim graph: Resource graphs that also contains edges that represent potential requests (each process needs to specify max claim to each resource) r p1p1 p2p2 p1p1 p2p2 p1p1 p2p2 p1p1 p2p2 Requests one unit Still completely reducible Requests one unit Not completely reducible (no deadlock though (yet))

Banker’s Algorithm (Dijkstra & Habermann) Variables: available[i]: units of r i not allocated c[a,i]: max claim of p a on r i alloc[a,i]: number of units of r i allocated to p a need[a,i]: number of potential requests: c[a,i] - alloc[a,i] finish[i]: one entry per process, true if process can finish work[i]: one entry per process Let p a attempt to allocate request units of r i if request > need[a,i] {error}; if request > available[i] {wait}; available[i] := available[i] - request; alloc[a,i] := alloc[a,i] + request; need[a,i] := need[a,i] - request; if (not safe()) {undo request and wait}; safe() work[i] := available[i]; while (  u: not finish[u] and (need(u,i) ≤ work[i])) { work[i] := work[i]+alloc[u]; finish[u]:= true; } safe :=  u: finish[u]

Solution: Priority Inheritance If low-priority thread holds lock and A high-priority thread requests lock then set low-priority thread’s priority to that of the high-priority thread until it gives up lock.

Priority Inversion Happens a lot vxWorks problems in Pathfinder Fundamental problem: –Low-priority thread holds lock, enters C.S. –Higher-priority thread blocks waiting for lock –A medium-priority thread comes along and KA-BOOOOOM

STORAGE MANAGEMENT

The Storage Hierarchy CPU L1 L2 L3(optional) Main Memory Disk TapesCD’s

Properties Price/byte goes down as you move up the hierarchy: –L1 > L2 > L3 > Main memory > Disk > Tapes Speed goes down as well: –L1 > L2 > L3 > Main memory > Disk > Tapes Trends: –CPU getting much faster than storage –The space-time complexity is inherent

Fact You can: Increase size and maintain same speed Increase speed and maintain same size BUT Generally, you cannot do both at a reasonable cost

Programmer’s View Memory is an array of bytes It is addressable in a linear fashion: –e.g. For a machine that has a 32-bit address space, memory is an array from 0 to Memory cannot hold values between program runs (or when machine powered down)

NonRelocatable Programs Programs written such that: They must be loaded and run at some specific address or specific range, and/or Assume some specific region in memory will be theirs

Relocatable Programs Programs written such that: They do not assume anything about where they will be loaded, and do not assume anything about where the data are placed A linker can prepare them to run anywhere Example: UNIX, Windows NT, OS/2…

Relocatable vs. Nonrelocatable ldr0, 0x8000 addr0, 4 ld0x8004, r0 this assumes data at locations 0x8000 and 0x8004 ldr0, *8000 addr0, 4 ld*8004, r0 this tells linker data should be fetched from offsets

Implementing Relocation Through a relocating loader Through a relocation register

A Relocating Loader Resolves the references at load time. More flexible, no need to know where program will run beforehand More overhead, because it had to be done every time the program is run

Relocation Register All addressing is relative to a base register Program can be relocated by changing the value of the base register Example: ldr0, br(8000) addr0, 4 ldbr(8004), r0

Memory Management Enable programmers to use memory Protect programs from one another Manage the physical resources efficiently

Early Systems Not much of an operating system Not much memory Program + monitor No protection, or relocation Example: DOS Monitor User Program

Overlaying To overcome limited memory space: Program written in pieces After each piece finishes, it “loads” next piece and runs it Code in one overlay cannot access data or code in another overlay without loading it Can be very interesting to program (don’t try this at home!)

Example Overlay control Monitor Overlay 2 Overlay 1Overlay 3 On disk

Multiple Partition Allocation Memory grew larger We want to have more programs in main memory at the same time Thus: –Create multiple partitions in main memory –Allocate one partition to each program

Fixed Partition Allocation Partition 1 Partition 2 Partition 3 Divide memory into partitions of fixed sizes Load a program into a partition A program in a partition cannot access code in another partition

Internal Fragmentation Partition 1 Partition 2 Partition 3Program This fragment is wasted A program rarely fits exactly into a partition

Protection: Limit Registers In addition to the base register, we can have a limit register or a length register base register limit register every access is checked in hardware to ensure it is within the allowable limits Program

Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best with relocation registers

Dynamic Partition Allocation Program 1 Program 2 Program 3

Implementation OS maintains a list of free regions of memory (holes) Loads job in a hole and runs it Selecting the hole –first fit: allocate first hole that is large enough –best fit: allocate smallest hole that is large enough –worst fit: allocate largest hole –rotating first fit: start next search from where you left off

External Fragmentation Program 1 Program 2 Program 3 These fragments are not allocated to any program, and they are wasted.

How bad is external fragmentation? (Knuth) H: # of holesS: # of used segments blue: when released, H is decreased by 1 green: when released, H is unchanged red: when released, H is increased S = b+g+r H = (2b+y+  )/2 At equilibrium, b = r S = b+g+r = 2b+g = 2H or H = S/2 number of holes is half of number of segments!

Compaction (Burping) Program 1 Program 2 Program 3 Program 1 Program 2 Program 3