Can someone quite technical explain what exactly occurs when you run out of RAM? For e.g. let's say I have Safari open with 12 tabs and I'm using 7gb ram system wide. Then I open 8 more tabs which puts me at 8gb ram usage. Does it simply take the first few tabs of the browser and save it to ssd memory or something? When I go back to the first few tabs, will they load much slower because they are loading from ssd memory at this point. Any explanations or analogies would help me - thanks!
I'm not a technical person for this stuff but here are my 2¢:
Note that the OS makes use of compressed RAM (since Mavericks or something like that) and also caches applications.
So, in theory, your 8 GB RAM sort of functions like 16 GB RAM since there is a 2:1 memory compression ratio. Also, macOS tends to fill up RAM regardless if it needs to or not. The RAM that is not necessarily needed gets filled up with previously opened applications that are no longer used. That way if they are accessed again, they are immediately available with no delay. However, if macOS determines it needs that memory that is being utilized by cached applications, it can simply empty that cache and use it for what is needed.
So, people who see that 7 GB is used doesn't mean they're nearly out of RAM. You can easily use more than 8 GB and still not be out of RAM on an 8 GB machine.
However, as the needs for more RAM increase, eventually the OS may save some of this to SSD, as swap memory. This is slower and can cause delays, but the good news is that current SSDs are so fast that often it's not really that slow, especially if the amount of swap used isn't that much.
Put it this way:
With my 2014 Core i5 8 GB Mac mini with NVMe SSD, with extended use I'd usually have some swap, but often it was quite small. I wouldn't really notice any delays until I hit over 1-2 GB swap, but when it was less than that, I'd usually not notice it. I'd notice slow downs when the swap got bigger. In my experience, Safari with a bunch of tabs is usually not a problem, but it becomes problematic if you're also running a bunch of other memory hungry applications as well.
On my 2020 M1 16 GB Mac mini, with the same extended use I usually don't have any swap at all, but even the times I do hit the swap I notice it even less, probably because the SSD is so much faster, and the CPU is so much faster too.