3.memory Management 20240103
3.memory Management 20240103
• 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:
• 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:
• 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
• 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.
• 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