Archives

Categories

Swap Breaking SSD

I’ve seen many comments about swap space and SSD claiming that swap will inherently destroy SSD through using too many writes. The latest was in the comments of my post about swap space and SSD performance [1]. Note that I’m not criticising the person who commented on my blog, everyone has heard lots of reports about possible problems that they avoid without analysing them in detail.

The first thing to note is that the quality of flash memory varies a lot, the chips that are used in SSDs for workstation/server use are designed to last while those in USB-flash devices aren’t. I’ve documented my unsuccessful experiments with using USB-flash for the root filesystem of a gateway server [2] (and the flash device that wasn’t used for swap died too).

The real issue when determining whether swap will break your SSD is the amount of writes. While swapping can do a lot of writing quickly that usually doesn’t happen unless something has gone wrong. The workstation that I’m currently using has writes to the root fileystem outnumbering writes to swap by a factor of 130:1 (by volume of data written). On other days I’ve seen it as low as 42:1, in either case it’s writes to the root filesystem (which is BTRFS and includes /home etc) that will break the SSD if anything. For some other workstations I run I see ratios of 201:1 (that’s with 8G of RAM), 57:1, and 23:1. In a quick search I couldn’t find a single system I run where even 10% of disk writes were attributed to swap. This really isn’t surprising given that adding RAM is a cheap way to improve the performance of most systems. If a SSD didn’t do any write leveling (as is rumored to be the case with cheap USB flash devices) then swap use might still cause a problem because of the number of writes in a small area, but if that was the case then filesystem journals and other fixed data structures would be more likely to cause a problem – and any swap based breakage would break swap not the root filesystem (although if swap was the first partition then it might also break the MBR).

Of the workstations that are convenient to inspect the one with the most writes to the root filesystem and swap space (IE everything on /dev/sda) had 128G written per day for 1.2 days of uptime, but that involved running a filesystem balance and some torrent downloads (not the typical use). Among the two systems which had been running for more than 48 hours with typical use the most writes was 24G in a day. If a SSD can sustain 10,000 writes per block (which is smaller than quoted by most flash manufacturers nowadays) and has perfect wear leveling (which is unlikely) then the system with a 120G SSD and 128G written in a day could continue like that for almost 10,000 days or 27 years – much longer than storage is expected to work or be useful. So for workstation use (where even 24G of writes per day probably counts as heavy use) a 120G SSD that can sustain 10,000 writes per block shouldn’t be at great risk of wearing out.

Conclusion

I believe that swap is much less likely to break SSDs than regular file access on every system with a reasonable amount of RAM. For systems which don’t have enough RAM you probably want the speed of SSD for swap space anyway in spite of the risks.

If wear leveling works as designed and the 10,000+ writes per block claims are accurate then SSDs will massively outlast their useful life. Long before they wear out they should be too small, too slow, and probably not compatible. 26 years ago I had a 5.25″ full height ST-506 disk in my desktop PC, it wouldn’t physically fit in most systems I own now (unless I removed the DVD drive), there is no possibility of buying a controller (I don’t own a system with an ISA bus), and that disk was too slow and small by today’s standards. A 27yo SSD isn’t going to be useful for anything, even for archive storage it’s no good as no-one has tested long term storage and data could decay before then.

2 comments to Swap Breaking SSD

  • Daniel Andersson

    I have heard similar “it’s dangerous to put swap on the SSD”-sentiments from Windows users for a long time, again often without numbers to back this up. I have used Support and Q&A for Solid-State Drives [blogs.msdn.com] (signed off by Steven Sinofsky in 2009; actually just a month or so before he became president of the Windows Division at Microsoft) as a goto link in those cases, where the author among other things states:

    In fact, given typical pagefile reference patterns and the favorable performance characteristics SSDs have on those patterns, there are few files better than the pagefile to place on an SSD.

    also based on some typical usage metrics. So, the conclusion of the current page is most likely transferable to Windows users as well.

    A practical reason for many to avoid placing the swap file on the SSD is storage space. Especially when 40/60/80 GB SSD sizes were common, home users with appreciation for PC gaming avoided putting the swap file on the SSD since space was limited — but again, the swap file is probably one of the most obvious files performance-wise to actually have on the fastest media (in particular regarding access time), and it seems that it should be prioritized higher than having e.g. 35 GB of uncompressed Titanfall audio available at blazing-fast access times.

  • etbe

    Large portions of the overall design of all modern OSs were copied from ancient Unix systems. The basics of paged virtual memory, file based disk access, memory mapped files, and disk caching are common enough between BSD Unix, Linux, NT, and OS/2 2.x are similar enough that at a conceptual level they are pretty much identical for memory and disk access. When comparing different OSs it’s just a matter of quantity, the amount of RAM needed to avoid swap and the storage space needed for the OS image vary a lot, but the concepts are the same.

    As an aside one thing I’ve idly considered is using a RAM disk on a server as a swap space, sending data over GigE should be faster than writing it to local disk. Of course rebooting the server would force a reboot of the workstation in that case.

    Regarding the space used for swap. If you use a regular disk then the disk speed significantly limits the useful swap size, getting more than 2G of swap used on rotating media without terrible performance is fairly rare. Even the first SSDs had enough space for 2G of swap.

    But for the type of people who buy Alienware PCs (which seem to be some of the most expensive gaming PCs available) there shouldn’t be an issue of using much swap, they should just have enough RAM. One thing you’ll want to do for best gaming performance is not have anything else running. It’s not like the workstation I’m using now which has open PDFs, MS-Office files (in LibreOffice), lots of Chromium tabs, an MUA, lots of SSH sessions, and sometimes a compile all running at once.