0% found this document useful (0 votes)
65 views

Os - Memory Management in Operating System

Memory management in operating systems deals with controlling and managing the primary memory of a computer system. It tracks available and allocated memory and moves processes between primary and secondary memory. Key techniques for memory management include segmentation, paging, and swapping. Segmentation divides memory into variable sized blocks called segments. Paging breaks processes into fixed sized blocks called pages. Swapping moves pages between primary and secondary storage. These techniques help optimize memory usage and allow running processes larger than available primary memory.

Uploaded by

luckysighania93
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Os - Memory Management in Operating System

Memory management in operating systems deals with controlling and managing the primary memory of a computer system. It tracks available and allocated memory and moves processes between primary and secondary memory. Key techniques for memory management include segmentation, paging, and swapping. Segmentation divides memory into variable sized blocks called segments. Paging breaks processes into fixed sized blocks called pages. Swapping moves pages between primary and secondary storage. These techniques help optimize memory usage and allow running processes larger than available primary memory.

Uploaded by

luckysighania93
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Memory Management in Operating System

Overview

Memory management is an essential component in operating systems. It


deals with the usage of the primary memory of the computer system. Its
purpose is to move processes between primary memory
(R.A.M.) and secondary memory (R.O.M.). Most of the operating systems
these days make us of memory management. It increases the efficiency
and performance of the operating system.

What is Memory Management in an Operating System?

Memory management in OS is a technique of controlling and managing the


functionality of Random access memory (primary memory). It is used for
achieving better concurrency, system performance, and memory utilization.

Memory management moves processes from primary memory to


secondary memory and vice versa. It also keeps track of available memory,
memory allocation, and unallocated.

Why use Memory Management in OS?

 Memory management keeps track of the status of each memory


location, whether it is allocated or free.
 Memory management enables computer systems to run programs
that require more main memory than the amount of free main
memory available on the system. This is achieved by moving data
between primary and secondary memory.
 Memory management addresses the system’s primary memory by
providing abstractions such that the programs running on the system
perceive a large memory is allocated to them.
 It is the job of memory management to protect the memory allocated
to all the processes from being corrupted by other processes. If this is
not done, the computer may exhibit unexpected/faulty behavior.
 Memory management enables sharing of memory spaces among
processes, with the help of which, multiple programs can reside at the
same memory location (although only one at a time).
What is Paging?

A computer system can address and utilize more memory than the size of
the memory present in the computer hardware. This extra memory is
referred to as virtual memory. Virtual memory is a part of secondary
memory that the computer system uses as primary memory. Paging has a
vital role in the implementation of virtual memory.

The process address space is a set of logical addresses that every process
refers to in its code. Paging is a technique of memory management in
which the process address space is broken into blocks. All the blocks are of
the same size and are referred to as “pages”. The size of a page is a power
of 2 and its value is in the range of 512 bytes to 8192 bytes. The size of a
process is measured in terms of the number of pages.

A similar division of the main memory is done into blocks of fixed size.
These blocks are known as “frames” and the size of a frame is the same as
that of a page to achieve optimum usage of the primary memory and for
avoiding external fragmentation.

Following are some Advantages of Paging:

 Paging decreases external fragmentation.


 Paging is easy to implement.
 Paging adds to memory efficiency.
 Since the size of the frames is the same as that of pages, - swapping
becomes quite simple.
 Paging is useful for fast accessing data.

What is Fragmentation?

When processes are moved to and from the main memory, the available
free space in primary memory is broken into smaller pieces. This happens
when memory cannot be allocated to processes because the size of
available memory is less than the amount of memory that the process
requires. Such blocks of memory stay unused. This issue is called
fragmentation.
Fragmentation is of the following two types:

1. External Fragmentation:

The total amount of free available primary is sufficient to reside a process,


but can not be used because it is non-contiguous. External fragmentation
can be decreased by compaction or shuffling of data in memory to arrange
all free memory blocks together and thus form one larger free memory
block.

2. Internal Fragmentation:

Internal fragmentation occurs when the memory block assigned to the


process is larger than the amount o memory required by the process. In
such a situation a part of memory is left unutilized because it will not be
used by any other process. Internal fragmentation can be decreased by
assigning the smallest partition of free memory that is large enough for
allocating to a process.

Operating System Memory Management Techniques

Following are the three major memory management techniques used in


operating systems:

1. Segmentation

Segmentation is a method of dividing the primary memory into multiple


blocks. Each block is called a segment and has a specific length. Every
segment has a starting address referred to as its base address. The length
of a segment determines the amount of free memory available in the
segment.

The location of any data items stored in the segment can be determined by
the distance of the actual position of the data item from the base address of
the segment. This distance is called an offset or displacement value.
Simply put, when data is to be obtained from a segment, then the actual
address of data is computed as the sum of the base address of the
segment and the offset value.
The offset value and the base address of a segment are both specified in a
program instruction itself.

2. Paging

Explained earlier

3. Swapping

Swapping is a technique used in an operating system for efficient


management of the memory of the computer system. Swapping includes
two tasks, swapping in, and swapping out. Swapping in means placing the
blocks or pages of data from the secondary memory to the primary
memory. Swapping out is removing blocks/pages of data from the main
memory to the Read-Only Memory (R.O.M.). Swapping is useful when a
large program has to be executed or some operation has to be performed
on a large file.

Conclusion

 Memory management in OS is a technique of managing the


functionality of primary memory, used for achieving better
concurrency, system performance, and memory utilization.
 Memory management keeps track of the status of each memory
location, whether it is allocated or free.
 Paging is a technique of memory management in which the process
