0% found this document useful (0 votes)
48 views41 pages

3.memory Management 20240103

This document discusses memory management techniques in operating systems. It covers contiguous and dynamic memory allocation schemes like fixed and variable partitioning. It also discusses logical and physical address spaces, and issues like internal and external fragmentation that can occur due to memory allocation and deallocation processes. The goal of memory management is to allocate memory efficiently between competing processes while maintaining data integrity and privacy.

Uploaded by

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

3.memory Management 20240103

This document discusses memory management techniques in operating systems. It covers contiguous and dynamic memory allocation schemes like fixed and variable partitioning. It also discusses logical and physical address spaces, and issues like internal and external fragmentation that can occur due to memory allocation and deallocation processes. The goal of memory management is to allocate memory efficiently between competing processes while maintaining data integrity and privacy.

Uploaded by

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

Memory Management

By: Suvash Chandra Gautam


January 04, 2023
Memory Management
a) Memory management without swapping
b) Swapping
c) Virtual memory
d) Paging, Page replacement algorithms (FIFO, Optimal, LRU, LFU, NRU,
Random, Clock, Second-chance)
e) Predicting page faults
f) Segmentation with paging
What is Memory Management?
• Memory management in an operating system (OS) refers to the
processes and techniques employed to handle the computer's memory
resources effectively.
• The primary goal of memory management is to provide a well-
organized and efficient way for programs to access and use the
computer's memory.
• This involves allocation, deallocation, and tracking of memory space,
ensuring that each program or process gets the required memory for
execution without interfering with other programs. Here are some key
aspects of memory management in an operating system:
Why Memory Management is Required?

• Allocate and de-allocate memory before and after process execution.


• To keep track of used memory space by processes.
• To minimize fragmentation issues.
• To proper utilization of main memory.
• To maintain data integrity while executing of process.
What is 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

• 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.
• 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.
• 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.
• 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:
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.
Single contiguous memory management schemes:
Advantages of Single contiguous memory management schemes:

• Simple to implement.
• Easy to manage and design.
• 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.
Multiple Partitioning:

• Multiple partitioning is a memory management technique where the


physical memory (RAM) is divided into several fixed-size or variable-size
partitions.
• Each partition can be assigned to a different process, allowing multiple
processes to be loaded into memory concurrently.
• This approach helps in efficient utilization of memory by
accommodating multiple processes simultaneously.
• There are two main types of multiple partitioning schemes:
1. Fixed Partitioning/Static:
2. Variable/Dynamic Partitioning:
Fixed/Static 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.
Fixed/Static Partitioning
Fixed/Static Partitioning Example
• As illustrated in above figure, first process is only consuming 1MB
out of 4MB in the main memory.
Hence, Internal Fragmentation in first block is (4-1) = 3MB.
Sum of Internal Fragmentation in every block = (4-1)+(8-7)+(8-
7)+(16-14)= 3+1+1+2 = 7MB.
• Suppose process P5 of size 7MB comes. But this process cannot be
accommodated in spite of available free space because of contiguous
allocation (as spanning is not allowed). Hence, 7MB becomes part of
External Fragmentation.
Fixed/Static Partitioning

• This is the oldest and simplest technique used to put more than one
process in the main memory.
• In this partitioning, the number of partitions (non-overlapping) in
RAM is fixed but the size of each partition may or may not be the
same.
• As it is a contiguous allocation, hence no spanning is allowed. Here
partitions are made before execution or during system configure.
Advantages
• Simple to implement.
• Easy to manage and design.
Internal and External Fragmentation
• Internal fragmentation and external fragmentation are two types of
memory wastage that can occur in a computer system due to memory
allocation and deallocation processes.
• Internal Fragmentation:
• Definition: Internal fragmentation occurs when memory is allocated in
fixed-size blocks, and the allocated memory block is larger than the
actual size of the data being stored.
• Example: Consider a system with fixed-size memory blocks of 100 units.
If a process requires 80 units of memory, it will be allocated an entire
block of 100 units. The remaining 20 units within the block are wasted
due to internal fragmentation.
Disadvantages of Fixed Partitioning –
• Internal Fragmentation:
• Main memory use is inefficient. Any program, no matter how small,
occupies an entire partition. This can cause internal fragmentation.
• External Fragmentation:
• The total unused space (as stated above) of various partitions cannot
be used to load the processes even though there is space available
but not in the contiguous form (as spanning is not allowed).
Internal and External Fragmentation
• Definition: External fragmentation occurs when free memory is
scattered in small, non-contiguous chunks throughout the system,
making it challenging to allocate a contiguous block of memory for a
process.
• Explanation: In systems with variable-size memory allocation (such as
dynamic partitioning or dynamic page allocation), memory blocks are of
varying sizes. As processes are loaded and removed, free memory
becomes fragmented into smaller pieces.
• Even if the total free memory is sufficient to accommodate a process, it
may be scattered in such a way that finding a single contiguous block
becomes difficult.
Internal and External Fragmentation
• Example: Consider a system with 300 units of free memory, divided
into three non-contiguous chunks of 100, 50, and 150 units. If a
process requires 200 units of contiguous memory, it cannot be
accommodated, leading to external fragmentation.
• Impact: External fragmentation can result in wasted memory, as free
memory may be too fragmented to be effectively utilized. This
fragmentation can also hinder the performance of memory allocation
algorithms.
Dynamic Partitioning
• Dynamic partitioning is a memory management technique where the
physical memory (RAM) is divided into variable-sized partitions to
accommodate processes with different memory requirements.
• Unlike fixed partitioning, where all partitions are of the same size,
dynamic partitioning allows the creation of partitions that match the
exact size needed by each process.
• It is a part of the Contiguous allocation technique. It is used to
alleviate the problem faced by Fixed Partitioning. In contrast with
fixed partitioning, partitions are not made before the execution or
during system configuration
Dynamic Partitioning
• Initially, RAM is empty and partitions are made during the run-time
according to the process’s need instead of partitioning during system
configuration.
• The size of the partition will be equal to the incoming process.
• The partition size varies according to the need of the process so that
internal fragmentation can be avoided to ensure efficient utilization of
RAM.
• The number of partitions in RAM is not fixed and depends on the
number of incoming processes and the Main Memory’s size.
Advantages of Variable(Dynamic) Partitioning

