0% found this document useful (0 votes)
48 views

OS Memory Management Notes

Os diploma notes

Uploaded by

varshapawar90648
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

OS Memory Management Notes

Os diploma notes

Uploaded by

varshapawar90648
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Operating System Memory Management Notes

Virtual Memory

Virtual memory is a memory management technique in an operating system (OS) that creates the

illusion of a large, continuous block of memory for applications, even if the physical RAM (Random

Access Memory) is limited. It allows the OS to use a combination of physical memory (RAM) and

disk storage to simulate a larger amount of memory, enabling programs that require more memory

than what is physically available.

Key Concepts of Virtual Memory

1. Paging: The OS divides memory into fixed-size blocks called pages. It can load only the required

pages into RAM and store the rest on the disk, improving memory utilization.

2. Page Table: A table that maps virtual addresses to physical addresses. The OS uses this table to

translate virtual memory addresses to actual physical memory locations.

3. Swap Space: When the RAM is full, the OS can move some inactive pages to a designated area

on the disk, called swap space, to free up RAM for active processes.

4. Demand Paging: The OS loads pages into memory only when they are needed, which reduces

the initial load time and memory footprint.

Advantages of Virtual Memory

- Efficient Memory Utilization: Allows the execution of large programs or multiple applications

concurrently without requiring large physical RAM.

- Process Isolation: Each process gets its own virtual memory space, which enhances security and

stability.

- Simplified Memory Allocation: Reduces the need for complex memory management in

applications.
Valid-Invalid Bit Scheme

The valid-invalid bit scheme is a memory management mechanism used in operating systems to

keep track of which pages are loaded in memory (RAM) and are valid (accessible) or invalid (not

currently in memory or inaccessible). It is often part of the page table, which maps virtual addresses

to physical addresses in systems that use paging.

How the Valid-Invalid Bit Scheme Works

- Valid Bit: When a page is marked as valid (1), it means that the page is currently loaded in physical

memory (RAM) and is accessible by the process.

- Invalid Bit: When a page is marked as invalid (0), it means that the page is not currently in physical

memory or that the address is not accessible by the process.

How It's Used

1. Memory Access Check: When a process tries to access a page, the OS checks the page table

entry for that page. The valid-invalid bit indicates if the page is in memory.

2. Page Fault Handling: If the bit is invalid (0), the OS triggers a page fault.

3. Security and Stability: The valid-invalid scheme prevents processes from accessing memory that

they do not own.

Benefits

- Efficient Memory Usage: The OS loads only pages that are actively being used, reducing memory

requirements.

- Improved Performance: By keeping track of valid and invalid pages, the OS avoids unnecessary

memory accesses.

- Process Isolation: Ensures that each process can only access its allocated memory.
Page Fault Handling

Page fault handling is the process by which an operating system (OS) manages a situation when a

program tries to access a page that is not currently loaded into physical memory (RAM).

Steps in Page Fault Handling

1. Page Fault Detection: The OS detects a page fault when a process accesses a page marked as

invalid.

2. Suspend the Process: The CPU traps to the OS (enters the OS code) and suspends the process

that caused the page fault.

3. Determine the Type of Page Fault: The OS determines whether the fault is legitimate (page not in

memory) or an illegal access.

4. Locate the Required Page on Disk: The OS finds the page in secondary storage (disk) in a

designated area for virtual memory.

5. Allocate a Free Frame in Physical Memory: If no free frame is available, it applies a page

replacement algorithm to free one.

6. Load the Page into Memory: The OS reads the page from disk into RAM and updates the page

table.

7. Resume the Process: The OS restarts the process at the point where it was interrupted.

Page Replacement (If Necessary)

If no free frames are available, a page replacement algorithm decides which page to remove from

memory.

Performance Impact

Page faults are costly, as disk access is slower than RAM access. Frequent page faults can lead to

thrashing.
Page Replacement Algorithms

Page replacement algorithms are used by operating systems to manage memory when handling

page faults. When a page fault occurs, these algorithms decide which page to remove to make

room.

Common Page Replacement Algorithms

1. First-In-First-Out (FIFO): Replaces the page that has been in memory the longest.

2. Optimal Page Replacement (OPT): Replaces the page that will not be needed for the longest

period (theoretically optimal but impractical).

3. Least Recently Used (LRU): Replaces the page that has not been used for the longest time.

4. Least Frequently Used (LFU): Replaces the page that has been used the least frequently.

5. Most Recently Used (MRU): Replaces the page that was most recently used.

6. Clock (Second-Chance) Algorithm: Uses a circular buffer to give each page a second chance

before replacement.

Each algorithm has its strengths and is suited to different workloads.

Fragmentation

Fragmentation in an operating system refers to inefficient memory usage caused by scattered free

blocks. It is classified into two types:

1. External Fragmentation: When free memory is divided into small, non-contiguous blocks. Caused

by repeated allocation and deallocation. Solution: compaction, paging, or segmentation.

2. Internal Fragmentation: Wasted space within allocated blocks due to fixed-size allocations.
Solution: smaller allocation units or segmentation.

Comparison of External and Internal Fragmentation

- External Fragmentation: Caused by allocation/deallocation, wastes space between blocks.

Solution: compaction or paging.

- Internal Fragmentation: Caused by fixed-size allocations, wastes space within blocks. Solution:

smaller allocation units.

Fragmentation in Paging and Segmentation

- Paging: Reduces external fragmentation but can lead to internal fragmentation.

- Segmentation: Reduces internal fragmentation but may lead to external fragmentation.

Fragmentation Management

Operating systems use paging, segmentation, compaction, and memory pooling to minimize

fragmentation.

You might also like