CHAPTER 2: MEMORY AND PROCESS MANAGEMENT
MEMORY MANAGEMENT OF OPERATING SYSTEM
a)The computer’s available pool of memory
b)Allocating space to application routines and making sure that they do not interfere with each other.
Primary function
=to preserve the space in main memory occupied by the operating system itself.
Characteristics of the Different Levels in The Hierarchy of
Memory Management:
a)memory hierarchy separates computer storage into a hierarchy based on response time
b)There are four major storage levels
1.Internal – processor registers and cache.
2.Main – the system RAM and controller cards.
3.On-line mass storage – Secondary storage.
4.Off-line bulk storage – Tertiary and Off-line storage.
c)1.Logical address – is address generated by CPU
2.Physical address – address seen in the memory unit
Memory Management Strategies in Memory Allocation:
1. Fetch
-The rules used by virtual memory manager to determine when a page is copied from disk to memory
-Determine when to move the next piece of a program or data to main memory from secondary storage.
2. Placement
-The rules used by virtual memory manager to determine where the virtual pages to be loaded
-Determine where in main memory the system should place incoming program or data pieces.
a)First fit
Allocate the first Memory block that is large enough for the new process. Searching can start either at the beginning of the set of holes or at the location where the previous first-fit search ended.
b) Best fit
Allocate the smallest block among those that are large enough for the new process.
c) Worst fit
Allocate the largest block among those that are large enough for the new process.
3. Replacement
-The rules used by VM manager to determine which virtual page must be removed from memory to make room for new page.
-When memory is to full to accommodate a new program, the system must remove some (or all) of a program or data that currently resides in memory.
Resident & Transient Routines
Resident routines:
Routines that directly support application programs as they run.
Example: routine that control physical I/O
Transient routines
Stored on disk and read into memory only when needed.
Example:routine that formats disks
Swapping Technique
a)The technique of temporarily removing a process from the memory of a computer system.
Swap – out operation: by copying its instruction and data onto a disk. This operation frees the area of memory that was allocated to the process.
Swap – in operation : by loads another process in this area of memory.
Fixed – Partition Memory Management:
a)Divides the available space into fixed-length partitions, each of which holds one
program.
b)This would allow several user jobs to reside in the memory.
c)Partition sizes are generally set when the system is initially started, so the memory allocation decision is made before the actual amount of space needed by a given program is known.
Advantages:
1.Its major advantage is simplicity
2.Is to provide multiprogramming
Disadvantages
1.Because the size of a partition must be big enough to hold the largest program that is likely to be loaded, fixed-partition memory management wastes space
2.Internal and external fragmentation occur
Segmentation:
a)Concept : based on the common practice by programmers of structuring their
program in modules
b)Segmentation scheme : each job is divided into several segment of different sizes. One for each module that contains pieces that perform related function
c)Main memory is no longer divided into page frames because the size of each segment is different (some are large some are small)
d)When a program is compiled the segment are set up according to the program’s structural modules.
A program is a collection of segments. A segment is a logical unit such as:
1.Main program ,subroutine
2.Procedure
3.Function
4.Method
5.Object
6.Local variable, global variable,
7.Stack, array ,symbol table
Paging:
a)A program’s segments can vary in length.
b)Under paging, a program is broken into fixed-length pages. Page size is generally small (perhaps 2K to 4K), and chosen with hardware efficiency in mind.
c)Like segments, a program’s pages are loaded into noncontiguous memory.
d)Addresses consist of two parts , a page number in the high-order positions and a displacement in the low-order bits.
e)Addresses are dynamically translated as the program runs. When an instruction is fetched, its base-plus displacement addresses are expanded to absolute addresses by hardware.
f)Then the page’s base address is looked up in a program page table (like the segment table, maintained by the operating system) and added to the displacement.
Process Management:
a)The computer system today allow multiple programs to be loaded into memory and to be executed concurrently but at one point of time only one program is in execution or rather at most one instruction is executed on behalf of the process.
b)A source program stored on disk is called passive because it will not demand any resource.
Eg: Program in executions is called process – during execution demand resource like CPU, memory, I/O etc for execution.
Major System Resource Types within a Computer System:
1.CPU Time
=CPU time (or process time) is the amount of time for which a central processing unit (CPU) was used for processing instructions of a computer program or operating system
2.Memory
=refers to the physical devices used to store programs (sequences of instructions) or data (e.g. program state information) on a temporary or permanent basis for use in a computer or other digital electronic device.
3.Hard Disk space
=The amount of permanent storage of data, measured in bytes. This storage is maintained whether the computer is on or off.
4.Network
=network is a group of two or more computer systems linked together.
5.Throughput
=number of processes that complete their execution per time unit.
6.Electrical power
=is the rate at which electric energy is transferred by an electric circuit.
7.External devices
=Any peripheral device that is not housed inside the computer cabinet. Monitors, keyboards, mice and printers are inherently external devices; however, drives, network adapters and modems may also be external.
States of a Process:
a. New : Created
=Here the OS recognizes the process but does not assign recourses to it.
b. Ready : Assign a process to a processor
=The process is ready/ waiting to be assigned to a processor.
c. Run : Instruction execution
When a process is selected by the CPU for execution,it moves to the run state.
d. Blocked : For an event to occur
When a process is waiting for some event to occur, eg I/O completion or reception of a signal then it is in the blocked state/ when a running process does not have access to a resource it is said to be in the blocked state.
e. Terminated : Finish execution
This is state reached when the process finishes execution.
Interrupts:
a)An interrupt is an electronic signal.
b)Hardware senses the signal, saves key control information for the currently executing program, and starts the operating system’s interrupt handler routine. At that instant, the interrupt ends.
Scheduling Concept:
a)The basis of multitasking is scheduling.
b)Determining when a given process is to be run, within a multitasking environment called scheduling
Example : User standing in the queue are synonyms with process and the reservation clerk is synonym with CPU.
CPU Scheduler:
a. None - Preemptive
=Always processes a scheduled request to completion
Since only one request is under processing by the CPU at any time, it is not necessary to maintain the distinction between long, medium and short – term scheduling
Example of scheduling are FCFS and SJF scheduling
b. Preemptive:
a)Interrupts the processing of a job and transfer the CPU to another job.
b)Strategy of allowing process that are logically run able to be suspended.
c)It is widely used in time-sharing environments
d)The process may be pre-empted by the operating system when:
1.a new process arrives (perhaps at a higher priority), or
2.an interrupt or signal occurs, or
3.a (frequent) clock interrupt occurs.
Purpose of CPU Scheduler
a. Long term scheduler / Job Scheduler:
Which program are admitted to the system for execution and when and which one should be exited.
b. Medium Term Scheduler:
Which determine when process are to be suspended and resumed.
c. Short term scheduler/ CPU scheduler/ Dispatcher:
Which determines which of the ready processes can have CPU resources, and for how long.
Scheduling Creteria:
1.CPU utilization
=keep the CPU as busy as possible, we want to reduce the idle time.
2.Throughput
=number of processes that complete their execution per time unit.
3.Turnaround time
=amount of time to execute a particular process.
4.Waiting time
=amount of time a process has been waiting in the ready queue.
5.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)
Optimization Criteria
Max
1.CPU utilization
2.throughput
Min
1.turnaround time
2.waiting time
3.response time
Deadlock
=will occurs in a computer system if all the following conditions hold simultaneously.
Process Scheduling Algorithms:
1.First Come First Serve (FCFS)
2) Shortest-Job-First (SJF) Scheduling
3) Shortest Remaining Time
4) Priority Scheduling
5) Round Robin Scheduling
a)Average waiting time:
=starting time - arrival time
AWT =total waiting time of all processes / no of processes
b)Average turnaround time:
=Finished time - arrival time
ATT = total turnaround time of all processes / no of processes
c)Average respond time:
=First response - arrival time
ART =total respond time of all processes / no of processes
Four condition for deadlock to Occur:
1. Mutual Exclusion
= means that a resource is assigned to only one process at a time.
2. Hold and Wait
= condition means a situation where in a process owns a resource and claiming the other resource.
3. No preemption
= condition means a situation where the granted resource to a process cannot be taken back by the operating system forcibly.
4. Circular wait
= is a situation where each waiting process is waiting for the next process in the chain and none is able to get the resource.
Methods for handling deadlocks:
1.Ignore Deadlocks:
Ensure deadlock never occurs using either:
2.Prevention
= Prevent any one of the 4 conditions from happening.
3.Avoidance
= Allow all deadlock conditions, but calculate cycles about to happen and stop dangerous operations.
Allow deadlock to happen. This requires using both:
4.Detection
= Know a deadlock has occurred.
5.Recovery
= Regain the resources.
Threads
=a unit smaller than a process, which can be scheduled and executed
has two characteristics:
It requires space in main memory where it resides during its execution; although, from time to time, it requires other resources such as data files or I/O devices.
It passes through several states (such as running, waiting, ready) from its initial arrival into the computer system to its completion.
A)Using this technique, the heavyweight process, which owns the resources, becomes a more passive element, while a thread becomes the element that uses the CPU and is scheduled for execution.
B)Manipulating threads is less time consuming than manipulating processes, which are more complex. Some operating systems support multiple processes with a single thread, while others support multiple processes with multiple threads.