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

Mity

macrumors 6502a
Original poster
Nov 1, 2014
777
704
Have a look at this video:

He's building an Xcode project which is using almost 16GB of RAM. Despite having 64GB total available, there's still 6.5MB of swap being utilized.

Screenshot 2023-06-13 at 22.57.30.png


I don't experience this at all on my 2019 16" with 64GB RAM (I do, however, experience heat and fan noise ;) ). Despite running lots of Jupyter notebooks, I've never utilized swap. My base M1 Air swaps frequently but I've always attributed that to the 8GB of RAM and my bad habit of having 20+ Chrome tabs open.

So, what's going on above where the 64GB of RAM on the M1 Max machine is using swap?
 
  • Like
Reactions: zapmymac

russell_314

macrumors 604
Feb 10, 2019
6,640
10,228
USA
Because it's not a simple mechanism like "start using swap when RAM is full".

Similar to vm.swappiness in Linux kernel, dynamic_pager in macOS also has an algorithm under the hood.
I kind of wonder if the operating system tries to learn what the user is doing and reacts to prepare for that. These computers are being tested by reviewers so they're probably constantly running benchmarks so the operating system is preparing for a massive workload. It's crazy, but I checked my Activity Monitor on my Air and I have zero swap being used. I don't run benchmarks or intensive applications. I keep a bunch of stuff open, but it's lightweight stuff like Notes, Mail, Maps, Messeges, Photos, Numbers, Firefox, Safari, etc.
 

Mity

macrumors 6502a
Original poster
Nov 1, 2014
777
704
Because it's not a simple mechanism like "start using swap when RAM is full".

Similar to vm.swappiness in Linux kernel, dynamic_pager in macOS also has an algorithm under the hood.

That doesn't explain why, though. When I code on my Intel MBP, why doesn't it utilize swap?
 
  • Love
Reactions: zapmymac

russell_314

macrumors 604
Feb 10, 2019
6,640
10,228
USA
That doesn't explain why, though. When I code on my Intel MBP, why doesn't it utilize swap?
Why doesn't my M2 Air utilize swap? Why did my Intel Mac mini with 32 GB RAM utilize swap?

What I'm trying to say is I don't think it's an Intel or Apple silicon thing. I don't have an answer, obviously, but I have two cases personally where Apple silicon is not using swap currently, and my old Intel Mac utilized swap and had twice the RAM. I can speculate that it has something to do with how the computer is being used, but that's just my speculation
 

Mity

macrumors 6502a
Original poster
Nov 1, 2014
777
704
Why doesn't my M2 Air utilize swap? Why did my Intel Mac mini with 32 GB RAM utilize swap?

What I'm trying to say is I don't think it's an Intel or Apple silicon thing. I don't have an answer, obviously, but I have two cases personally where Apple silicon is not using swap currently, and my old Intel Mac utilized swap and had twice the RAM. I can speculate that it has something to do with how the computer is being used, but that's just my speculation

I doubt it's personalized. I'm taxing my 64GB Intel MBP far more. I have about 50 Chrome tabs open at all times because I hate closing out my Jupyter notebooks. I would expect those to be moved to the SSD but they don't.
 

Mity

macrumors 6502a
Original poster
Nov 1, 2014
777
704
Just so you don't think I'm joking about my Apple silicon Mac not using swap. That's with 25 days of uptime.

View attachment 2217805

Thanks for posting. I don't think you're joking. I think there's some behavior that causes it to do this. Do you use Chrome or Safari and how many tabs do you leave open? Any other apps like WhatsApp Desktop?
 

russell_314

macrumors 604
Feb 10, 2019
6,640
10,228
USA
Thanks for posting. I don't think you're joking. I think there's some behavior that causes it to do this. Do you use Chrome or Safari and how many tabs do you leave open? Any other apps like WhatsApp Desktop?
No, I avoid putting chrome on my MacBook like it's the plague. I'm fairly certain if I have chrome that would be swap used. No whatsapp. Nothing against the app but I don't know anyone else with it to message LOL

