Ios Unit 3
Ios Unit 3
The main idea behind the paging is to divide each process in the form of pages. The main
memory will also be divided in the form of frames.
One page of the process is to be stored in one of the frames of the memory. The pages
can be stored at the different locations of the memory but the priority is always to find the
contiguous frames or holes.
Pages of the process are brought into the main memory only when they are required
otherwise they reside in the secondary storage.
Different operating system defines different frame sizes. The sizes of each frame must
be equal. Considering the fact that the pages are mapped to the frames in Paging, page
size needs to be as same as frame size.
Example
Let us consider the main memory size 16 Kb and Frame size is 1 KB therefore the main
memory will be divided into the collection of 16 frames of 1 KB each.
There are 4 processes in the system that is P1, P2, P3 and P4 of 4 KB each. Each process
is divided into pages of 1 KB each so that one page can be stored in one frame.
Initially, all the frames are empty therefore pages of the processes will get stored in the
contiguous way.
Frames, pages and the mapping between the two is shown in the image below.
Let us consider that, P2 and P4 are moved to waiting state after some time. Now, 8 frames
become empty and therefore other pages can be loaded in that empty place. The process
P5 of size 8 KB (8 pages) is waiting inside the ready queue.
Given the fact that, we have 8 non contiguous frames available in the memory and paging
provides the flexibility of storing the process at the different places. Therefore, we can
load the pages of process P5 in the place of P2 and P4.
Memory Management Unit
The purpose of Memory Management Unit (MMU) is to convert the logical address into
the physical address. The logical address is the address generated by the CPU for every
page while the physical address is the actual address of the frame where each page will
be stored.
When a page is to be accessed by the CPU by using the logical address, the operating
system needs to obtain the physical address to access that page physically.
1. Page Number
2. Offset
Memory management unit of OS needs to convert the page number to the frame number.
Example
Considering the above image, let's say that the CPU demands 10th word of 4th page of
process P3. Since the page number 4 of process P1 gets stored at frame number 9
therefore the 10th word of 9th frame will be returned as the physical address.
The details about each segment are stored in a table called a segment table. Segment
table is stored in one (or many) of the segments.
Till now, we were using Paging as our main memory management technique. Paging is
more close to the Operating system rather than the User. It divides all the processes into
the form of pages regardless of the fact that a process can have some relative parts of
functions which need to be loaded in the same page.
Operating system doesn't care about the User's view of the process. It may divide the
same function into different pages and those pages may or may not be loaded at the
same time into the memory. It decreases the efficiency of the system.
It is better to have segmentation which divides the process into the segments. Each
segment contains the same type of functions such as the main function can be included
in one segment and the library functions can be included in the other segment.
Translation of Logical address into physical address by segment table
1. Segment Number
2. Offset
For Example:
Suppose a 16 bit address is used with 4 bits for the segment number and 12 bits for the
segment offset so the maximum segment size is 4096 and the maximum number of
segments that can be refereed is 16.
When a program is loaded into memory, the segmentation system tries to locate space
that is large enough to hold the first segment of the process, space information is obtained
from the free list maintained by memory manager. Then it tries to locate space for other
segments. Once adequate space is located for all the segments, it loads them into their
respective areas.
The operating system also generates a segment map table for each program.
With the help of segment map tables and hardware assistance, the operating system can
easily translate a logical address into physical address on execution of a program.
The Segment number is mapped to the segment table. The limit of the respective
segment is compared with the offset. If the offset is less than the limit then the address is
valid otherwise it throws an error as the address is invalid.
In the case of valid addresses, the base address of the segment is added to the offset to
get the physical address of the actual word in the main memory.
The above figure shows how address translation is done in case of segmentation.
In the fixed partition scheme, memory is divided into fixed number of partitions. Fixed
means number of partitions are fixed in the memory. In the fixed partition, in every
partition only one process will be accommodated. Degree of multi-programming is
restricted by number of partitions in the memory. Maximum size of the process is
restricted by maximum size of the partition. Every partition is associated with the limit
registers.
In the variable partition scheme, initially memory will be single continuous free block.
Whenever the request by the process arrives, accordingly partition will be made in the
memory. If the smaller processes keep on coming then the larger partitions will be made
into smaller partitions.
• In variable partition schema initially, the memory will be full contiguous free block
• Memory divided into partitions according to the process size where process size
will vary.
• One partition is allocated to each active partition.
1. Compaction
Moving all the processes toward the top or towards the bottom to make free available
memory in a single continuous place is called compaction. Compaction is undesirable
to implement because it interrupts all the running processes in the memory.
Disadvantage of Compaction
• Page fault can occur.
• It consumes CPU time (overhead).
1. Physical address space: Main memory (physical memory) is divided into blocks
of the same size called frames. frame size is defined by the operating system by
comparing it with the size of the process.
2. Logical Address space: Logical memory is divided into blocks of the same size
called process pages. page size is defined by hardware system and these pages
are stored in the main memory during the process in non-contiguous frames.