0% found this document useful (0 votes)
10 views23 pages

Module 3 - OS

The document discusses memory management in operating systems, including address binding, types of address binding, and the differences between logical and physical addresses. It covers contiguous memory allocation, its characteristics, advantages, and disadvantages, as well as fragmentation and virtual memory concepts like paging and segmentation. Additionally, it outlines demand paging and page replacement strategies.

Uploaded by

sajeedsarmad2
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)
10 views23 pages

Module 3 - OS

The document discusses memory management in operating systems, including address binding, types of address binding, and the differences between logical and physical addresses. It covers contiguous memory allocation, its characteristics, advantages, and disadvantages, as well as fragmentation and virtual memory concepts like paging and segmentation. Additionally, it outlines demand paging and page replacement strategies.

Uploaded by

sajeedsarmad2
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

MODULE 3

● Memory management is the functionality of an operating system which handles or


manages primary memory and moves processes back and forth between main memory
and disk during execution.
● Memory management keeps track of each and every memory location, regardless of
either it is allocated to some process or it is free.
● It checks how much memory is to be allocated to processes.
● It decides which process will get memory at what time.
● It tracks whenever some memory gets freed or unallocated and correspondingly it
updates the status.

What is address binding in the operating system?


The Address Binding refers to the mapping of computer instructions and data to physical
memory locations. Both logical and physical addresses are used in computer memory. It assigns
a physical memory region to a logical pointer by mapping a physical address to a logical
address known as a virtual address. It is also a component of computer memory management
that the OS performs on behalf of applications that require memory access.

Types of Address Binding in Operating System


There are mainly three types of an address binding in the OS. These are as follows:

1. Compile Time Address Binding


2. Load Time Address Binding
3. Execution Time or Dynamic Address Binding

Compile Time Address Binding


It is the first type of address binding. It occurs when the compiler is responsible for performing
address binding, and the compiler interacts with the operating system to perform the address
binding. In other words, when a program is executed, it allocates memory to the system code of
the computer. The address binding assigns a logical address to the beginning of the memory
segment to store the object code. Memory allocation is a long-term process and may only be
modified by recompiling the program.

Load Time Address Binding

It is another type of address binding. It is done after loading the program in the memory, and it
would be done by the operating system memory manager, i.e., loader. If memory allocation is
specified when the program is assigned, no program in its compiled state may ever be
transferred from one computer to another. Memory allocations in the executable code may
already be in use by another program on the new system. In this case, the logical addresses of
the program are not connected to physical addresses until it is applied and loaded into memory.

Execution Time or Dynamic Address Binding

Execution time address binding is the most popular type of binding for scripts that aren't
compiled because it only applies to variables in the program. When a variable in a program is
encountered during the processing of instructions in a script, the program seeks memory space
for that variable. The memory would assign the space to that variable until the program
sequence finished or unless a specific instruction within the script released the memory address
connected to a variable.

Logical and Physical Address


In computers, an address is used to identify a location in the computer memory. In operating
systems, there are two types of addresses, namely, logical address and physical address. A
logical address is the virtual address that is generated by the CPU. A user can view the logical
address of a computer program. On the other hand, a physical address is one that represents a
location in the computer memory. A user cannot view the physical address of a program.

Read this article to find out more about logical and physical address and how they are different
from each other.

What is a Logical Address?


The logical address is a virtual address created by the CPU of the computer system. The
logical address of a program is generated when the program is running. A group of several
logical address is referred to a logical address space. The logical address is basically used as
a reference to access the physical memory locations.

In computer systems, a hardware device named memory management unit (MMU) is used to
map the logical address to its corresponding physical address. However, the logical address of
a program is visible to the computer user.

What is a Physical Address?


The physical address of a computer program is one that represents a location in the memory
unit of the computer. The physical address is not visible to the computer user. The MMU of the
system generates the physical address for the corresponding logical address.
The physical address is accessed through the corresponding logical address because a user
cannot directly access the physical address. For running a computer program, it requires a
physical memory space. Therefore, the logical address has to be mapped with the physical
address before the execution of the program.

