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

OS Diagram

Diagram of OS memory management

Uploaded by

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

OS Diagram

Diagram of OS memory management

Uploaded by

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

Memory Management : Stack VS Head

Stack
High Address
ver in &
Devinknam
. Hea
Heap Overflow

war
Function Calls
11-0
Local Variables

·ack Over

Kernel/OS Reserved Memory


Allocation
Fast Access
Low Address
Limited Size
Memory management is a crucial function of an operating system (OS), ensuring that programs and processes have sufficient space to run
efficiently. It involves managing two primary types of memory: stack and heap, as illustrated in your diagram. Here’s a breakdown of how memory
and virtual memory addressing work in reference to these components:

1. Stack Memory:

• Purpose: The stack is used for static memory allocation. It’s mainly used to store temporary variables, function calls, and control flow data like
return addresses.

• Organization: In the diagram, the stack grows downward from high memory addresses to lower ones. Each function call creates a new “stack
frame” with local variables and return addresses, which are removed after the function execution is complete (following a Last In, First Out
(LIFO) principle).

• Efficiency: The stack provides fast access since the memory allocation and deallocation happen in a predictable manner—pushing and popping
data on/from the stack is straightforward. However, the memory size is limited, and exceeding it leads to a stack overflow.

2. Heap Memory:

• Purpose: The heap is used for dynamic memory allocation, such as when objects or data structures are created at runtime (using commands like
malloc in C or new in Java).

• Organization: The heap grows upward from low memory addresses. Memory here is not structured like the stack and can fragment over time as
memory blocks are dynamically allocated and freed. In your diagram, the rectangles of different sizes represent allocated memory blocks. Heap
overflow occurs when there is no more room to allocate new memory.

• Efficiency: Heap memory is slower to access because memory allocation involves more complex management by the OS. Memory leaks and
fragmentation can also be issues when heap memory is not managed properly.

3. Virtual Memory:

• Concept: Virtual memory is a layer of abstraction that allows the operating system to create the illusion that the system has more physical
memory than it actually does. This is done by using disk storage (such as a hard drive or SSD) to extend physical memory. The OS maps virtual
addresses to physical addresses, ensuring that active processes can continue running even when RAM is full.

• How It Works in the Diagram: Virtual memory allows both stack and heap to expand beyond the physical limits of the computer’s Random
Access Memory (RAM). The OS handles this by moving inactive data from RAM to disk storage in a process called paging. In the diagram, this
would be represented by arrows indicating that both stack and heap can grow larger than physical memory by using disk space.

• Efficiency: Virtual memory ensures that memory-intensive applications can run on systems with limited physical memory. However, excessive
paging (called thrashing) can slow down the system, as disk access is much slower than RAM.

4. Address Translation:

• Logical and Physical Addresses: When a program is executed, it works with logical addresses (or virtual addresses), which the OS translates
into physical addresses using a process known as address translation. This translation is managed by the Memory Management Unit (MMU) in
the CPU, which maps virtual addresses to actual physical locations in RAM or disk storage.

• Paging: In virtual memory systems, memory is divided into small units called pages. When a program tries to access data that isn’t in RAM, the
OS fetches the data from disk (using a page table) and loads it into RAM.

Summary:

In simple terms, stack and heap represent two ways memory is used within a computer system. The stack is small, fast, and for short-lived data,
while the heap is larger, slower, and used for dynamic data. Virtual memory allows both to operate beyond physical limits by using disk space to
simulate extra RAM. Through address translation, the operating system ensures processes have access to necessary memory without knowing
where it’s physically stored.

Virtual memory is a critical feature in modern systems, ensuring efficient multitasking and resource management, even when memory demands
exceed physical resources.

You might also like