Memory Management
Memory Management
Memory Management
By, SANTOSH S
Research Staff
ECE Dept.,
MSEC
5.5 Contiguous Memory Allocation
• Definition - What does Contiguous Memory Allocation mean?
Ans: Contiguous memory allocation is a classical memory allocation model that assigns a process consecutive memory
blocks (that is, memory blocks having consecutive addresses).
• Contiguous memory allocation is one of the oldest memory allocation schemes. When a process needs to execute,
memory is requested by the process. The size of the process is compared with the amount of contiguous main
memory available to execute the process. If sufficient contiguous memory is found, the process is allocated memory
to start its execution. Otherwise, it is added to a queue of waiting processes until sufficient free contiguous memory
is available.
1. External Fragmentation: Total memory space is enough to satisfy a request or to reside a process
in it, but it is not contiguous, so it cannot be used.
2. Internal Fragmentation: Memory block assigned to process is bigger. Some portion of memory is
left unused, as it cannot be used by another process.
• Swapping:
• Swapping is a mechanism in which a process can be swapped temporarily out
of main memory (or move) to secondary storage (disk) and make that memory
available to other processes. At some later time, the system swaps back the
process from the secondary storage to main memory.
• Though performance is usually affected by swapping process but it helps in
running multiple and big processes in parallel and that's the reason Swapping
is also known as a technique for memory compaction.
• The total time taken by swapping process includes the time it takes to move the entire process to a
secondary disk and then to copy the process back to memory, as well as the time the process takes to regain
main memory.
• Let us assume that the user process is of size 2048KB and on a standard hard disk where swapping will take
place has a data transfer rate around 1 MB per second. The actual transfer of the 1000K process to or from
memory will take : 2048KB / 1024KB per second = 2 seconds = 2000 milliseconds Now considering in and
out time, it will take complete 4000 milliseconds plus other overhead where the process competes to regain
main memory.
NoNContiguous Memory Allocation
• In non-contiguous allocation, Operating system needs to maintain the table which is called Page Table for
each process which contains the base address of the each block which is acquired by the process in memory
space. In non-contiguous memory allocation, different parts of a process is allocated different places in
Main Memory. Spanning is allowed which is not possible in other techniques like Dynamic or Static
Contiguous memory allocation. That’s why paging is needed to ensure effective memory allocation. Paging
is done to remove External Fragmentation.
• Working:
Here a process can be spanned across different spaces in main memory in non-consecutive manner.
Suppose process P of size 4KB. Consider main memory have two empty slots each of size 2KB. Hence total
free space is, 2*2= 4 KB. In contiguous memory allocation, process P cannot be accommodated as
spanning is not allowed.
• In contiguous allocation, space in memory should be allocated to whole process. If not, then that space
remains unallocated. But in Non-Contiguous allocation, process can be divided into different parts and
hence filling the space in main memory. In this example, process P can be divided into two parts of equal
size – 2KB. Hence one part of process P can be allocated to first 2KB space of main memory and other part
of processP can be allocated to second 2KB space of main memory. Below diagram will explain in better
way:
In order to avoid this time consuming process, we divide our process in secondary
memory in advance before reaching the memory memory for its execution. Every
process is divided into various parts of equal size called Pages. We also divide our main
memory into different parts of equal size called Frames. It is important to understand
that:
• Comparision of Contiguous and Noncontiguous Memory Allocation? [ Assignment]
Paging
• Paging is a memory management scheme that eliminates the need for contiguous allocation of
physical memory. This scheme permits the physical address space of a process to be non –
contiguous.
• A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory and it is a section of a hard that's set up
to emulate the computer's RAM. Paging technique plays an important role in implementing
virtual memory.
• Similarly, main memory is divided into small fixed-sized blocks of (physical) memory
called frames and the size of a frame is kept the same as that of a page to have optimum
utilization of the main memory and to avoid external fragmentation.
Segmentation
• Segmentation is a memory management technique in which each job is divided into several segments of
different sizes, one for each module that contains pieces that perform related functions. Each segment is
actually a different logical address space of the program.
• When a process is to be executed, its corresponding segmentation are loaded into non-contiguous
memory though every segment is loaded into a contiguous block of available memory.
• Segmentation memory management works very similar to paging but here segments are of variable-length
where as in paging pages are of fixed size.
• A program segment contains the program's main function, utility functions, data structures, and so on. The
operating system maintains a segment map table for every process and a list of free memory blocks along
with segment numbers, their size and corresponding memory locations in main memory. For each
segment, the table stores the starting address of the segment and the length of the segment. A reference
to a memory location includes a value that identifies a segment and an offset.
Segmentation With Paging