Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Class Note - Memory Management

Memory management is essential for operating systems, focusing on efficient allocation and deallocation of memory to processes. It includes techniques like paging, which eliminates external fragmentation by dividing memory into fixed-size blocks, and segmentation, which divides memory into logical segments for easier protection and sharing. Modern systems often combine both methods to optimize memory usage and maintain system stability.

Uploaded by

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

Class Note - Memory Management

Memory management is essential for operating systems, focusing on efficient allocation and deallocation of memory to processes. It includes techniques like paging, which eliminates external fragmentation by dividing memory into fixed-size blocks, and segmentation, which divides memory into logical segments for easier protection and sharing. Modern systems often combine both methods to optimize memory usage and maintain system stability.

Uploaded by

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

Class Notes: Memory Management – Paging

and Segmentation
🔶 Introduction to Memory Management
Memory management is a core function of an operating system. It handles the allocation and
deallocation of memory to processes during their execution, ensuring efficiency, security, and
system stability.

Key Objectives:

 Maximize CPU and memory utilization


 Ensure process isolation and protection
 Provide mechanisms for memory sharing
 Enable efficient swapping and multitasking

🔷 Contiguous vs Non-Contiguous Allocation


1. Contiguous Allocation

 Each process is allocated one continuous block of memory.


 Simple to implement.
 Leads to fragmentation:
o External Fragmentation: Free memory is divided into small holes.
o Internal Fragmentation: Fixed-sized memory blocks may have unused space.

2. Non-Contiguous Allocation

 Process memory is divided and placed in non-adjacent memory blocks.


 Uses techniques like Paging and Segmentation.
 Reduces fragmentation and allows better memory utilization.

🔶 Paging
📌 Definition:
Paging is a memory management scheme that eliminates the need for contiguous allocation of
physical memory. It breaks physical memory into fixed-size blocks called frames and logical
memory into blocks of the same size called pages.

🧠 Key Concepts:

 Page: Fixed-size portion of a process’s memory.


 Frame: Fixed-size block of physical memory.
 Page Table: Maps pages to frames.
 Page Number (p) and Offset (d): Address is split into these two parts.

📋 Address Translation:

1. Logical address is generated by the CPU.


2. Logical address = (Page number p, Offset d)
3. Page table is used to find the frame number corresponding to page p.
4. Physical address = (Frame number, Offset)

✅ Advantages:

 Eliminates external fragmentation.


 Easy to manage with simple data structures (page tables).

❌ Disadvantages:

 Page table overhead (especially for large address spaces).


 Internal fragmentation (last page might not be fully used).
 Additional memory access time due to table lookup.

🔷 Example of Paging:
Assume:

 Page size = 4 KB (2^12 bytes)


 Logical address = 16-bit (so 64 KB address space)

Logical address = 14-bit page number + 2-bit offset

Logical Address (Binary) Page Number Offset


0001 0010 1100 1011 0001001011 001011
🔶 Segmentation
📌 Definition:

Segmentation divides a process’s memory into logical segments such as:

 Code segment
 Stack
 Heap
 Data segment

Each segment is treated as a separate unit with its own base and limit.

🧠 Key Concepts:

 Logical address = (Segment number, Offset)


 Segment Table:
o Base: Starting address of the segment in physical memory
o Limit: Length of the segment

📋 Address Translation:

1. CPU generates a logical address (Segment number s, Offset d).


2. OS checks segment table:
o Is d < limit? If not, segmentation fault.
o Physical address = Base + Offset

✅ Advantages:

 Reflects logical division of programs.


 Allows easier sharing and protection (each segment can have access rights).
 No internal fragmentation.

❌ Disadvantages:

 External fragmentation.
 More complex memory management.

🔄 Paging vs Segmentation – Comparison Table


Feature Paging Segmentation
Division Basis Fixed-size pages Logical segments (code, stack, etc.)
Feature Paging Segmentation
Fragmentation Type Internal External
Address Format Page number + Offset Segment number + Offset
Ease of Sharing Difficult Easy (each segment can be shared)
Protection Per-page basis Per-segment basis
Logical View Unstructured Structured (programmer-defined)

🔷 Combined Paging and Segmentation


Some systems (like Intel x86) use both techniques together:

 Segmentation first divides memory logically.


 Each segment is paged internally.

This allows:

 Logical separation of code/data/stack


 Efficient memory use through paging
 Fine-grained protection and sharing

📌 Summary Points
 Memory management ensures effective and safe use of RAM.
 Paging divides memory into fixed-size blocks, avoids external fragmentation.
 Segmentation divides memory logically, supports easier protection and sharing.
 Paging is efficient but abstract; segmentation is logical but less space-efficient.
 Modern systems often combine both for balance.

📝 Common Questions
Q1: Why is paging used despite internal fragmentation?

Because it eliminates external fragmentation and simplifies memory allocation.

Q2: Can a program be larger than the physical memory?

Yes, using virtual memory and paging, only active pages need to be loaded.

Q3: What is a page fault?


Occurs when a page is not in memory. The OS loads it from disk, slowing execution.

You might also like