0
0
Operating Systemsknowledge~30 mins

Internal vs external fragmentation in Operating Systems - Hands-On Comparison

Choose your learning style9 modes available
Understanding Internal vs External Fragmentation
📖 Scenario: You are learning how computer memory is managed. When programs use memory, sometimes space is wasted. This wasted space is called fragmentation. There are two main types: internal and external fragmentation.Imagine a parking lot with fixed-size parking spots. Cars that are smaller than the spot leave empty space inside the spot (internal fragmentation). If the parking spots are scattered and not continuous, some cars cannot park even if there is enough total space (external fragmentation).
🎯 Goal: Build a simple example that shows how internal and external fragmentation happen in memory allocation. You will create a list of memory blocks, mark their sizes, and then simulate allocation to see wasted space inside blocks (internal) and leftover unusable space between blocks (external).
📋 What You'll Learn
Create a list of memory blocks with fixed sizes
Set a variable for the requested memory size
Write code to find a block that fits the request and calculate internal fragmentation
Calculate external fragmentation as total free space in unusable small blocks
💡 Why This Matters
🌍 Real World
Memory management is a key part of operating systems. Understanding fragmentation helps in designing efficient memory allocation.
💼 Career
Operating system developers, system programmers, and software engineers benefit from knowing how fragmentation affects performance and resource use.
Progress0 / 4 steps
1
Create memory blocks list
Create a list called memory_blocks with these exact integer sizes in KB: 100, 500, 200, 300, 600.
Operating Systems
Need a hint?

Use square brackets to create a list and separate numbers with commas.

2
Set requested memory size
Create a variable called requested_size and set it to 212 to represent the memory size requested by a program.
Operating Systems
Need a hint?

Assign the number 212 to the variable requested_size.

3
Find block and calculate internal fragmentation
Write a for loop using variables index and block_size to iterate over memory_blocks with enumerate(). Inside the loop, find the first block where block_size is greater than or equal to requested_size. Then create a variable internal_frag that is the difference between block_size and requested_size. Stop the loop after finding this block.
Operating Systems
Need a hint?

Use enumerate(memory_blocks) to get index and block size. Use break to stop after first fit.

4
Calculate external fragmentation
Create a variable called external_frag that sums all block sizes in memory_blocks which are less than requested_size. Use a list comprehension inside the sum() function.
Operating Systems
Need a hint?

Use a list comprehension to filter blocks smaller than requested_size and sum them.