I had five tabs in Firefox and two in Safari with that picture, but I just opened up another six tabs in Firefox so total of 11 and two more in Safari and still no swap. I'm sure if I kept opening tabs it would max out the memory and force it to go into swap. I usually don't keep more than 10 tabs because the tabs get so tiny on top, and I really don't flip back-and-forth between so many tabs. I usually close the whole window if I start getting too many and start again.

I wouldn't really worry about swap. I know there was a bug in macOS where it was using quite a bit of a swap but that was fixed a while back.
 

Ethosik

Contributor
Oct 21, 2009
8,138
7,112
Do you know if turning off "hardware acceleration" in settings eliminates or reduces swap use?
For Chrome? Don't know. Some software might be designed to use up more memory if you disable hardware acceleration so it might make it worse. Just don't worry about swap. Some applications are built to use swap no matter what you do, unless you severely tweak your operating system but that causes more harm than good. I think Apple, Microsoft and the Linux community know how to manage memory. Some bugs will always be there, but just don't worry about swap.
 

Mity

macrumors 6502a
Original poster
Nov 1, 2014
777
704
Some applications are built to use swap no matter what you do, unless you severely tweak your operating system but that causes more harm than good. I think Apple, Microsoft and the Linux community know how to manage memory. Some bugs will always be there, but just don't worry about swap.

That must be it.

I asked not out of worry, more out of curiosity. I thought it was due to an architecture difference.

The only other thing I can think of is that swap may use less energy and thus help with battery life. So, if there's Chrome tab that stays open but I don't use it, Chrome or MacOS decides to store it using swap as opposed to RAM.
 
  • Like
Reactions: vitorpbarbosa7

Ethosik

Contributor
Oct 21, 2009
8,138
7,112
That must be it.

I asked not out of worry, more out of curiosity. I thought it was due to an architecture difference.

The only other thing I can think of is that swap may use less energy and thus help with battery life. So, if there's Chrome tab that stays open but I don't use it, Chrome or MacOS decides to store it using swap as opposed to RAM.
There are a few Reddit posts I have in my bookmarks on the topic, but I cannot link them as the whole Reddit situation if it will even come back. This has been a discussion with the Unix community since 2010 (maybe before who knows). Each OS and architecture acts a bit differently, but generally I have seen all three OS use swap even though there is more than enough RAM available. Depending on how any given app is developed too.
 

Analog Kid

macrumors G3
Mar 4, 2003
9,351
12,578
The OS is constantly working to ensure it's ready to be responsive, so it always wants to have some RAM available. It's always looking suspiciously at memory you haven't accessed for a while, wondering if maybe that space could be put to better use-- even if that use is keeping it empty in anticipation of another allocation. If the system decides the memory is starting to wear out its welcome in RAM, it moves it to SSD.

That's anthropomorphizing a bit, but it gets the idea across.

The other thing is that once a swap file is created, it's rarely (possibly never) deleted before a reboot. So if swap is ever used, that file will remain even if it's not currently needed. It takes time to allocate the swap file, so the system makes the assumption that if you needed it once, you're likely to need it again some time-- no sense closing the file and then reallocating it later, it's cheaper to just empty the file and hold it in reserve.

So one common reason to see a swap file and a lot of empty RAM is when the system does something, however briefly, that motivates the system to create the swapfile and then frees up all that memory later. The vestigial file is left behind. Sometimes that file is empty, if all its contents have been brought back to RAM, sometimes it still holds memory because the system just hasn't needed that data and the system doesn't see the point in transferring it over to main memory.

You've had a bunch of boxes you never open stored in the guest room, you move them to the garage when you have company, and then don't bother to bring them back to the house again until you need whats in them.

I'm not sure this is an M1 thing. It's possible that memory and SSD access times have changed leading the system to make different tradeoffs, but it's just as likely to be a difference in usage pattern, I think. Maybe someone knows something different about the M1 and can tell us differently, though.
 

Bobbuilds69

