Drawback of paging and how to solve it

Drawbacks of paging

When pages are scattered far apart in physical memory, it can lead to additional drawbacks:

1. Reduced Cache Efficiency:

  • Explanation: If the pages of a process are spread out across distant locations in RAM, it can reduce the efficiency of the CPU cache, which relies on the locality of reference. The CPU cache works best when data is close together, as it can quickly load and reuse it. When data is scattered, it increases the chances of cache misses, slowing down memory access.
  • Example: Imagine a book is split into sections and stored on shelves all over a large library (representing RAM). If you have to walk across the library to read each section, it takes much longer than if the sections were on the same or nearby shelves. Similarly, if pages of a process are spread far apart in memory, the CPU might need to fetch data from multiple distant locations, reducing performance

2. Increased Page Table Lookup Time:

  • Explanation: If the pages of a process are not stored contiguously in RAM, the Memory Management Unit (MMU) might have to work harder to translate logical addresses to physical addresses. Each lookup involves accessing different parts of the RAM, which can take more time, especially if those parts are far apart.
3. Internal Fragmentation:
  • Explanation: Pages are of fixed size, but the data within them might not fill the entire page. This unused space within a page leads to wasted memory, known as internal fragmentation.
  • Example: If each page is 4KB, but a process only needs 2KB of space, the remaining 2KB is wasted. Even if there are multiple such processes, all the extra unused space adds up, leading to inefficient memory use.
What is segmentation?

Segmentation is a memory management technique where a process's memory is divided into different segments based on its logical structure, like code, data, and stack. Each segment is independent and has its own base and limit values. Segmentation allows each segment to grow independently, unlike paging where the memory is divided into fixed-size pages.

Example:
Imagine a simple program with three parts:
  • Code segment: Where the instructions of the program are stored.
  • Data segment: Where the program's variables and data are stored.
  • Stack segment: Where function calls and local variables are handled.
Let's say:
  • The Code segment is 10 KB.
  • The Data segment is 5 KB.
  • The Stack segment is 3 KB.

Disadvantages of Segmentation: 
  • External Fragmentation: Since segments are of variable sizes, as processes are loaded and unloaded from memory, free memory can become fragmented into small, non-contiguous blocks. Over time, this can make it difficult to allocate large segments, even if enough total free memory is available. 
  • Example: Imagine you have 100 KB of free memory, divided into blocks of 30 KB, 40 KB, and 30 KB. Now, suppose a process requires a segment of 50 KB. Even though you have 100 KB total free memory, you can't allocate the 50 KB segment because there's no single contiguous block of 50 KB available. The small free blocks scattered around the memory are not useful for this large segment.

Comments

Post a Comment

Popular posts from this blog

Indexed allocation

Thrashing

Basics of paging