by crazygringo · 3y ago · 0 comments
Huh? When the system is getting close to running out of memory, isn't the least-recently-used memory swapped out to disk by the OS? And if you're using an SSD like nearly everyone these days, it isn't even noticeable.
Freezing tabs is a good idea to ensure the memory stops being accessed precisely so it can be swapped... but besides this, why not let the browser use all the memory it needs, and just let swap do its job? It seems entirely redundant for a browser to try to save memory by essentially implementing its own secondary swap strategy.
After all least-recently used memory is swapped out, the time comes to swap out recently used memory and it becomes noticeable, especially with a spinning disk with 400Kb/sec random write speed.
Swapping is extremely ineffective. Unloading a tab allows to use sequential write which is orders faster than random write even with SSD.
For keeping things open in the background that aren't being actively used, swapping is extremely effective.
I don't see any good reason why background applications should get swapped out by the OS, but background tabs should be handled by a different mechanism.
(And I have no idea what sequential write has to do with anything...? If you're talking about coming back to an old tab, loading it from swap will nearly always be faster than reloading over the internet, no?)
For HDD, sequential write speed can be 50 Mb/s and random write speed for 4Kb chunks can be as low as 400 Kb/s. For SSD, there is also a difference in speed on order of 50x.
Swapping uses 4Kb chunks and therefore uses the drive in the most inefficient mode. Alternative mechanism can employ faster and effective sequential access.
The only performance issues that are actually relevant here are if you get into thrashing because you've run out of memory totally (no longer pre-emptive), but that doesn't happen in normal usage. Or when you're swapping memory back in for an app/page that's scattered among many 4 KB pages on disk... but the point is that should still be faster than reloading the page over the internet! (And on SSD's it's blazingly fast since fragmentation on disk barely even matters.)
If swap needs to write 10 MB, in whatever chunk size, it will send them one after the other, just like the file system. Regular file systems don't have 100 MB sector sizes, either.
> For SSD, there is also a difference in speed on order of 50x.
I highly doubt that. Source: running fio on my SSD. SSDs actually can take advantage of parallelization, writing to multiple places at the same time, which a spinning drive obviously can't do.