Difference between Logical and Physical Address in


Operating System
The following table highlights all the major differences between logical and physical address in
operating system −

contiguous memory allocation

Contiguous memory allocation is a memory management technique used by operating systems


to allocate memory to processes in contiguous blocks. In this technique, a process is allocated a
single block of memory that is contiguous or adjacent to each other. This ensures that memory
is efficiently utilized, with minimal fragmentation and wasted memory. Contiguous memory
allocation is a widely used technique in modern operating systems and has several advantages,
including efficient memory utilization, fast access to memory, and simple management.
However, it also has some limitations, such as the possibility of external fragmentation, large
block requirements, and fixed block size limitations. Despite its limitations, contiguous memory
allocation remains an important and widely used technique in modern operating systems.
Definition of contiguous memory allocation
Continuous memory allocation is a memory management technique in which memory is
allocated to processes in contiguous blocks. This ensures that memory is utilized efficiently, with
minimal fragmentation and wasted memory. The technique simplifies memory management by
allowing the operating system to manage memory in larger blocks, leading to faster access to
memory and improved system performance. Overall, continuous memory allocation is an
important technique used by operating systems to efficiently manage memory resources and
ensure that memory is effectively utilized.

Purpose of memory management techniques

The purpose of contiguous memory allocation in operating systems is to efficiently manage the
memory resources available on a computer system. By allocating memory to processes in
contiguous blocks, this technique ensures that the memory is utilized efficiently, with minimal
fragmentation and wasted memory. This results in faster access to memory, as contiguous
blocks of memory can be accessed more quickly than non-contiguous blocks.

Additionally, contiguous memory allocation simplifies memory management by allowing the


operating system to manage memory in larger blocks rather than small, fragmented pieces. This
reduces the overhead associated with managing multiple memory blocks, leading to faster
system performance.

Overall, the purpose of contiguous memory allocation is to ensure that memory is efficiently
utilized and effectively managed, resulting in improved system performance and faster access to
memory. This is particularly important for applications with high memory requirements, such as
multimedia editing and gaming, and for systems with a small number of processes that require
fast access to memory.

Characteristics of Contiguous Memory Allocation


Contiguous memory allocation is a memory management technique that divides memory into
contiguous blocks, where each block is assigned to a single process. Here are some of the
characteristics of contiguous memory allocation −

Contiguous blocks: Memory is divided into contiguous blocks, with each block being assigned to
a single process. This means that the memory allocated to a process is a single, contiguous
block of memory.
● Efficient use of memory − Contiguous memory allocation is efficient in terms of memory
utilization, as there is no internal fragmentation within a process's allocated memory
block.
● Easy to manage − Contiguous memory allocation is easy to manage, as the operating
system can quickly allocate and deallocate memory to processes by assigning
contiguous blocks.
● External fragmentation − One of the main drawbacks of contiguous memory allocation is
external fragmentation, which occurs when small gaps of free memory are scattered
throughout the memory space. Over time, these small gaps can accumulate and result in
larger portions of memory becoming unusable, even though the total amount of free
memory may be sufficient to satisfy a request for memory.
● Compaction − To address external fragmentation, operating systems may use
techniques such as compaction, where the operating system rearranges memory blocks
to eliminate gaps and consolidate free memory into larger contiguous blocks.

Overall, contiguous memory allocation is an efficient and easy-to-manage memory management


technique, but it may suffer from external fragmentation over time. Operating systems may use
various techniques to reduce external fragmentation and ensure that memory is utilized
effectively.

Advantages of Contiguous Memory Allocation

● Efficient memory utilization − Contiguous memory allocation is efficient in terms of


