6 ‐ Memory Management - CloudScope/DevOpsWithCloudScope GitHub Wiki

What is Main Memory?

  • Main memory, commonly referred to as RAM (Random Access Memory), is the computer's primary temporary storage for actively processed data. Efficient memory management, involving allocation and deallocation, is essential for optimal performance. The amount of RAM directly impacts multitasking and program handling capabilities, making it a critical factor in overall system performance.

Memory management in OS is a technique of controlling and managing the functionality of Random access memory (primary memory). It is used for achieving better concurrency, system performance, and memory utilization.

  1. Memory Mapping

    • mmap(): A system call that maps files or devices into memory, allowing files to be treated as part of the process's address space.

    • Shared Memory: Processes can share memory regions for inter-process communication (IPC), reducing the need to copy data between processes.

  2. Virtual Memory

    • Concept: Virtual memory abstracts physical memory to provide each process with its own address space, isolating processes and allowing them to use more memory than is physically available.

    • Paging: Linux uses a paging mechanism where memory is divided into fixed-size pages (typically 4KB). Pages can be swapped in and out of physical memory to disk as needed.

    • Swapping: When physical memory is exhausted, inactive pages are moved to swap space on disk, freeing up RAM for active processes.

  3. Fragmentation

    • When processes are moved to and from the main memory, the available free space in primary memory is broken into smaller pieces. This happens when memory cannot be allocated to processes because the size of available memory is less than the amount of memory that the process requires.

Memory Monitoring and Management Tools

  • free, top, htop: Command-line tools that display memory usage statistics.

  • vmstat: Provides detailed information about system processes, memory, paging, block IO, traps, and CPU activity.

  • /proc/meminfo: A virtual file that provides a snapshot of memory usage, including total, free, and available memory.