Department of Computer Science
DCS
COMSATS Institute of
Information Technology
Assistant Professor
COMSATS Lahore
Pakistan
Operating System Concepts
Primary memory (real memory, physical memory) of computer system has been a major influence on OS design.
Main memory is still expansive compared to secondary storage.
Department of Computer Science
Operating System Release date
Windows 1.0
Windows 2.03
Windows 3.0
Windows 3.1
Windows 95
Windows NT 4.0
Windows 98
Windows ME
Windows 2000
Professional
Windows XP
Home
Windows XP prof
Windows Vista
Windows 7
Nov 1985
Nov 1987
Mar 1990
Apr 1992
Aug 1995
Aug 1996
Jun 1998
Sep 2000
Feb 2000
Oct 2001
Oct 2001
Jan 2007
Oct 2009
Minimum memory req
256 KB
320 KB
896 KB
2.6 MB
8 MB
32 MB
24 MB
32 MB
64 MB
Recomm.
Memory
I MB
4 MB
16 MB
96 MB
64 MB
128 MB
128 MB
64 MB
128 MB
512 MB
1 GB
128 MB
256 MB
1 GB
2 GB
Department of Computer Science 3
Department of Computer Science 4
It is the component of the OS concerned with the system’s memory organization scheme and memory management strategies.
It determines, how available memory space is allocated to processes and how to respond to changes in a memory process’s memory usage.
It also interact with special purpose memory management Hardware to improve performance.
Department of Computer Science 5
Memory
Management
Strategies
Fetch strategies
Placement strategies
Replacement strategies
Demand fetch
Anticipatory fetch
First fit
Best fit
Worst fit
Department of Computer Science 6
Fetch Strategy
It determines when to move the next piece of a program or data to main memory from the secondary memory.
Demand Fetch
In the conventional methods, the system places the next piece of the code or data in main memory when a running program references it.
That is, programs are loaded into the RAM area when they are needed.
Department of Computer Science 7
Anticipatory strategy
The program or data which is loaded on the basis of prediction that it will be reference in the near future.
This will increase the performance but if the loaded pages are not used, then there is an inefficient memory utilization.
Department of Computer Science 8
Placement strategy
It determines where in main memory the system should place incoming program or data pieces.
First Fit Strategy
Place the incoming page into the first available hole in the memory
It is faster but leads to memory waste.
It allows the system to make a placement decision quickly.
Best Fit Strategy
Place the incoming page into the hole in which it fits tight.
Best use of memory space.
It is slower in making allocation.
Department of Computer Science 9
Worst Fit Strategy
Worst-fit memory allocation is opposite to best-fit.
It allocates free available block to the new job and it is not the best choice for an actual system.
Place the incoming job in the largest available whole
Problem Memory fragmentation Memory waste.
Department of Computer Science 10
Replacement strategy
When memory is too full to accommodate a new program, the system must remove some of program or data currently resides in memory.
The system’s replacement strategy determines which piece to remove for making room for incoming jobs.
Department of Computer Science 11
To execute a program in the early systems, the
OS had to find enough contiguous main memory to accommodate the entire program.
If the program size is larger than the available memory, the program could not execute it.
This is done in contiguous memory allocation, in which all the program pages are loaded into the adjacent memory allocations.
Department of Computer Science 12
Non Contiguous Memory Allocation
In noncontiguous memory allocation, a program is divided into blocks or segments, that the system may place in non adjacent slots in main memory
This allows making use of holes (unused gaps) in memory that would be too small to hold whole programs.
The OS thereby incurs more overhead as for as using these unused holes for incoming pages.
Department of Computer Science 13
When is noncontiguous preferable to contiguous memory allocation???
ANSWER!
When the available memory contain no area large enough to hold the incoming programs in one Contiguous space, but sufficient smaller pieces of memory are available, that in total are large enough.
Department of Computer Science 14
Contiguous memory allocation limited the size of programs that could execute on the system
One way in which software designer could overcome the memory limitation was to create overlays, which allowed the system to execute programs larger than main memory.
Programmer divides the program into logical sections.
When the program does not need the memory for one section, the system can replace some or all of its with the memory for a needed section.
Overlays enables a programmer to extend main memory.
Department of Computer Science 15
0
Operating System a b
Portion of user code and data than must remain in main memory for duration of execution
Overlay Area
A
B
C c b
User portion with memory requirements larger than available portion of main memory
Initialization phase b
Processing phase
A
Load initialization phase at b and run
B
C
Load Processing phase at b and run
Load Output phase at b and run b
Output phase
Department of Computer Science 16
Managed overlay requires careful and time consuming planning and the programmer often must have detailed knowledge of the system memory organization.
Later on virtual memory system obviate the need for programmer controlled overlays.
Department of Computer Science 17
Protection in single user contiguous memory allocation systems can be implemented with a single
processor.
built into the
The boundary register contains the memory address at which the user’s program begins.
Each time a process reference a memory address the system determines if the request is for an address greater than or equal to that stored in the boundary register.
If yes, system service the memory request.
Else program is trying to access OS, request is terminated with an error message.
Department of Computer Science 18
0 a
Operating System Processor b c
User Area
Boundary register a
Unused Area
Note :
Operating System prevents the user from accessing the addresses less than a.
Memory protection with single user contiguous memory allocation
Department of Computer Science 19
Even with batch processing OSs, a single user systems still wasted a considerable amount of the computing resource.
A processor wait until IO finished. Because IO speeds were extremely slow compared with processor speed, the CPU was severely underutilized.
Designer saw that they could further increase CPU utilization by implementing multiprogramming systems, in which several users simultaneously compete for the system resources.
The process currently waiting for IO yields the processor if another process is ready to do calculation.
Department of Computer Science 20
Thus IO and processing operation done simultaneously.
Greatly increases CPU utilization and system throughput.
To take advantage of Multiprogramming several processes must reside in the computer’s main memory at the same time.
When one process requests IO, the CPU may switch to another process and continue without any delay associated with loading programs from secondary storage.
Department of Computer Science 21
The earlier multiprogramming systems used fixed partition multiprogramming.
In which, system divides main memory into a number of fixed size partitions.
Each partition holds a single job, and the system switches the processor rapidly between jobs to create the illusion of simultaneously.
Department of Computer Science 22
In the early multiprogramming systems, the programmer translated a job using an absolute assembler or compiler (comp. , linking, and loading),
A job had its precise location in memory determined before it was launched and could run only in a specific partition.
This restriction led to wasted memory because the job had to wait for its designated partition (if occupied), even if other partitions were available.
Department of Computer Science 23
Job Queue for partition 1
These Jobs run only in partition 1
These Jobs run only in partition 2
Job Queue for partition 2
Job Queue for partition 3
These Jobs run only in partition 3
0 a b c
Operating system
Partition 1
Partition 2
Partition 3 d
Fixed partition multiprogramming with absolute translation and loading
Department of Computer Science 24
0
Operating system
Job Queue for partition 1 a
No jobs waiting for partition 1
Partition 1
Job Queue for partition 2 b
No jobs waiting for partition 2
Partition 2
Job Queue for partition 3 c
Partition 3
(in use) d
Memory waste under Fixed partition multiprogramming with absolute translation and loading
Department of Computer Science 25
jobs
0 a
Operating system
Partition 1
Job Queue b
Partition 2 c
Partition 3 d
Fixed partition multiprogramming with relocateable translation and loading
Department of Computer Science 26
The system can delimit each partition with two boundary registers,
Low and
High
Also called the base and limit register
If a process issues a request for memory, the system checks whether the requested is greater than or equal to the process low boundary register value and less then the high register value.
If so, the system honors the request. Else terminate the request with error.
Department of Computer Science 27
0 a b
Operating system
Partition 1
Processor
2 b
Currently active partition
Low Boundary c High Boundary Partition 2 c
Partition 3 d
Memory protection in contiguous allocation multiprogramming systems
Department of Computer Science 28
One problem prevalent in all memory organizations is that of fragmentation (loss of memory).
This states that certain area of the available RAM that system cannot use.
Fixed partition multiprogramming suffers from internal fragmentation , which occurs when the size of the process’s memory and data is smaller than that of the partition in which the process execute.
Department of Computer Science 29
0 a
Operating system
Partition 1
Used Memory b
Partition 2 Unused Memory c
Partition 3 d
Internal Fragmentation in a Fixed Partition Multiprogramming System
Department of Computer Science 30
Explain the need for relocating compilers, assemblers and loaders???
Answer
Before such tools, programmer manually specified the partition into which
Their program had to be loaded, which potentially wasted memory and
Processor utilization and reduce application portability.
Department of Computer Science 31
Explain the benefits and drawbacks of large and small partition sizes???
Answer
Larger partition allows large program to run, but result in internal fragmentation For small programs. Small partition reduce the amount of internal fragmentation And increase the level of multiprogramming by allowing more programs to reside In memory at once, but limit program size.
Department of Computer Science 32
This scheme allows a process to occupy only as much space as needed (up to the amount of available main memory).
This scheme is called variable partition multiprogramming.
The figure on next slide shows the contiguous allocation schemes where a process must occupy adjacent memory allocations.
The queue at the top contains available jobs and information about their memory requirements.
Department of Computer Science 33
Department of Computer Science 34
Variable partitioning does not suffer from internal fragmentation, because the process’s partition is exactly the size of the process.
Holes can be created upon process execution / completion.
These holes cannot accommodate the incoming processes which are larger than these available holes.
These holes are called external fragmentation.
Department of Computer Science 35
Department of Computer Science 36
There are two techniques to overcome the problems of external fragmentation created in variable partitioning system.
The techniques are,
Coalescing (Merging adjacent locations)
Compaction
Department of Computer Science 37
Department of Computer Science 38
Department of Computer Science 39
Department of Computer Science 40