Linux Virtual Memory - Dynamic Memory
In the last lesson we reviewed the memory attribute of Static vs Dynamic, and how dynamic memory is mapped into variable locations in the virtual memory map, and whose size is not determined before runtime. I need to briefly go over the different types of dynamic memory so that the examples in the next part will not be confusing.
Linux Virtual Memory - Memory Types
Each entry in a process's virtual memory map can have several different properties that change how both humans and the kernel think about their page allocation and management. Understanding the different properties, and the contexts where they are defined and used, is necessary to understand when, why, and to/from where the kernel makes decisions about pages.
Linux Virtual Memory - Paging pt.2
In the Previous lesson we looked at the fact that the virtual memory address for a process's pages are not directly related to the physical memory address for the page frame where it resides. This lesson will look at the mechanics of how the kernel performs the mapping.
Memory Sizes
Computer memory involves really big numbers. Uncomprehendingly big sometimes. To make sense of it, conventions have been made to make writing and thinking about these numbers easier for humans, with different conventions being most useful in different contexts.
Linux Virtual Memory - Paging pt.1
A memory address is a single number whose value is between 0 and a maximum determined by your hardware architecture, and a memory space is the entire range of valid addresses within a given scope. The x86-64 architecture has 64 bit memory values, meaning that the address space is between 0 and \(2^{64} - 1\) or \(1.84*10^{19}\), which is enough to address 16 exabytes of memory. For reference a mainstream desktop PC's physical RAM in 2019 tops out around 128 GB, or \(2^{37}\) or \(1.37*10^{11}\). Virtual memory space has room for 100,000,000 times more memory than this amount of physical RAM.
Linux virtual memory does not work at this fine level of detail however, and instead manages chunks of memory called pages. When a process accesses a location in memory, the OS (with help from the hardware MMU, or memory management unit,) determines which page that address belongs to, and translates the virtual page into a physical page frame in RAM.
Linux Virtual Memory Introduction
Virtual memory management is one of the most complicated functions of an operating system kernel, and together with process scheduling accounts for the majority of its function and performance. Over a series of posts I intend to break down how Linux manages this highly complicated topic into a format that will be digestible and relevant to both system administrators and program developers.