Unit - V
Unit - V
Chapter – 5
Memory Management
Advantages:
Simple to implement
It requires minimal operating system software and processing overhead as
partitions are fixed at the time of system generation.
Disadvantages:
Memory wastage
Inefficient use of memory due to internal fragmentation.
Maximum number of active processes is fixed.
Q.What is fragmentation?
As processes are loaded and removed from memory, the free memory space is broken
into little pieces. It happens after sometimes that processes cannot be allocated to
memory blocks considering their small size and memory blocks remains unused.
This problem is known as Fragmentation.
Fragmentation is of two types −
S.N. Fragmentation & Description
External fragmentation
1 Total memory space is enough to satisfy a request or to reside a process in it, but it is
not contiguous, so it cannot be used.
Internal fragmentation
2 Memory block assigned to process is bigger. Some portion of memory is left unused, as
it cannot be used by another process.
The following diagram shows how fragmentation can cause waste of memory and a
compaction technique can be used to create more free memory out of fragmented
memory –
a) Best-fit:- It chooses the block, that is closest in size to the given request from the
beginning to the ending free blocks.
We must search the entire list, unless it is ordered by size.
This strategy produces the smallest leftover hole.
b) First-fit:- It begins to scan memory from the beginning and chooses the first available
block which is large enough.
Searching can start either at the beginning of the set of blocks or where the previous
first-fit search ended.
We can stop searching as soon as we find a free block that is large enough.
4. List three main levels of data storage and explain cache storage.
{{**Note: - Any other relevant explanation shall be considered. **}}
Three levels of data storage:
1. Primary Storage
2. Secondary Storage
3. Tertiary Storage
Cache Storage:
A Cache (Pronounced as “cash”) is a small and very fast temporary storage memory.
It is designed to speed up the transfer of data and instructions.
It is located inside or close to the CPU chip.
It is faster than RAM and the data/instructions that are most recently or most
frequently used by CPU are stored in cache.
As CPU has to fetch instruction from main memory speed of CPU depending on
fetching speed from main memory.
CPU contains register which has fastest access but they are limited in number as well
as costly. Cache is cheaper so we can access cache.
Cache memory is a very high speed memory that is placed between the CPU and main
memory, to operate at the speed of the CPU.
It is used to reduce the average time to access data from the main memory.
The cache is a smaller and faster memory which stores copies of the data from
frequently used main memory locations.
Most CPUs have different independent caches, including instruction and data.
b) Secondary-Storage Management:
Systems have several levels of storage, including primary storage, secondary storage
and cachestorage.
Instructions and data must be placed in primary storage or cache to be referenced by a
runningprogram.
Because main memory is too small to accommodate all data and programs, and its data
arelost when power is lost, the computer system must provide secondary storage to
back up mainmemory.
Secondary storage consists of tapes, Disks, and other media designed to hold
information thatwill eventually be accessed in primary storage (primary, secondary,
cache) is ordinarily divided intobytes or words consisting of a fixed number of bytes.
Each location in storage has an address; the setof all addresses available to a program
is called an address space.
The three major activities of anoperating system in regard to secondary storage
management are:
Managing the free space available on the secondary-storage device
Allocation of storage space when new files have to be written.
Scheduling the requests for memory access.
2. Linked List :
In this approach, the free disk blocks are linked together i.e. a free block contains a
pointer to the next free block.
The block number of the very first disk block is stored at a separate location on disk
and is also cached in memory.
In Figure-2, the free space list head points to Block 5 which points to Block 6, the
next free block and so on.
The last free block would contain a null pointer indicating the end of free list.
A drawback of this method is the I/O required for free space list traversal.
Techniques-
There are two popular techniques used for non-contiguous memory allocation-
1. Paging
2. Segmentation
Paging-
Paging is a fixed size partitioning scheme.
In paging, secondary memory and main memory are divided into equal fixed size
partitions.
The partitions of secondary memory are called as pages.
The partitions of main memory are called as frames.
Each process is divided into parts where size of each part is same as page size.
The size of the last part may be less than the page size.
The pages of process are stored in the frames of main memory depending upon their
availability.
Example-
Consider a process is divided into 4 pages P0, P1, P2 and P3.
Depending upon the availability, these pages may be stored in the main memory
frames in a non-contiguous fashion as shown-
Disadvantages
o Number of tables and the amount of processor overhead for handling page
interrupts are greater than in the case of the simple paged management
techniques.
11.Explain concept of Virtual Memory with Diagram
Virtual memory is the separation of user logical memory from physicalmemory.
This separation allows an extremely large virtual memory to beprovided for
programmers when only a smaller physical memory is available.
Virtual memory makes the task of programming much easier, because theprogrammer
no longer needs to worry about the amount of physical memoryavailable for execution
of program.
It is the process of increasing the apparentsize of a computer's RAM by using a section
of the hard disk storage as anextension of RAM.
As computers have RAM of capacity 64 or 128 MB to be usedby the CPU resources
which is not sufficient to run all applications that are usedby most users in their
expected way and all at once.
Example:
Consider, an e-mail program, a web browser and a word processor is loadedinto RAM
simultaneously; the 64 MB space is not enough to store all theseprograms.
Without a virtual memory, a message “You cannot load any moreapplications. Please
close an application to load a new one.” would bedisplayed.
By using a virtual memory, a computer can look for empty areas ofRAM which is not
being used currently and copies them on to the hard diskdevice.
Thus RAM is freed to load new applications.
Actually it is doneautomatically, the user do not even know that it is happening, and
the userfeels like RAM has unlimited space even though the RAM capacity is 32 MB.
Itis a process of increasing computer’s RAM by using a section of the hard diskstorage
as an extension of RAM.
OR
13.Explain swapping in operating system with diagram and example.
Swapping:A process must be in the main memory so that it can execute.
Swapping is a memory/process management technique used by the operating system
to increase the utilization of the processor.
A process in execution may go into blocked state due to expiry of time
quantum,occurance of interrupt,etc. when a process is in blocked state and next
process is waiting for execution then operating system performs swapping.
Swapping is a process of moving blocked process from the main memory to the
backing store and new process from backing store to main memory.
Swapping forms a queue of temporarily suspended process and the execution
continues with the newly arrived process.
In the above diagram, two processes P1 and P2 are shown.
A process P1 is in main memory and in blocked state.
Process P2 is in backing store waiting for its turn to execute.
As P1 is blocked, operating system swap out this process by moving it from main
memory to backing store and swap in process P2 by loading it from backing store to
main memory.
This process of swap out and swap in is called as swapping of processes.
Example:Consider three processes P1,P2 and P3 are in memory.
A Round-Robin CPU scheduling algorithm is in use.
A process P1 starts its execution.
When a time quantum expires memory manager swaps out the process P1 and swaps
in process P2.
If P1 requires more time than the time quantum then it is added to blocked queue and
waits for its turn for execution.
Once a time quantum of P2 expires ,manager swaps out it and swaps in P3.
when time quantum of P3 expires, manager swaps out it and swaps in P1.
This cycle of swap out and swap in continues till all the processes completes their
execution.
A good page replacement algorithm is one that minimizes the number of page faults.
NOTE
Only frame is used for page replacement during entire procedure after all the frames get
occupied.
Solution-
Total number of references = 10
From here,
Total number of page faults occurred = 6
Alternatively,
Miss ratio
= 1 – Hit ratio
= 1 – 0.4
= 0.6 or 60%
Problem-02:
A system uses 3 page frames for storing process pages in main memory.
It uses the Least Recently Used (LRU) page replacement policy.
Assume that all the page frames are initially empty.
What is the total number of page faults that will occur while processing the page
reference string given below-
4 , 7, 6, 1, 7, 6, 1, 2, 7, 2
Also calculate the hit ratio and miss ratio.
Solution-
Total number of references = 10
From here,
Total number of page faults occurred = 6
Problem-03:
A system uses 3 page frames for storing process pages in main memory.
It uses the Optimal page replacement policy. Assume that all the page frames are
initially empty.
What is the total number of page faults that will occur while processing the page
reference string given below-
4 , 7, 6, 1, 7, 6, 1, 2, 7, 2
Also calculate the hit ratio and miss ratio.
Solution-
Total number of references = 10
From here,
Total number of page faults occurred = 5
Q. Explain FIFO (First in First out) page replacement algorithm for reference string
7012030423103.
First-In-First-Out (FIFO) Algorithm: A FIFO replacement associates with each page
thetime when that page was bought into memory.
When the page must be replaced, the oldestpage is chosen.
It maintains a FIFO queue to hold all pages in memory.
We replace the page at the head of the queue.
When a page is brought into the memory, we insert it at thetail of the queue.
Reference string: Consider three frames are available.
Page fault 11
Page hit 2