• No Internal Fragmentation: In variable Partitioning, space in the


main memory is allocated strictly according to the need of the process,
hence there is no case of internal fragmentation. There will be no
unused space left in the partition.
• No restriction on the Degree of Multiprogramming: More
processes can be accommodated due to the absence of internal
fragmentation. A process can be loaded until the memory is empty.
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.
Static and Dynamic Loading

• Loading a process into the main memory is done by a loader. There are two
different types of loading :
• Static Loading: Static Loading is basically loading the entire program into a
fixed address. It requires more memory space.
• Dynamic Loading: The entire program and all data of a process must be in
physical memory for the process to execute. So, the size of a process is limited to
the size of physical memory.
• To gain proper memory utilization, dynamic loading is used. In dynamic loading,
a routine is not loaded until it is called. All routines are residing on disk in
a relocatable load format. One of the advantages of dynamic loading is that the
unused routine is never loaded. This loading is useful when a large amount of
code is needed to handle it efficiently.
Swapping
• When a process is executed it must have resided in memory. Swapping is a
process of swapping a process temporarily into a secondary memory from
the main memory, which is fast compared to secondary memory.
• A swapping allows more processes to be run and can be fit into memory at
one time. The main part of swapping is transferred time and the total time is
directly proportional to the amount of memory swapped.
• Swapping is also known as roll-out, or roll because if a higher priority
process arrives and wants service, the memory manager can swap out the
lower priority process and then load and execute the higher priority process.
• After finishing higher priority work, the lower priority process swapped
back in memory and continued to the execution process.
Swap-In & Swap Out:
• Swapping has been subdivided into two concepts: swap-in and swap-
out.
• Swap-out is a technique for moving a process from RAM to the hard
disc.
• Swap-in is a method of transferring a program from a hard disc to
main memory, or RAM.
Advantages:
• If there is low main memory so some processes may has to wait for
much long but by using swapping process do not have to wait long for
execution on CPU.
• It utilize the main memory.
• Using only single main memory, multiple process can be run by CPU
using swap partition.
• The concept of virtual memory start from here and it utilize it in better
way.
• This concept can be useful in priority based scheduling to optimize the
swapping process.
Disadvantages:

• If there is low main memory resource and user is executing too many
processes and suddenly the power of system goes off there might be a
scenario where data get erase of the processes which are took parts in
swapping.
• Chances of number of page faults occur
• Low processing performance.
Virtual memory
• Virtual Memory is a storage mechanism which offers user an illusion
of having a very big main memory.
• It is done by treating a part of secondary memory as the main
memory. In Virtual memory, the user can store processes with a
bigger size than the available main memory.

• Therefore, instead of loading one long process in the main memory,


the OS loads the various parts of more than one process in the main
memory. Virtual memory is mostly implemented with demand paging
and demand segmentation.
Why Need Virtual Memory?

• Whenever your computer doesn’t have space in the physical


memory it writes what it needs to remember to the hard disk in a
swap file as virtual memory.
• If a computer running Windows needs more memory/RAM, then
installed in the system, it uses a small portion of the hard drive for
this purpose.
For example

• Let’s assume that an OS requires 300 MB of memory to store all the


running programs. However, there’s currently only 50 MB of available
physical memory stored on the RAM.
For Example

• The OS will then set up 250 MB of virtual memory and use a program
called the Virtual Memory Manager(VMM) to manage that 250 MB.
• So, in this case, the VMM will create a file on the hard disk that is 250
MB in size to store extra memory that is required.
• The OS will now proceed to address memory as it considers 300 MB
of real memory stored in the RAM, even if only 50 MB space is
available.
• It is the job of the VMM to manage 300 MB memory even if just 50 MB
of real memory space is available.
Advantages of Virtual Memory

• More processes may be maintained in the main memory: Because


we are going to load only some of the pages of any particular process,
there is room for more processes. This leads to more efficient
utilization of the processor because it is more likely that at least one of
the more numerous processes will be in the ready state at any
particular time.
• A process may be larger than all of the main memory: One of the
most fundamental restrictions in programming is lifted. A process
larger than the main memory can be executed because of demand
paging. The OS itself loads pages of a process in the main memory as
required.
Advantages of Virtual Memory

• It allows greater multiprogramming levels by using less of the


available (primary) memory for each process.
• It has twice the capacity for addresses as main memory.
• It makes it possible to run more applications at once.
• Users are spared from having to add memory modules when RAM
space runs out, and applications are liberated from shared memory
management.
Advantages of Virtual Memory

• When only a portion of a program is required for execution, speed has


increased.
• Memory isolation has increased security.
• It makes it possible for several larger applications to run at once.
• Memory allocation is comparatively cheap.
• It doesn’t require outside fragmentation.
• It is efficient to manage logical partition workloads using the CPU.
• Automatic data movement is possible.

You might also like