Does macOS compact RAM to save power?

0

1

We all know that a modern OS will save power by throttling the CPU (or even putting it to sleep) when it isn't needed. But what about the RAM? After all, DRAM can't be powered-down without losing its contents, even when the machine is in sleep mode.

But maybe not all of the DRAM needs to be powered all the time. Since RAM is packaged in discrete modules (DIMMs), it sounds feasible for the OS to "compact" the active memory into as few DIMMs as possible, and then disable the unused DIMMs. (Thanks to virtual memory addressing, it should be possible for the OS to move RAM contents around without disrupting running programs.)

So the question is: Does macOS actually save power in that way? Or do all of your RAM chips stay on and fully powered, even when you aren't actually using all of your RAM capacity?


Side note: I know that macOS has different "sleep modes", and in some of them, the RAM is powered down completely (after its contents are saved to disk). I'm not asking about those other modes. I'm asking about the default sleep mode, in which the contents of RAM are not restored from disk upon power-up.

superbatfish

Posted 2019-12-03T22:11:53.833

Reputation: 101

Answers

1

Compared to other devices in the system DRAM memory is a paltry saving.

If you have multiple DIMMs then your system may be using them in dual channel (or higher if you have a workstation CPU) and it would be a juggling trick to copy used memory out of one DIMM to another, to disentangle the dual-channel mode and shut down a DIMM.

Chances are a higher power saving could be made by, say, marginally limiting the CPU peak clock rate, shutting down a mechanical hard disk, or throttling the GPU.

DIMMs are one of the relatively low power devices compared to all the other major power systems in a computer and there is little benefit to them having anything like this level of granularity of power control.

I doubt the memory controller in processors is even capable of dynamically hotplugging memory banks on the fly. I suspect the system would have to effectively hibernate (checking if it might fit in a single DIMM, halt the processor, and then restart the processor in single channel mode with a channel disabled to load memory contiguously on a single DIMM (if the working set fits).

Mokubai

Posted 2019-12-03T22:11:53.833

Reputation: 64 434

That RAM usage may not be significant when the machine is in use, but when a laptop is sleeping, wouldn't DRAM be one of the most significant users of power? That is, how long your laptop can sleep without entering a full "hibernation" probably depends mostly on how much current the RAM needs, right? – superbatfish – 2019-12-04T15:25:05.593

Thanks, BTW, for mentioning the dual-channel issue. I wasn't aware of it. Still, if dual-channel mode is the only show-stopper for the (hypothetical) feature I'm asking about, then it's possible that MacBook designers decided to optimize for battery life rather than modest RAM performance gains. They could just opt for single-channel mode if they want. – superbatfish – 2019-12-04T15:27:32.433

Potentially, but the time, CPU and system load and complexity of the operating system and computer hardware to do this wipes out any potential gain. If we assume of the order of 2W of power per DIMM, in a system with a battery that can last upwards of 6 hours at full pelt drawing up to 60W for all components, then the time before hibernation should be days, maybe weeks, not hours. If you need the difference between 7 and 14 days of sleep rather than hibernation then you've probably wasted money buying an overspecced machine to begin with. – Mokubai – 2019-12-04T15:33:25.560

If it goes into hibernation after a couple of days as is most likely, then you weren't using the machine enough to warrant the extra design and system complexity cost of the insane power micromanagment in the first place. – Mokubai – 2019-12-04T15:35:46.577

Thanks for the explanation. To be clear, I'm not worried about hibernation per se. I'm thinking about buying a MacBook with 64GB of RAM even though my typical usage will be 32GB or less. I'm just curious if there's a penalty to having all that extra RAM, either while the machine is active or while it's asleep. I'm having trouble finding estimates of the power usage for the MacBook DDR4 chips, but as you say, it sounds like it isn't significant relative to the other components. – superbatfish – 2019-12-05T14:51:38.560

Slightly off-topic, but fun to share: Apparently memory defragmentation can be important in embedded systems like QNX devices. They have a nice explanation: http://www.qnx.com/developers/docs/qnxcar2/index.jsp?topic=%2Fcom.qnx.doc.neutrino.sys_arch%2Ftopic%2Fproc_Defragmenting.html

– superbatfish – 2019-12-05T15:30:00.463