Changes to How Mac Manages Memory
With the release of OS X Mavericks, Apple changed how the Mac managed memory. With the addition of memory compression, your Mac can now do more with less memory while maintaining or increasing performance. In older versions of OS X, memory usage was built around a standard memory management system. Apps requested an allocation of RAM, the system fulfilled the request, and the apps gave back the RAM when they no longer needed it. The operating system took care of most of the work of keeping track of how much RAM was available and who was using it. The OS also figured out what to do if the amount of RAM needed wasn’t available, which could lead to adverse effects on the Mac’s performance as the system tried to make use of virtual RAM by swapping space on an SSD or hard drive.
What Is Compressed Memory?
Compressed memory isn’t something new or exclusive to Apple. Computing systems have been using various forms of memory compression for a long time. If you used Macs in the mid-’80s and early ’90s, you might remember products such as RAM Doubler from Connectix, which compressed data stored in RAM, effectively increasing the amount of free RAM available to the Mac. Compressed memory utilities fell out of favor as computer makers and OS developers created better memory management systems. At the same time, memory prices declined. The other factor that made memory compression systems lose their popularity was the performance issue. Memory compression algorithms took a hefty chunk of processing power. While they let you get more done with less physical RAM, they tended to bog down your computer when they needed to compress or decompress memory. Memory compression is making a comeback, primarily because of the advent of inexpensive multiple core processors. When the routines used for memory compression can be offloaded to one of many processor cores, you’re not likely to notice any performance hit when memory needs to be compressed or decompressed. It becomes merely a background task.
How Compressed Memory Works on a Mac
Memory compression on the Mac increases operating system and app performance by allowing better management of RAM resources. It also prevents or significantly reduces the use of virtual memory, which is the paging of data to and from Mac’s drive. With OS X Mavericks and later, the OS looks for inactive memory, which is memory that isn’t currently in active use but still holds data that can be used by an app. This inactive memory compresses the data it’s holding, so the data takes up less memory. Inactive memory can be apps that are in the background and not being used. An example is a word processor that is open but inactive because you’re taking a break and reading about compressed memory. While you’re busy browsing the web, the OS is compressing the word processor’s memory, freeing up RAM for use by other apps.
When Does Memory Compression Occur?
The compression process isn’t active all the time. Instead, the OS checks to see how much free space is available in RAM. If there’s a significant amount of free memory, no compression occurs, even if there’s a lot of inactive memory. As free memory is used up, the OS starts looking for inactive memory to compress. Compression starts with the oldest used data stored in memory and works its way forward to ensure that there is adequate free memory available. When the data in a compressed area of RAM is needed, the OS decompresses the data on the fly and makes it available to the app requesting it. Because the compression and decompression routines run concurrently on one of the processor cores, you’re unlikely to experience any performance loss while the compression or decompression occurs.
Limits of Memory Compression on Macs
There are limits to what compression can achieve. At some point, if you continue to launch apps or use memory-intensive apps that gobble up RAM, your Mac won’t have enough free space to function optimally. Just as in the past, the OS begins to swap inactive RAM data to your Mac’s drive. However, with memory compression, this is likely to be a rare occurrence for most users. Even if the OS ends up swapping memory out to your drive, OS X’s memory management system takes advantage of the compressed inactive memory by writing the compressed data to full-length drive segments to increase performance and reduce wear on SSDs.
Activity Monitor and Memory Compression
Apple provided a nifty tool, the Activity Monitor, that could monitor how the Mac used RAM. While the Activity Monitor is still available, its memory monitoring capabilities have undergone a dramatic change that mimics the way a Mac is better able to make use of RAM through the use of compressed memory. You can monitor how much memory the Mac is compressing by using the Memory tab in Activity Monitor. Compressed memory displays in the Memory Pressure graph, which indicates how actively the OS is involved in compressing RAM data. The graph turns from green (little pressure) to yellow (significant pressure), and finally to red, when there isn’t enough RAM space, and memory has to be swapped out to the drive.