1. Computing

Discuss in my forum

Understanding Compressed Memory in OS X

OS X Mavericks Brings Memory Compression to the Mac

By

Understanding Compressed Memory in OS X

Apple even provided a pretty nifty tool, the Activity Monitor, that among other things, could monitor how a Mac's RAM was being used.

Screen shot courtesy of Coyote Moon, Inc.
Understanding Compressed Memory in OS X

The amount of compressed memory displays in the Memory Pressure graph, which indicates how actively the OS is involved in compressing RAM data.

Screen shot courtesy of Coyote Moon, Inc.

With the release of OS X Mavericks, Apple changed how memory is managed on a Mac. In older versions of OS X, memory usage was built around a pretty 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 OS took care of most of the dirty 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. That last part was the most important because there could be adverse effects on a Mac's performance as the system tried to make use of virtual RAM (swap space on an SSD or hard drive).

Apple even provided a pretty nifty tool, the Activity Monitor, that among other things, could monitor how a Mac's RAM was being used. While the Activity Monitor is still available, its memory monitoring capabilities have undergone a dramatic change, one that mimics the way a Mac is now able to better make use of RAM through the use of compressed memory.

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 back in the mid 80s and early 90s, you may 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. I remember seeing the RAM Doubler icon appear as my Mac Plus started up. Believe me, the Mac Plus, which only had 4 MB of RAM, needed all the help that RAM Doubler could give it.

Compressed memory utilities fell out of favor as computer makers and OS developers created better memory management systems. At the same time, memory prices were declining. 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. That meant that 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 simply becomes a background task.

How Compressed Memory Works on a Mac

Memory compression on the Mac is designed to increase OS and app performance by allowing better management of RAM resources, and to prevent or greatly reduce the use of virtual memory, which is the paging of data to and from a Mac's drive.

With OS X Mavericks (or later), the OS looks for inactive memory, which is memory that isn't currently in active use but still holds data that will 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 would be a word processor that is open but inactive, because you're taking a break and reading about compressed memory (by the way, thanks for stopping by and reading this article). While you're busy browsing the web, the OS is compressing the word processor's memory, freeing up RAM for use by other apps, such as the Flash player you're using to watch a movie on the web.

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 is performed, 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 are run concurrently on one of the processor cores, you're unlikely to experience any performance loss while the compression/decompression occurs.

Of course, 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. Just as in the past, the OS will begin to swap inactive RAM data to your Mac's drive. But with memory compression, this is likely to be a very rare occurrence for most users.

Even if the OS ends up having to swap 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

You can monitor how much memory is being compressed by using the Memory tab in Activity Monitor. The amount of compressed memory displays in the Memory Pressure graph, which indicates how actively the OS is involved in compressing RAM data. The graph will turn 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.

So, if you've noticed that your Mac seems to have a bit more bounce in its performance since you installed Mavericks, it may well be because of the advances in memory management and the return of memory compression.

  1. About.com
  2. Computing
  3. Macs
  4. Mac Operating Systems
  5. Understanding Compressed Memory in OS X

©2014 About.com. All rights reserved.