Memory Note Part 1
Memory Note Part 1
2560K possible
possible
Fig. 1 Main memory partition
Memory management in multi-programming system concerned with three functions. These are:
i) To keep track of which parts of memory are currently used and which parts are not in use,
ii) To allocate memory to processes when they need it and de-allocate it when they are done,
iii) To manage swapping b/n main memory and hard-disk when main memory is too small to hold all
the processes.
Swapping
Remove a process temporarily from main memory to a backing store and later, bring it back into
memory for continued execution
Roll-out, Roll-in Swapping
Allows to preempt a lower priority process in favor of a higher priority process
After the higher priority process is done, the preempted process is continued
Major part of swap time is transfer time; total transfer time is directly proportional to the
amount of memory swapped.
Process may or may not be swapped into the same memory space depending upon the availability
of execution time binding
Backing store
Preferably a fast disk
Must be large enough to accommodate copies of all memory images of all processes
Must provide direct access to each memory image
Maintain a ready queue of all processes on the backing store
Dispatcher brings the process into memory if needed
Overlay: is a technique that is used to keep in memory only those instructions and data
that are needed at any given time.
Needed when process is larger than amount of memory allocated to it.
Implemented by user, no special support needed from operating system;
programming design of overlay structure is complex.
Simple to implement, but main memory use is extremely inefficient due to internal
fragmentation. The phenomenon, in which there is wasted space internal to a partition
due to the fact that the block of data loaded is smaller than the partition, is referred to as
internal fragmentation.
Note: The use of fixed partitioning is almost unknown today. One example of an OS that
did use this technique was an early IBM mainframe OS (OS/MFT; MFT:
Multiprogramming with a Fixed number of Tasks)
– In this memory partition method the entire user space is treated as a “Big hole”.
– Hole – block of available memory; holes of various size are scattered throughout memory.
– When a process arrives, it is allocated memory from a hole large enough to accommodate it
(i. e. each process is loaded into partition of exactly the same size at that process).
– The boundaries of partitions are dynamically changed, and the boundaries are depend on
the size of the processes.
– Operating system maintains information about:
a) allocated partitions
a) free partitions (hole)
– Partitions are of variable length (size) and number
– Process is allocated exactly as much memory as required
– Avoids internal fragmentation, but must deal with external fragmentation
At some point, none of the processes in memory is ready. The OS therefore swaps-out process 2
(fig. 5 e), which leaves sufficient room to load a new process, process 4 (fig. 5 f ).
Later, a point is reached at which none of the processes in main memory is ready, but process 2
in the ready, suspend state is available. Because there is insufficient room in memory for process
2, the Operating system swaps process 1 out (fig. 5 g ) and swaps process 2 back-in (fig. 5 h).
As this example shows, there are a lot of small holes in memory. As times goes on, memory
becomes more and more fragmented, and memory use declines. This phenomenon is called
external fragmentation.
Must use compaction to shift processes so they are contiguous and all free memory is in one block.
P3
Dynamic Partitioning Placement Algorithm
When it is time to load or swap a process into main memory and if there is
more than one free hole of memory of sufficient size, then the operating 16M
system must decide which free hole to allocate (i. e. how to satisfy a
request of size n from a list of free holes.).
i) First-fit: It begins to scan memory from the beginning and chooses the first available hole
that is large enough (regardless of size).
ii) Best-fit: Find the smallest available block that will hold the program.
– It chooses the hole that is closest in size to the request; must search entire list,
unless ordered by size. Produces the smallest leftover hole. (Example: Use
30K block for 28K program, leaves 2K)
– Since smallest block is found for process, the smallest amount of fragmentation
is left memory compaction must be done more often
iii) Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover
hole.
Example:
Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in-the-order). How would the
following algorithms place processes of P1= 212K, P2=417K, P3=112K, and P4=426K (in-the-order)?
600K
Total 559K
==============================================================
Answer:
Best-fit algorithm
Memory partitions
OS size: 100K Processes Partition Internal Fragmentation
500K P1=212k In 300K 88K
Total 433K
Memory protection
Main memory usually divided into two partitions (refer fig. 1):
– Resident operating system, usually held in low memory with interrupt vector.
– User processes then held in high memory.
0000
OS
800K
2200K Job 3
3200K Job n
A: This protection must be provided by the hardware. Consider the fig. 7, it depicts the hardware
– The base register holds the smallest legal physical address (1200K);
– Then the program can legally access all addresses from 1200K through 1800K inclusive.
If the logical address is greater than the contents of the base register it is authorized to
access, otherwise it is trap to operating system. The physical address (logical + base) is
less than (base + limit) it causes no problems, otherwise it is trap to the operating
system.
CPU
Logical
Yes
Physical
address address
No No
Trap to OS Memory
Review questions
1. List down different types of memory partitioning tecchniques.
a) Best-Fit
b) First-Fit
c) Worst-Fit
7. Suppose a process requests 15K byte of memory and the memory manager currently has a list
of unallocated blocks of 10 KB, 20 KB, 16 KB, 7 KB, 25 KB, 35 KB, and 45 KB blocks (in- the-
order). Which memory space will be selected for 15 KB process using the following algorithms:
a) First fit
b) Best-Fit
8. What do you mean by memory compaction? Why compaction is not always possible?