memory utilization, as there is no internal fragmentation within a process's allocated
memory block.
● Simple and easy to manage − This technique is simple and easy to manage, as the
operating system can quickly allocate and deallocate memory to processes by assigning
contiguous blocks.
● Fast access − Since the memory is allocated in contiguous blocks, access to the
memory is faster than other memory management techniques.

Disadvantages of Contiguous Memory Allocation

● External Fragmentation − One of the main disadvantages of contiguous memory


allocation is external fragmentation, which occurs when small gaps of free memory are
scattered throughout the memory space.
● Limited memory capacity − Contiguous memory allocation is limited by the size of the
memory blocks available on the system, which may limit the total amount of memory that
can be allocated to a process.
● Difficulty in sharing memory − This technique makes it difficult to share memory between
multiple processes, as each process is assigned a contiguous block of memory that
cannot be shared with other processes.
● Lack of flexibility − Contiguous memory allocation lacks flexibility in allocating and
deallocating memory, as the operating system can only allocate memory in contiguous
blocks.

Difference between Fixed Partitioning


and Variable Partitioning

1. Fixed Partitioning :
Multi-programming with fixed partitioning is a contiguous memory management technique in
which the main memory is divided into fixed sized partitions which can be of equal or unequal
size. Whenever we have to allocate a process memory then a free partition that is big enough to
hold the process is found. Then the memory is allocated to the [Link] there is no free space
available then the process waits in the queue to be allocated memory. It is one of the most
oldest memory management technique which is easy to implement.

2. Variable Partitioning :
Multi-programming with variable partitioning is a contiguous memory management technique in
which the main memory is not divided into partitions and the process is allocated a chunk of free
memory that is big enough for it to fit. The space which is left is considered as the free space
which can be further used by other processes. It also provides the concept of compaction. In
compaction the spaces that are free and the spaces which not allocated to the process are
combined and single large memory space is made.
Allocation strategies
In Partition Allocation, when there is more than one partition freely available to accommodate a
process’s request, a partition must be selected. To choose a particular partition, a partition
allocation method is needed. A partition allocation method is considered better if it avoids
internal fragmentation.

When it is time to load a process into the main memory and if there is more than one free block
of memory of sufficient size then the OS decides which free block to allocate.

There are different Placement Algorithm:

A. First Fit

B. Best Fit

C. Worst Fit

1. First Fit: In the first fit, the partition is allocated which is the first sufficient block from the top of
Main Memory. It scans memory from the beginning and chooses the first available block that is
large enough. Thus it allocates the first hole that is large enough.
2. Best Fit Allocate the process to the partition which is the first smallest sufficient
partition among the free available partition. It searches the entire list of holes to find the
smallest hole whose size is greater than or equal to the size of the process.

3. Worst Fit Allocate the process to the partition which is the largest sufficient among the
freely available partitions available in the main memory. It is opposite to the best-fit
algorithm. It searches the entire list of holes to find the largest hole and allocate it to
process.
Fragmentation
As processes are loaded and removed from memory, the free memory space is
broken in to 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 called fragmentation.

• Two types of fragmentations are

1. External fragmentation

2. Internal fragmentation

EXTERNAL FRAGMENTATION

• External fragmentation is the unused area between two used areas.

It is a serious problem. Here memory space to satisfy a request is available, but


is not contiguous.
Memory compaction

• External fragmentation can be reduced using memory compaction. In


memory compaction, we move the used space in upper memory or in
lower memory. That is used space is moved in one place and unused
are collected in another place

INTERNAL FRAGMENTATION
• Consider the following figure. Suppose a 6K request is coming, then 8K is fully
allocated because it is a fixed partition.

Here 2k is wasted.
• That is the wasted space contained in a partition that is allocated for a request
is called internal fragmentation.

• It is a wasted space with in a partition.

• Internal fragmentation can be reduced effectively assigning the smallest


partition but large enough for the process.

VIRTUAL MEMORY

● A computer can address more memory than the amount of


