Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

EugW

macrumors P6
Original poster
Jun 18, 2017
15,687
13,918
Earth (for now)
I'm curious, with slower CPUs, how significant is the CPU overhead from memory compression?

The reason I ask is on an old 2009 13" MacBook Pro with 2.26 GHz Core 2 Duo and 4 GB, I can get the spinning beachball periodically for a few seconds when multitasking. I used to think it was due to hitting the swap, but after checking Activity Monitor, it turns out it's not always related to hitting the swap.

Since it only has 4 GB, there is a fair amount of compressed memory when multitasking. By "fair amount" I mean sometimes more than 1 GB. I figure the beachballs are a combination of just slow CPU trying to deal with multiple applications, plus the added overhead of memory compression. However, in some of this usage, the memory pressure stays green, despite the significant amount of memory compression.

On such an old CPU, is memory compression CPU overhead a significant issue?

Note I can just upgrade to 8 GB, but this is just a surfing and email machine, as I already have two other 2017 machines, so it may not be worth it. My kids are still too young to make use of it as a hand-me-down.
 
This article suggests that if you have more than 20% compressed memory, that signals a problem:

http://www.chriswrites.com/how-to-reduce-memory-usage-on-the-mac/

Compressed. To make more memory available for other processes, OS X will sometimes compress data in RAM, or swap it to your hard drive. Typically, if the compressed memory is 20% or more than your total memory, then this suggests there’s a problem and you should look at how many apps and processes are currently running on your machine.

On this machine usually the compressed memory is less than 800 MB which is less than 20% of 4 GB, but nonetheless when multitasking it may be in the 600 to 700 MB range and sometime way more. Also, when more than one user is logged in, that will increase memory usage.

I'm still wondering how much overhead there is from memory compression. My CPU is slow enough as it is. Having to compress memory on the fly may not be the end of the world, but I'm thinking the memory compression overhead may be adding to the perceived lagginess when multitasking, even when memory pressure is green, and swap file usage is low, especially for ancient CPUs like the Core 2 Duo 2.26 GHz P8400 / P7550.
 
Last edited:
So, I just installed 8 GB RAM in this machine. As expected, with moderate multitasking, it compresses memory way less, and sometimes not at all. Despite the fact that with 4 GB RAM and light to moderate multitasking I can keep the memory pressure in the green, with 8 GB it still subjectively feels more responsive. With 8 GB also in the green of course, but a shorter bar of green and very little memory compression, if any.

I suspect that the memory compression does indeed use up enough CPU cycles to have an impact on perceived speed, at least on a slow machine such as this one. No, it's not as slow as hitting the swap (and yes even an SSD swap can feel quite slow), but it still feels faster not having to compress so much memory.

So, IMO, memory pressure being green doesn't provide the full picture. Ideal is to have enough RAM to be able to keep all your quit applications in the memory cache, while also avoiding doing a lot of memory compression.
 
This article suggests that if you have more than 20% compressed memory, that signals a problem:
It’s not really a problem as the kernel is doing the right thing with the resources available.

I'm still wondering how much overhead there is from memory compression. My CPU is slow enough as it is. Having to compress memory on the fly may not be the end of the world, but I'm thinking the memory compression overhead may be adding to the perceived lagginess when multitasking, even when memory pressure is green, and swap file usage is low, especially for ancient CPUs like the Core 2 Duo 2.26 GHz P8400 / P7550.
Try simulating by timing the compressing an 800MB file which should give you an idea.

To add, I don’t know if there’s a tool which will show how many pages are being decompressed by frequency. The frequency of compressing/decompressing of the working set of an app is the equivalent of swapping pages to storage. Perhaps this is what the memory pressure colors allude too. Still would like factual numbers of what they represent.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.