macrumors member
Jun 8, 2022
84
205
I tried Chrome out again a few weeks ago because apparently Google optimized it, but I noticed my MacBook started using Swap when it wasn’t doing it before, so I uninstalled Chrome and reverted back to Opera, and my MacBook no longer uses Swap.
 

volatility

macrumors newbie
May 8, 2023
4
5
There's no clear answer as to why the system was paging, it really depends on what exactly you did.
What could've happened is that memory was marked as inactive. Once the amount of free memory dropped, it decided to page out the inactive memory. macOS rarely releases inactive memory.

I don't think there is any direct architectural difference, I believe if there's any differences, they are just consequential

While I do lots of low-level stuff, this is just my rough understanding that I gathered from Apple's fairly decent Darwin documentation. So take it with a pinch of salt.

What I can say for sure though is that paging is not user personalized. At least it is not documented anywhere. I can't imagine how that would work, especially with the 100+ system users.

You really shouldn't be worried about paging (swapping), let the operating system do its thing, the concepts have worked pretty much the same for decades now.
 

Alex_s

macrumors newbie
Jun 14, 2023
1
1
All my swap is occupied by Opera and Chrome browsers. But the memory is enough, so I don't pay attention to it.
 
  • Like
Reactions: Tagbert

theorist9

macrumors 68040
May 28, 2015
3,845
3,033
Once data is put into swap, it can take a while to clear. And swap may not clear entirely until you reboot.

Thus the data you're seeing in swap might have been put there several hours ago when the computer actually was using a lot of RAM, and simply hasn't been removed since then. It doesn't mean it was actually putting data into swap at the time the screenshot was taken (when RAM use was low).

It's like asking why the emergency flashlights are out on the kitchen counter when the power is on. The answer is the power was out earlier, and we haven't put the flashlights away yet.

To test if your computer really is using swap when RAM requirements are low, you would need to reboot, and then be very disciplined for a day--only have one or two app windows open at a time, to ensure your memory use is consistently low. You'd need to monitor this with Activity Monitor. During this time, you would regularly check to (a) ensure your RAM usage remains consistently low; and (B) see if any swap appears.
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,990
8,874
A sea of green
To test if your computer really is using swap when RAM requirements are low, you would need to reboot, and then be very disciplined for a day--only have one or two app windows open at a time, to ensure your memory use is consistently low. You'd need to monitor this with Activity Monitor. During this time, you would regularly check to (a) ensure your RAM usage remains consistently low; and (B) see if any swap appears.
There's also a command in Terminal: vm_stat

See man vm_stat for details.
 
  • Like
Reactions: Analog Kid

Analog Kid

macrumors G3
Mar 4, 2003
9,351
12,578
To test if your computer really is using swap

If you're comfortable with the command line then this is pretty easy to check. There's a command called 'vm_stat' that tells you what the virtual memory system is doing.

If you type 'vm_stat 60' at the command line, the first line will tell you the summary since reboot and then once every 60 seconds it will print another line telling you what's happened in the last minute.

"swapouts" is the column you're interested in-- if that column is zero, then nothing has been written to disk. It's the number of 16kB pages written if you're worried about bytes.

Ignore the "pageouts" column, it's a different, more subtle, thing that's not interesting here because it's all within physical RAM, no disk access.

Every now and then, the command will reprint the column headers and the summary since boot, which is annoying, but I don't think it can be disabled so if you leave it running a long time and see big numbers periodically, it's the summary.

'vm_stat -c 11 60' will show you stats once a minute for 10 minutes. It seems to count the summary line in the "count" so you need to use a duration+1 for the count. 60 is obviously the number of seconds in this example, so you can set it to something shorter or longer depending on your interest.
 

zonai

macrumors 6502
Sep 16, 2022
336
555
The newer versions of Chrome have a feature to offload unused tabs’ memory usage, a lot of times that spills into the “cached files” section because I’ll see large sizes there and less in memory used. But I have about 3GB of swap on my 32GB M1 Pro and it kind of drives me crazy that sudo purge only cleans cached files and not swap. But I think running sudo purge with a large cached files would prevent going to swap as often.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.