● physically installed on the system.
● This extra memory is actually called virtual memory and it is
a section of hard disk that has set up to emulate the
computers RAM.
● Virtual memory is implemented using secondary storage to
augment the main memory.
● Programs can be larger than the physical memory. Instead
of holding the entire program , main memory hold only a
portion of the program which is currently being executed.
● Virtual Memory enhances the CPU utilization and through
put by executing as many programs as possible,
simultaneously.
● Virtual memory serves two purposes:
● First it allows us to extend the use of physical memory by
using Disk
● Second , it allows us to have memory protection, because
each virtual address is translated to a physical address. •
● Two most common methods of implementing virtual storage
are Paging and Segmentation.

PAGING
• Paging is a memory management technique.

• In this approach, physical memory is divided into fixed


sized block called frames and logical memory is also
divided in to the fixed sized blocks called pages.

• The size of the page is same as that of frame.

• The key idea of this method is to place the pages of a


process into the available frames of memory , whenever
this process is to be executed.
ADDRESS TRANSLATION

● It is done by mapping. Logical address is mapped to physical


address using a page table
● Every address generated by the CPU is divided into two parts
page number (p) and page offset.
● Physical address is represented by two parts Frame number(f)
and page offset(d).
● The page number is used as an index into a page table.
● The page table contains the base address of each page in
physical memory.
● This base address is combined with the page offset to define the
physical memory address that is sent to the memory unit.
Fig: Paging hardware

SEGMENTATION

• Segmentation is a memory-management scheme that supports

this programmer view of memory.

• Here each job is divided into several segments of different sizes.

• Segments are variable size.

• So each segment has a base and limit.

• Limit is provided for avoiding segment overlapping.

• A program segment contains the program’s main function, utility

functions, data structures and so on.


● A segment table is provided. Each entry of the segment table
has a segment base and a segment limit.
● Segment base contains the starting physical address where the
segment resides in memory, whereas segment limit specifies the
length of the segment.
● A logical address consists of two parts: a segment number s,
and an offset into that segment d.
● The segment number is used as an index to the segment table.
The offset d of the logical address must be between 0 and the
segment limit. If it is not, we trap the operating system.
● When an offset is legal, it is added to the segment base to
produce the address in physical memory of the desired byte.
● The segment table is thus essentially an array of base–limit
register pairs
DEMAND PAGING

• A demand-paging system is similar to a paging system with

swapping where processes reside in secondary memory (usually a

disk).

• When we want to execute a process, we swap it into memory.

• Any page execution is started on a page fault.


• In demand paging firstly no programs are in memory.

• When CPU generate an address, a page fault will occur. When a

page fault occurs, we can load the entire program in to main

memory or we can load only the needed program.

● A lazy swapper never swaps a page into memory unless that


page will be needed.
● A swapper manipulates entire processes, whereas a pager is
concerned with the individual pages of a process.
● We thus use “pager,” rather than “swapper,” in connection with

demand paging.

PAGE REPLACEMENT

• Page replacement takes the following approach.

1. Find the location of the desired page on the disk.

2. Find a free frame:


a. If there is a free frame, use it.

b. If there is no free frame, use a page-replacement algorithm to

select a victim frame.

c . Write the victim frame to the disk; change the page and
frame tables accordingly.

3. Read the desired page into the newly freed frame; change the
page and frame tables.

4. Continue the user process from where the page fault


occurred.
PAGE REPLACEMENT ALGORITHM

• Hit = 5, Page fault=15 , Hit ratio= 5/(15+5) = 5/20

• Simplest page replacement algorithm

• When a page wants to be replaced, the oldest page will be chosen


2. Optimal Replacement algorithm

● Optimal page replacement algorithm has the lowest page fault


rate of all algorithms, and will never suffer from Belady’s
anomaly.
● It is simply, replace the page that will not be used for the longest
[Link] (Least Recently Used) Page Replacement

• LRU chooses the page that has not been used for the

longest period of time.

• This strategy looking backward in time rather than forward.

You might also like