How Memory Works in macOS (why Apple can get away with shipping computers with 8 GB of RAM)"
This blog post is adapted from a YouTube video script. The video can be found below.
When Apple Silicon first launched, you'd hear goofy statements from Apple and various publications regarding RAM and Apple Silicon. One of the most common assertions Apple made was that 8 GB of RAM on Apple Silicon was equivalent to 16 GB of RAM on an Intel Mac. I'd argue today, the majority of users understand 8 GB of RAM is not 16 GB, regardless of the process type. What makes 8 GB still usable in 2024, even if not ideal, is the memory management in macOS. This will be a high-level overview of how macOS manages memory, so you better understand your own Mac.
Understanding Memory Usage in Activity Monitor
First, open Activity Monitor on your macOS and click on the Memory tab. Here, you'll see a list of all the applications and processes currently running.
To quote Apple:
"The Memory pane displays how much memory your Mac is using, how often it is swapping memory between RAM and your startup disk, the amount of memory provided for an app, and how much of it is compressed memory."
Apple Support
The Memory Pressure Graph
The most important thing to understand is the memory pressure graph at its most basic:
- Green: Your Mac is using memory efficiently.
- Yellow: You might need to free up RAM as performance could be reduced.
- Red: Your Mac needs more RAM, and performance is suffering.
This is also reflected in the graph itself. Freeing up RAM is generally accomplished by quitting applications and processes or by rebooting.
Memory Usage Columns
To the right of Memory Pressure are two columns that provide an overview of your Mac's memory usage. Starting with the first column:
- Physical Memory: This shows how much RAM is installed in your system. Note that on Apple Silicon Macs, this cannot be upgraded.
- Memory Used: This details how much RAM is currently being used, broken down into several categories:
Breaking Down Memory Categories
- App Memory: The amount of RAM being used by applications.
- Wired Memory: The RAM required by the operating system to function, which cannot be cached.
- Compressed Memory: RAM that has been compressed to free up space for other processes.
The Role of Cached Files and Swap Used
Cached Files: These are stored in unused memory to speed up performance. With modern macOS, unused RAM is wasted RAM, so it's uncommon to see macOS with a lot of free RAM. This is important to understand for long-time Mac users who remember checking for the amount of unused memory to gauge system performance. This no longer applies to macOS.
Swap Used: This indicates the space used on your startup drive for memory page outs, functioning as a memory extension when the physical RAM is fully utilized.
Virtual Memory Management
macOS uses a technique called virtual memory management. Here, each application thinks it has access to a large block of memory, which is actually a combination of physical RAM and swap space managed dynamically by the OS.
If you have less physical RAM, your system will rely more on swap space. Modern SSDs, which are very fast, make this process generally transparent to the user. Over usage or reliance on swap space can cause wear and tear on the SSD over time. A larger SSD will have more memory cells to rotate, thus will have a longer life. It's not uncommon to see SSDs advertise terrabytes written (TBW), a common metric for advertising longevity of an SSD, radically increase as the size increases. Apple gets a lot of well-deserved criticism for selling RAM-starved computers with small SSDs that aren't user-serviceable. While SSDs generally are considered more stable than their spinning disk counter parts, they have a finite shelf life.
Unified Memory in Apple Silicon
Apple Silicon uses unified memory for both its CPU and GPU. This means both can access the same memory, reducing redundancy and improving efficiency. While Intel's iGPUs used unified memory, this is a significant upgrade, which required separate memory pools. The downside, when compared to a dedicated GPU, is that the RAM pulls double duty as video operations are now in the RAM. This means that data such as frame buffers, shaders, textures, vertex data, geometry buffers, render targets and so on, are no longer stored within VRAM, rather RAM, thus the RAM is now pulling double-duty as the RAM and VRAM. For lower memory configured devices, this can tax the RAM further. At more extreme configurations like a Mac Studio with 192 GB of RAM, this means access to far more video memory than a traditional GPU would have.
Advanced Memory Management Features
- Virtual Memory Compression: Introduced in macOS Mavericks (10.9), this feature compresses inactive processes to free up more RAM.
- App Nap: This reduces the priority of inactive applications, saving memory and battery life.
- Application Save States: Allows apps to be quit and relaunched to their previous state, freeing up memory.
Some of Apple's energy saving and performance techniques also affect memory management such as App Napping. App napping works by detecting inactive applications, reducing their priority to minimize the amount of resources they consume. If an app meets certain criteria such as the app isn't visible to the user, isn't playing audio, or is performing a service like downloading a file, it can be put to sleep. This has memory implications, as napped applications are generally prioritized for memory swaps and memory compression.
If we go to the CPU section in the activity monitor, we can add the column App Nap and see the apps that are actively in a nap state.
Command Line Utilities
For those who want to get geekier, macOS offers several CLI utilities out of the box. These can be accessed from the terminal by running the following commands:
vm_stat
: Shows virtual memory stats.memory_pressure
: Provides detailed memory pressure information.top
: An terminal-based activity monitor. If you'd like an even more powerful activity monitor consider usinghtop
via Homebrew for a more user-friendly experience).
Final Thoughts
Switching from Mac OS 9 to OS X brought many improvements, including protected memory, which enhances security and reliability. While modern macOS has made significant strides in memory management, it's always a good idea to keep your system optimized and understand how it uses resources.
For a deep dive, check out the Developer Documentation and this Informit Article.