0% found this document useful (0 votes)
56 views10 pages

Ios Unit 3

Uploaded by

kanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views10 pages

Ios Unit 3

Uploaded by

kanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

Paging in OS (Operating System):


In Operating Systems, Paging is a storage mechanism used to retrieve processes from
the secondary storage into the main memory in the form of pages.

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.

The logical address has two parts.

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.

2. Segmentation in OS (Operating System):


In Operating Systems, Segmentation is a memory management technique in which the
memory is divided into the variable size parts. Each part is known as a segment which
can be allocated to a process.

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.

Segment table contains mainly two information about segment:

1. Base: It is the base address of the segment


2. Limit: It is the length of the segment.

Why Segmentation is required?

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

CPU generates a logical address which contains two parts:

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.

Types of Segmentation in Operating Systems


• Virtual Memory Segmentation: Each process is divided into a number of
segments, but the segmentation is not done all at once. This segmentation may or
may not take place at the run time of the program.
• Simple Segmentation: Each process is divided into a number of segments, all of
which are loaded into memory at run time, though not necessarily contiguously.

Translation of Two-dimensional Logical Address to Dimensional Physical Address:


3. What is Contiguous Memory Management?:

Contiguous memory allocation is a memory allocation strategy. As the name implies,


we utilize this technique to assign contiguous blocks of memory to each task. Thus,
whenever a process asks to access the main memory, we allocate a continuous
segment from the empty region to the process based on its size. In this technique,
memory is allotted in a continuous way to the processes.

Contiguous Memory Management has two types:


• Fixed(or Static) Partition
• Variable(or Dynamic) Partitioning

Contiguous Memory Management Techniques:


Below are two Contiguous Memory Management Techniques. Lets understand these in
detail.

1. Fixed Partition Scheme:

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.

• Limit Registers: It has two limit:


• Lower Limit: Starting address of the partition.
• Upper Limit: Ending address of the partition.

Internal Fragmentation is found in fixed partition scheme. To overcome the problem of


internal fragmentation, instead of fixed partition scheme, variable partition scheme is
used.

Disadvantages Fix partition scheme


• Maximum process size <= Maximum partition size.
• The degree of multiprogramming is directly proportional to the number of partitions.
• Internal fragmentation which is discussed above is present.
• If a process of 19kb wants to allocate and we have free space which is not
continuous we are not able to allocate the space.

2. Variable Partition Scheme:

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.

External Fragmentation is found in variable partition scheme. To overcome the problem


of external fragmentation, compaction technique is used or non-contiguous memory
management techniques are used.

Solution of External Fragmentation:

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).

2. Non-contiguous memory allocation:

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.

You might also like