On modern Unix-like systems such as FreeBSD, “swapping” refers to the activity of paging out the contents of memory to a disk and then paging it back in on demand. The page-out activity occurs in response to a lack of free memory in the system: the kernel tries to identify pages of memory that probably will not be accessed in the near future, and copies their contents to a disk for safekeeping until they are needed again. When an application attempts to access memory that has been swapped out, it blocks while the kernel fetches that saved memory from the swap disk, and then resumes execution as if nothing had happened.
[…]In 2021, cheap SSDs have become commonplace and have performance characteristics much better suited to swapping, so it seems worthwhile to revisit how swapping works in FreeBSD, and try to provide some insight into frequently raised issues.
Some light reading for the weekend.
“On modern Unix-like systems ” – like, for ever? I mean this has always been the definition of swapping? Also, though SSDs might have performance characteristics suited to swapping, having too little memory will wear the SSD out relatively quickly.
jal_,
Yes, occasional writes aren’t too bad but if you have continuous swapping it would definitely consume lifespan faster than otherwise. Over time SSD lifespans have been getting worse, and with QLC on the horizon indicators point it will continue to get worse.
Expensive enterprise may use more SLC cache and a ton of over-provisioning in the bulk cells to replacing those that die, but in cheap consumer drives I would be wary of access patterns that contribute to constant writes. Filling up RAM and allowing the system to swap is one such pattern. Fortunately most computers have plenty of RAM these days with 8-16GB being common and 16-64GB being readily available.
Both for perfomance reasons as well as avoiding SSD writes I use a memory disc for my browser caches. Okay, they are wiped on reboot but this is no bother.
Once upon a time, before hardware paging was commonplace, “swapping” meant moving entire segments or processes out to disk and bringing them all back in at the same time (rather than bringing uniform pages in on-demand). So I suppose not “forever”, the “modern” qualifier is reasonable.
Apparently FreeBSD at one point would revert to swapping behaviour (implemented using paging but for entire processes) under heavy memory pressure, but I can’t easily work out whether that’s still the case.
The article seems to imply desperation swapping is no longer used, in its discussion of OOM killer behaviour.
The1stImmortal,
Thanks for the historical context, although the article explicitly uses the “modern” definition.
I agree with jal_, the “modern” qualifier is odd for describing techniques that have been used since before I started computing. He’s got to be quite old to consider swapping a feature of “modern unix”, haha. Even much newer technologies developed in my time are considered “ancient”, like the netscape browser, active-x, ICQ, etc. Oh well not a big deal, just peculiar.
I think we just parsed the initial sentence differently. I read it as “On modern Unix-like systems (as opposed to on older Unix-like systems)”, whereas other people seem to be reading it more like “On modern Unix-like systems (as opposed to systems not like modern Unix)”.
From my interpretation, the “modern” qualifier is what distinguishes the use of paging from swapping, whereas in the other interpretation it is indeed somewhat superfluous.
Fun with English, I suppose.