In-Depth Notes on Memory Management and Process State Management

Memory Management Overview

  • Memory management involves efficiently allocating and deallocating memory within the operating system (OS).

Process State Management

  • OS oversees the life-cycle of all processes in memory, managing their states like running, ready, and blocked.

Process Management Concepts

  • Base Register: Physical address pointing to where the process is loaded in memory.
  • Limit Register: Specifies the allowed range of addresses for that process, allowing access via offsets from the base address.
  • Both registers are crucial for memory separation and management, especially in contiguous memory allocation.

Contiguous Memory Allocation

  • Traditionally, processes needed contiguous blocks of memory, making allocation straightforward but prone to fragmentation.
  • Overview of processes in memory:
    • Each process is represented by its data, program code, and registers.

Increasing Multiprogramming

  • Degree of Multiprogramming: Number of processes that can execute simultaneously.
  • Achieved primarily by increasing main memory size or adopting virtual memory systems.
  • Virtual Memory: Allows processes to use a larger address space than the physical memory, utilizing secondary storage when necessary.

Memory Management Responsibilities of the OS

  • Memory Allocation: Assigning memory to processes as needed.
  • Deallocation: Freeing up memory when processes terminate or are swapped out.
  • Address Space Isolation: Protecting each process's address space from interference by others.
  • Virtual Memory Management: Facilitating switching processes in and out of main memory based on current usage.
  • Address Translation: Converting logical addresses generated by processes to physical addresses in RAM.

Key Concepts in Memory Management

  • Relocation: Processes may not occupy the same memory location upon reallocation. The OS needs to manage this seamlessly.
  • Protection: Preventing one process from accessing memory allocated to another, achieved through logical address spaces.

Logical Address Space

  • Involves translating logical addresses (used by the process) to physical addresses (actual memory locations).
  • Utilizes Base and Limit Registers:
    • Base register: Defines where the process starts.
    • Limit register: Defines the size of the addressable space for the process.
  • The Memory Management Unit (MMU) handles address translation by adding the base register value to the logical address and checking against the limit register.

Dynamic Relocation

  • Allows for the changing of physical location without modifying the process itself. The base register is updated upon recollecting the process.

Memory Allocation Strategies

  • Variable-sized Partitioning: Memory is dynamically partitioned into sizes based on process requirements.
  • Fragmentation: Smaller holes may arise, complicating new allocations.
  • Compaction: Periodic shifting of processes facilitates reduction of fragmentation by merging free spaces.

Paging

  • Modern OS typically uses paging instead of contiguous allocation, dividing memory into fixed-sized pages, thus removing fragmentation challenges.
  • Each process's address space consists of multiple non-continuous pages, with multiple pages per process potentially resident in non-continuous frames of physical memory.

Paging Systems

  • Virtual and physical memory is divided into pages, and the mapping of these via a page table helps in management.
  • Each address comprises:
    • Page number: Index to the page table.
    • Offset: Location within the page.
  • The MMU translates logical addresses into physical addresses, enhancing efficiency and performance without the need for contiguity.

Hardware Support for Paging

  • TLB (Translation Lookaside Buffer): Cache for quick access to page table entries, reducing translation time and improving system performance.
  • TLB size generally varies from 32 to 1024 entries, with a hit leading to faster address resolution compared to a miss, which may require a page table lookup.