address space is broken into blocks. All the blocks are of the same
size and are referred to as “pages”.
 Fragmentation are of two kinds, external and internal.
 Segmentation is the method of dividing the primary memory into
multiple blocks. Each block is called a segment and has a specific
length.
 Swapping includes two tasks, swapping in, and swapping out.
Memory Management in Operating System (OS)

In this article, we will understand memory management in detail.

What do you mean by memory management?

Memory is the important part of the computer that is used to store the data.
Its management is critical to the computer system because the amount of
main memory available in a computer system is very limited. At any time,
many processes are competing for it. Moreover, to increase performance,
several processes are executed simultaneously. For this, we must keep
several processes in the main memory, so it is even more important to
manage them effectively.

Role of Memory management

Following are the important roles of memory management in a computer


system:

o Memory manager is used to keep track of the status of memory


locations, whether it is free or allocated. It addresses primary memory
by providing abstractions so that software perceives a large memory
is allocated to it.
o Memory manager permits computers with a small amount of main
memory to execute programs larger than the size or amount of
available memory. It does this by moving information back and forth
between primary memory and secondary memory by using the
concept of swapping.
o The memory manager is responsible for protecting the memory
allocated to each process from being corrupted by another process. If
this is not ensured, then the system may exhibit unpredictable
behavior.
o Memory managers should enable sharing of memory space between
processes. Thus, two programs can reside at the same memory
location although at different times.

Memory Management Techniques:

The memory management techniques can be classified into following


main categories:

o Contiguous memory management schemes


o Non-Contiguous memory management schemes

Contiguous memory management schemes:


In a Contiguous memory management scheme, each program occupies a
single contiguous block of storage locations, i.e., a set of memory locations
with consecutive addresses.

Single contiguous memory management schemes:

The Single contiguous memory management scheme is the simplest


memory management scheme used in the earliest generation of computer
systems. In this scheme, the main memory is divided into two contiguous
areas or partitions. The operating systems reside permanently in one
partition, generally at the lower memory, and the user process is loaded
into the other partition.

Advantages of Single contiguous memory management schemes:

o Simple to implement.
o Easy to manage and design.
o In a Single contiguous memory management scheme, once a
process is loaded, it is given full processor's time, and no other
processor will interrupt it.

Disadvantages of Single contiguous memory management schemes:

o Wastage of memory space due to unused memory as the process is


unlikely to use all the available memory space.
o The CPU remains idle, waiting for the disk to load the binary image
into the main memory.
o It can not be executed if the program is too large to fit the entire
available main memory space.
o It does not support multiprogramming, i.e., it cannot handle multiple
programs simultaneously.

Multiple Partitioning:

The single Contiguous memory management scheme is inefficient as it


limits computers to execute only one program at a time resulting in wastage
in memory space and CPU time. The problem of inefficient CPU use can
be overcome using multiprogramming that allows more than one program
to run concurrently. To switch between two processes, the operating
systems need to load both processes into the main memory. The operating
system needs to divide the available main memory into multiple parts to
load multiple processes into the main memory. Thus multiple processes
can reside in the main memory simultaneously.

The multiple partitioning schemes can be of two types:

o Fixed Partitioning
o Dynamic Partitioning

Fixed Partitioning

The main memory is divided into several fixed-sized partitions in a fixed


partition memory management scheme or static partitioning. These
partitions can be of the same size or different sizes. Each partition can hold
a single process. The number of partitions determines the degree of
multiprogramming, i.e., the maximum number of processes in memory.
These partitions are made at the time of system generation and remain
fixed after that.

Advantages of Fixed Partitioning memory management schemes:

o Simple to implement.
o Easy to manage and design.

Disadvantages of Fixed Partitioning memory management schemes:

o This scheme suffers from internal fragmentation.


o The number of partitions is specified at the time of system generation.

Dynamic Partitioning

The dynamic partitioning was designed to overcome the problems of a


fixed partitioning scheme. In a dynamic partitioning scheme, each process
occupies only as much memory as they require when loaded for
processing. Requested processes are allocated memory until the entire
physical memory is exhausted or the remaining space is insufficient to hold
the requesting process. In this scheme the partitions used are of variable
size, and the number of partitions is not defined at the system generation
time.

Advantages of Dynamic Partitioning memory management schemes:

o Simple to implement.
o Easy to manage and design.

Disadvantages of Dynamic Partitioning memory management


schemes:

o This scheme also suffers from internal fragmentation.


o The number of partitions is specified at the time of system
segmentation.

Non-Contiguous memory management schemes:

In a Non-Contiguous memory management scheme, the program is divided


into different blocks and loaded at different portions of the memory that
need not necessarily be adjacent to one another. This scheme can be
classified depending upon the size of blocks and whether the blocks reside
in the main memory or not.

What is paging?

Paging is a technique that eliminates the requirements of contiguous


allocation of main memory. In this, the main memory is divided into fixed-
size blocks of physical memory called frames. The size of a frame should
be kept the same as that of a page to maximize the main memory and
avoid external fragmentation.

Advantages of paging:

o Pages reduce external fragmentation.


o Simple to implement.
o Memory efficient.
o Due to the equal size of frames, swapping becomes very easy.
o It is used for faster access of data.
What is Segmentation?

Segmentation is a technique that eliminates the requirements of contiguous


allocation of main memory. In this, the main memory is divided into
variable-size blocks of physical memory called segments. It is based on the
way the programmer follows to structure their programs. With segmented
memory allocation, each job is divided into several segments of different
sizes, one for each module. Functions, subroutines, stack, array, etc., are
examples of such modules.

You might also like