Module 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Memory Management

In a multiprogramming computer, the Operating System resides in a part of memory,


and the rest is used by multiple processes. The task of subdividing the memory
among different processes is called Memory Management. Memory management is
a method in the operating system to manage operations between main memory and
disk during process execution. The main aim of memory management is to achieve
efficient utilization of memory.

Logical and Physical Address Space

 Logical Address Space: An address generated by the CPU is known as a


“Logical Address”. It is also known as a Virtual address. Logical address
space can be defined as the size of the process. A logical address can be
changed.

 Physical Address Space: An address seen by the memory unit (i.e the one
loaded into the memory address register of the memory) is commonly known
as a “Physical Address”. A Physical address is also known as a Real address.
The set of all physical addresses corresponding to these logical addresses is
known as Physical address space. A physical address is computed by MMU.
The run-time mapping from virtual to physical addresses is done by a
hardware device Memory Management Unit(MMU). The physical address
always remains constant.

Contiguous Allocation
Single Partition
In the Contiguous Memory Allocation, each process is contained in a single contiguous
section of memory. In this memory allocation, all the available memory space remains
together in one place which implies that the freely available memory partitions are not
spread over here and there across the whole memory space.

Multiple Partition
The memory can be divided either in the fixed-sized partition or in the variable-sized
partition in order to allocate contiguous space to user processes.

Fixed-size Partition

This technique is also known as Static partitioning. In this scheme, the system
divides the memory into fixed-size partitions. The partitions may or may not be the
same size. The size of each partition is fixed as indicated by the name of the
technique and it cannot be changed.

In this partition scheme, each partition may contain exactly one process. There is a
problem that this technique will limit the degree of multiprogramming because the
number of partitions will basically decide the number of processes.

This technique is also known as Static partitioning. In this scheme, the system
divides the memory into fixed-size partitions. The partitions may or may not be the
same size. The size of each partition is fixed as indicated by the name of the
technique and it cannot be changed.

In this partition scheme, each partition may contain exactly one process. There is a
problem that this technique will limit the degree of multiprogramming because the
number of partitions will basically decide the number of processes.

Advantages of Fixed-size Partition Scheme

 This scheme is simple and is easy to implement


 It supports multiprogramming as multiple processes can be stored inside the
main memory.
 Management is easy using this scheme

Disadvantages

 Internal Fragmentation

Suppose the size of the process is lesser than the size of the partition in that case
some size of the partition gets wasted and remains unused. This wastage inside the
memory is generally termed as Internal fragmentation

Variable-size

This scheme is also known as Dynamic partitioning. The size of the partition is not
declared initially. Whenever any process arrives, a partition of size equal to the size
of the process is created and then allocated to the process. Thus the size of each
partition is equal to the size of the process.

Advantages of Variable-size Partition

No Internal Fragmentation
As in this partition scheme space in the main memory is allocated strictly according
to the requirement of the process thus there is no chance of internal fragmentation.
Also, there will be no unused space left in the partition.

Degree of Multiprogramming is Dynamic


As there is no internal fragmentation in this partition scheme due to which there is
no unused space in the memory. Thus more processes can be loaded into the
memory at the same time.

No Limitation on the Size of Process


In this partition scheme as the partition is allocated to the process dynamically thus
the size of the
Disadvantages of Variable-size Partition

External Fragmentation
As there is no internal fragmentation which is an advantage of using this partition
scheme does not mean there will no external fragmentation. Let us understand this
with the help of an example: In the above diagram- process P1(3MB) and process
P3(8MB) completed their execution. Hence there are two spaces left i.e. 3MB and
8MB. Let’s there is a Process P4 of size 15 MB comes. But the empty space in
memory cannot be allocated as no spanning is allowed in contiguous allocation.
Because the rule says that process must be continuously present in the main
memory in order to get executed. Thus it results in External Fragmentation.

How to satisfy a request of size n from a list of free holes. There are some solutions
to this problem:

First Fit

In the First Fit, the first available free hole fulfil the requirement of the process
allocated.

Best Fit

In the Best Fit, allocate the smallest hole that is big enough to process requirements.
For this, we search the entire list, unless the list is ordered by size.

Worst Fit

In the Worst Fit, allocate the largest available hole to process. This method produces
the largest leftover hole.

non-contiguous memory
An operating system's non-contiguous memory allocation allows a process to get
several memory blocks in different locations throughout memory. The methods used
to make a process's physical address space non-contiguous are paging and
segmentation. Non-contiguous memory allocation divides the process into blocks
(or pages or segments), which are subsequently allotted to different memory
locations in accordance with the quantity of free memory.

Paging

Paging is a memory management scheme that eliminates the need for a contiguous
allocation of physical memory. The process of retrieving processes in the form of
pages from the secondary storage into the main memory is known as paging.

In paging, the physical memory is divided into fixed-size blocks called page frames,
which are the same size as the pages used by the process. The process’s logical
address space is also divided into fixed-size blocks called pages, which are the same
size as the page frames. When a process requests memory, the operating system
allocates one or more page frames to the process and maps the process’s logical
pages to the physical page frames.

The mapping between logical pages and physical page frames is maintained by the
page table, which is used by the memory management unit to translate logical
addresses into physical addresses. The page table maps each logical page number
to a physical page frame number.

Address Translation Architecture!


Paging Hardware With TLB!

Translation look aside buffer (TLB)


A Translation look aside buffer can be defined as a memory cache which can be
used to reduce the time taken to access the page table again and again.

It is a memory cache which is closer to the CPU and the time taken by CPU to access
TLB is lesser then that taken to access main memory.
Segmentation

The segmentation technology is used in operating systems and the process is


divided into many pieces called segments and these segments are of variable size.
In this, segmentation uses a variable partitioning method: one segment is equal to
one complete memory block. The access and details of each segment, they are
stored in a segment table consisting of two fields. The base field gives the starting
address from which other addresses get access and the limit field returns the length
of the section.

A segment can be defined as a logical grouping of instructions such as an array.


Subroutine, function, local variable, stacks, blocks, and symbol table. Segmentation
is the technique for managing these segments.

User’s View of a Program


Address Translation Architecture!

You might also like