Understanding Memory Management in Computing Systems

An overview of how operating systems manage memory — address spaces, the MMU, page tables, I/O, and security.

Overview

The primary goal of memory management is to provide a method for the OS or CPU to access memory efficiently while ensuring that each process operates independently without interfering with others.

Types of Memory Addresses

  • Physical Address Space — refers to the actual addresses in RAM (Random Access Memory).
  • Virtual Address — a layer of abstraction over physical memory, allowing each process to have its own isolated memory space.

Important Components

  • Memory Management Unit (MMU) — hardware component that translates virtual addresses to physical addresses. This translation is vital for accessing the correct memory locations during process execution.
  • Page Tables — data structures the MMU uses to maintain the mapping between virtual and physical addresses, ensuring data retrieval and storage are conducted accurately and efficiently.
  • Process Isolation — each process is assigned a separate virtual address space, providing a safeguard that ensures one process cannot directly access the memory of another.

Memory Regions in Processes

  • Stack — the memory region where parameters, local variables, and control data for the process are stored.
  • Heap — used for dynamic memory allocation. The heap is managed by algorithms like malloc in C, which allocate and free memory as needed during runtime.

Shared Libraries and Mapped Files

  • Shared libraries allow multiple processes to use the same library or file without needing separate copies in memory.
  • Memory-mapped files enable I/O operations through memory manipulation, which can improve performance.

Input/Output (I/O) Operations

I/O operations transfer data between CPU memory and peripheral devices.

  • Synchronous I/O — the program waits (blocks) until the I/O operation is complete.
  • Asynchronous I/O — the program continues executing while the I/O operation is processed, improving efficiency and responsiveness.
  • Direct Memory Access (DMA) — allows data to be transferred directly between memory and a device, bypassing the CPU to speed up operations significantly.

Security in Memory Management

  • Address Space Layout Randomization (ASLR) — a security technique that randomly arranges the position of key data areas within the process address space.
    • ASLR can be bypassed if an attacker finds a memory leak vulnerability that reveals the address.
    • ASLR does not protect against non-memory corruption bugs, such as logic errors or side-channel attacks.