CS Engineering Gyan

Paging in Memory Management

Paging divides memory into fixed-size pages and frames. A page table maps pages to frames, eliminating external fragmentation.
Paging is a memory management technique used to store and access data efficiently. It allows a process to be divided into smaller parts so that memory can be used in a flexible way. In paging, memory is divided into two parts:

Each page has the same size as a frame.
Paging in Operating System
In the diagram:

Working of Paging in Operating System

Working of Paging in Operating Systemm

Paging is a memory management method that converts a logical address generated by the CPU into a physical address in main memory. This process helps the operating system use memory efficiently.

1. Logical Address Generation

The CPU generates a logical address which is divided into two parts:

Logical Address = Page Number + Offset

In this example, the logical address is 13 bits:

2. Page Table Mapping

The page number is sent to the page table. The page table stores the corresponding frame number where the page is located in RAM.

Example: Page 2 → Frame 2

3. Physical Address Formation

After finding the frame number, the system combines:

Physical Address = Frame Number + Offset

In this example:

4. Accessing Main Memory

Using the physical address, the system accesses the correct frame in main memory and fetches the required data.

Segmentation in memory Management

Segmentation in Operating System (OS) is a memory management technique where a program is divided into smaller logical parts called segments. Segmentation divides a program into logical units such as code, data, and stack segments. Each segment has its own base and limit.
Segmentation means breaking a program into meaningful sections like:

Each part is stored separately in memory.

Working of Segmentation in Operating System

Working of Segmentation in Operating System

Segmentation is a memory management technique where a logical address generated by the CPU is converted into a physical address using a segment table.

Steps Involved

  1. Logical Address from CPU

    • Segment Number (s) = 1
    • Offset (d) = 400
    • Logical Address = (1, 400)
  2. Access Segment Table

    • Base Address = 1800
    • Segment Size = 400
  3. Check Validity

    • Check if Offset ≤ Segment Size
    • 400 ≤ 400 → Valid
    • If offset is greater → Segmentation Fault
  4. Calculate Physical Address

    • Physical Address = Base Address + Offset
    • Physical Address = 1800 + 400 = 2200
  5. Access Physical Memory

    • System accesses memory at address 2200
    • Data is retrieved successfully

Invalid Case

Difference Between Paging and Segmentation

Paging and segmentation are two important memory management techniques used by operating systems to manage main memory efficiently. Although both aim to overcome memory-related problems such as fragmentation and inefficient utilization, they differ significantly in concept, structure, and implementation. The detailed comparison below explains these differences clearly.

Feature Paging Segmentation
Basic Concept Paging divides the physical and logical memory into fixed-size blocks called pages and frames. Segmentation divides memory into variable-size logical units called segments based on program structure.
Memory Unit Size All pages and frames are of equal, fixed size. Segments are of variable size depending on program requirements.
View of Memory Paging provides a physical view of memory, focusing on efficient memory utilization. Segmentation provides a logical view of memory, matching how programmers think about programs.
Fragmentation Paging suffers from internal fragmentation due to fixed-size pages. Segmentation suffers from external fragmentation because segments vary in size.
Address Structure Logical address consists of page number and offset. Logical address consists of segment number and offset.
Memory Allocation Pages can be stored in any available frame, so memory need not be contiguous. Each segment is stored in a contiguous block of memory.
Ease of Implementation Easier to implement due to fixed-size memory blocks. More complex to implement due to variable-size segments.
Protection and Sharing Provides limited support for protection and sharing. Provides better protection and sharing at the segment level.
Use Case Suitable for systems where efficient memory utilization is a priority. Suitable for systems requiring logical separation of program components.

In conclusion, paging focuses on efficient physical memory management by eliminating external fragmentation, while segmentation emphasizes logical organization and protection of program components. Many modern operating systems use a combination of both techniques to take advantage of their respective strengths.

Memory management plays a vital role in the performance and reliability of an operating system. By using techniques such as paging, segmentation, and virtual memory, the OS ensures optimal utilization of limited memory resources.

← Previous: Memory Management Next: Fragmentation →
Home Visit Our YouTube Channel