0% found this document useful (0 votes)
334 views5 pages

Paging and Segmentation 5.1

Hi am study diploma in Computer engineering and technology and javascript ka use

Uploaded by

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

Paging and Segmentation 5.1

Hi am study diploma in Computer engineering and technology and javascript ka use

Uploaded by

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

Introduction to Paging

Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory. It divides the process’s
memory into fixed-size units called pages, and the physical memory is divided into units of the same size called frames.

Key Concepts in Paging:


1. Page:
- A fixed-size block of logical memory. Pages are of the same size as frames.

2. Frame:
- A fixed-size block of physical memory. The size of a frame matches the size of a page.

3. Page Table:
- A data structure used to map logical page addresses to physical frame addresses. Each entry in the page table holds the frame number
corresponding to a page.

How Paging Works:


- When a process is executed, its pages are loaded into available frames in physical memory.
- The CPU generates a logical address (page number + offset), which is then translated by the page table into a physical address (frame number +
offset).

Advantages of Paging:
- No external fragmentation: Since memory is allocated in fixed-size frames, there are no gaps between allocated and free memory spaces.
- Efficient memory utilization: Paging allows the use of non-contiguous memory, improving flexibility in memory allocation.

Disadvantages of Paging:
- Internal fragmentation: Some memory inside a page may remain unused if the process does not perfectly fit into pages.
- Page table overhead: Managing large page tables can consume memory and processing time.

Introduction to Segmentation
Segmentation is another memory management technique where the memory is divided into variable-sized segments. Each segment represents a
logical unit, such as a function, array, or data structure.
Key Concepts in Segmentation:
1. Segment:
- A variable-sized block of memory that represents a logical division of a program, such as a function or data.

2. Segment Table:
- A data structure that keeps track of all segments and their corresponding physical addresses. Each entry in the segment table contains the
base address and limit of the segment.

How Segmentation Works:


- A logical address in segmentation is divided into two parts:
- Segment number: Identifies which segment is being referenced.
- Offset: The distance within the segment where the specific memory location resides.

- The CPU uses the segment number to find the base address and limit of the segment in the segment table. The offset is then added to the base
address to access the desired memory location.

Advantages of Segmentation:
- Logical grouping: Segments correspond to logical units of the program, making it easier to manage and protect memory (e.g., code and data
segments).
- Flexible memory allocation: Segments can grow or shrink dynamically, allowing efficient use of memory.

Disadvantages of Segmentation:
- External fragmentation: Since segments are variable in size, gaps of unused memory (fragmentation) may occur between segments.
- Complex management: Managing variable-sized segments and their dynamic allocation can be complex.

Comparison of Paging and Segmentation:


Feature Paging Segmentation
Memory Division Fixed-size pages Variable-size segments
Logical Division Divides memory into equal pages Divides memory into logical units
Fragmentation Internal fragmentation External fragmentation
Uses a page table to map pages to frames Uses a segment table to map
Memory Mapping
segments
Simplifies memory allocation but may More logical, but may suffer from
Efficiency
waste space fragmentation

Virtual Memory

Virtual Memory is a memory management technique that gives an application the impression that it has access to a large, contiguous block of
memory, even if the physical memory (RAM) is smaller. This is achieved by using a combination of physical memory (RAM) and disk space.

Virtual Memory resides primarily on the system’s secondary storage (typically the hard drive or SSD). This storage is used as an extension of the
physical memory (RAM). Specifically, a portion of the disk, called swap space or page file, is reserved to store parts of processes or data that
cannot currently fit into RAM.

When the physical memory is full, the operating system swaps out less frequently used data from RAM to this swap space on the disk. If the
swapped-out data is needed again, it is brought back into RAM, and another portion of memory may be swapped out in its place.

Thus, virtual memory is conceptually part of the memory system, but physically it resides on the disk.

Key Features of Virtual Memory:


1. Logical vs Physical Memory:
Virtual memory divides programs into smaller, manageable chunks, which may not be loaded into physical memory entirely. Only the
necessary portions (pages) are loaded as needed.

2. Demand Paging:
Instead of loading the entire program into RAM at once, only the required pages are brought into memory when needed. The rest of the
program stays in secondary storage (like a hard disk).

3. Swap Space:
The part of the hard drive used as an extension of physical memory is called swap space. When the RAM is full, the operating system can swap
out pages from memory to disk, making room for other data.
Advantages of Virtual Memory:
Allows more processes to run concurrently, even if the physical memory is limited.
Programs can use more memory than what is physically available in RAM.

Disadvantages of Virtual Memory:


Accessing data from disk (swap space) is much slower than accessing data from RAM, leading to performance degradation if excessive swapping
occurs (thrashing).

Fragmentation

Fragmentation occurs when memory space is used inefficiently, leading to wasted space. It can happen in two forms:

1. Internal Fragmentation:
Definition: Occurs when memory blocks are allocated in fixed sizes, and a process does not use all the allocated space. The leftover memory
within an allocated block is wasted.
Example: If a process requires 13 KB of memory and the system allocates a 16 KB block (due to fixedsize pages), 3 KB of memory inside the block
will be wasted. This is internal fragmentation.
2. External Fragmentation:
Definition: Occurs when free memory is scattered in small blocks throughout the system, preventing large processes from being allocated
memory, even though there is enough total free space.
Example: If there are several small free blocks of memory between occupied blocks, it may be impossible to allocate memory for a process
requiring a large contiguous block of memory, even if enough free space is available overall.

Page Fault

A Page Fault occurs when a program tries to access a page that is not currently loaded into physical memory (RAM). The system must then
retrieve the page from secondary storage (disk) and load it into RAM.
Steps in a Page Fault:
1. The CPU attempts to access a page that is not in physical memory.
2. The memory management unit (MMU) detects the missing page and triggers a page fault exception.
3. The operating system locates the page on disk (in the swap space).
4. The page is loaded into a free frame in physical memory.
5. The page table is updated to reflect the new location of the page in memory.
6. The program resumes execution.
Types of Page Faults:
Minor Page Fault: Occurs when the page is not in RAM but is still available in the system’s swap space.
Major Page Fault: Occurs when the page needs to be fetched from secondary storage (disk), which is time-consuming.
Impact of Page Faults:
Performance Slowdown: Frequent page faults, cause the system to spend a lot of time swapping pages in and out of memory (this condition is
called thrashing).
Handling: Page replacement algorithms, such as Least Recently Used (LRU) or First-In-First-Out (FIFO), are used to manage which pages to
remove from memory to make space for new ones.

Comparison: Fragmentation vs Page Fault


Aspect Fragmentation Page Fault
Wastage of memory space (internal or Missing page in memory,
Definition
external) requiring a fetch from disk
Inefficient memory allocation | Program accessing a page not
Cause
in physical memory
Leads to inefficient memory utilization Slows down system
Impact performance (due to disk
access)
Defragmentation, paging Effective page replacement
Solution
algorithms

You might also like