Should I keep my swap file on an SSD drive?

82

25

I'm considering getting an SSD drive to run as the primary OS partition. As I understand, this should provide a substantial improvement in performance.

  • My question is this: Should I leave the swap file on that drive?

The swap partition will be largely random seeks and so should benefit from the speed. On the other hand, it will be constantly written to which will wear out the drive faster.

Steve Rowe

Posted 2009-10-06T14:33:42.273

Reputation: 3 729

We've made a blog post about Maximizing the lifetime of your SSD

– Tamara Wijsman – 2011-05-10T15:06:34.573

3Attention: There is only a limited amount of memory given to drivers, called the non-paged and paged pool memory sections. A page file is necessary for when the paged section gets full, as a gamer I have seen a game complain about paged pool memory just because I had my page file disabled on a 8 GB system. Conclusion: Page files are necessary, they prevent paged pool depletion and actually do speed up your system. – Tamara Wijsman – 2011-10-24T16:32:04.453

http://www.storagesearch.com/ssd-buyers-guide.html This should provide accurate info. – Xavierjazz – 2009-10-26T00:56:28.423

1But nowadays, Macbook Air for example, only has an SSD... so you can't avoid having the pagefile in the SSD, unless you disable the pagefile altogether... – nonopolarity – 2011-12-02T15:18:45.007

3

Please check out this article. http://www.storagesearch.com/ssdmyths-endurance.html 51 Years!!!

– Xavierjazz – 2009-10-07T23:19:13.733

I remember they used to say cd's are going to last on average 30 years, when they were introduced. Now this ... but looking at history, every new generation of storage media lasts less and less ... I'll stick with old HDD's for now. They seem to last pretty long. – Rook – 2009-10-08T00:22:39.623

I do believe the rumors of SSDs wearing out so quickly are exaggerated, but 51 years seems a bit of a stretch... Plus, it's largely theoretical at this point because SSDs are so new. I'd wait a few years until more info comes out about this before even getting an SSD, let along putting my pagefile on one. – Sasha Chedygov – 2009-10-26T01:07:35.990

someone said something about buying more ram i have seen some systems with crazy amount of ram that you would put on a server for the desktop user or gamer or graphic design artist that wants speed there is a point where too much ram would slow down a system as the mem controller ( in cpu or northbridge ) can not handle the amount of ram simply because they do not have the bandwidth thus a smaller amount of ram that the mem controller can handle would be much better, i hope that people remember this but many companies build computers with heaps of ram because its Cheap it makes numbers look bi – None – 2012-02-11T13:31:41.947

Answers

9

If possible, you might want to use a secondary platter hard drive as the location for virtual memory. If you don't have one, it's still recommended to have a page file, but you might want to disable it for extra disk space. It's all up to you whether to decrease memory load or more disk space is important...

Molly7244

Posted 2009-10-06T14:33:42.273

Reputation:

http://www.codinghorror.com/blog/2011/05/the-hot-crazy-solid-state-drive-scale.html - from Jeff Atwood. SSD lifetime is short enough already, do not put a page/swap file on it. – Breakthrough – 2011-07-24T18:35:33.233

The document is for Windows XP, I don't think Windows 7 requires you to have to change any settings. – David d C e Freitas – 2011-11-16T08:10:08.410

11This answer is plainly incorrect. I downloaded the linked document on 11/22/2011. 1) the quote given is incorrect. The full quote is: "We recommend disabling page file for a 2 GB flash storage device because of the potential impact that the page file has on the flash storage device lifetime, and the reduced free space for additional applications and user data on the flash storage device." 2) it is clear that MS are talking about typical USB and SD flash here, not SSD. – user4197 – 2011-11-22T10:32:54.163

8Odd. Last time I suggested SSDs have limited lifetimes compared to regular HDDs (for the same usage), I got downvoted. – Manos Dilaverakis – 2009-10-06T15:17:56.477

well, in this case i'm just the messenger, and they don't get shot anymore :) however, an accurate answer would pretty much depend on the specifications of the SSD which we don't know, quite possible that paging would perform better on a platter hard drive with a big cache memory. – None – 2009-10-06T15:22:18.747

6The quote is incomplete. The recommendation is for a 2 GB device. In that case pagefile would occupy a significant percentage of drive greatly reducing free space and increasing wear of individual cells. A 64 GB drive has more cells to distribute this wear over. I guess SSD manufacturer's recommendations would be more useful. If swap is seldom used it shouldn't cause much wear but an SSD could really help at those rare times when swapping suddenly causes insufferable slowness. – Bender – 2009-10-06T18:50:52.540

28does paging have an impact on the lifespan of SSDs? yes, but so does ANY write operation. do i care? hell, no! if the bleedin' thing goes down after 3, 4 or 5 years, so what? by then we will see SSDs 10 times faster than today's technology and it's time to move on anyway. or do you much care for a 5 year old 5400 RPM HDD with maybe 80 GB capacity? i rather doubt it :) – None – 2009-10-06T19:37:55.300

3@Phoshi: I think the technology is too new to judge that, because any estimates are completely theoretical at this point. No one (to my knowledge) has actually left an SSD running long enough to test its lifespan. – Sasha Chedygov – 2009-10-26T01:09:35.897

gotta agree with musicfreak here. current gen SSDs haven't actually existed for comparable lifetimes yet. let's check the data 5 years from now and see. – quack quixote – 2009-10-26T01:20:00.663

65

From MSDN Blogs > Engineering Windows 7 > Support and Q&A for Solid-State Drives:

Should the pagefile be placed on SSDs?

Yes. Most pagefile operations are small random reads or larger sequential writes, both of which are types of operations that SSDs handle well.

In looking at telemetry data from thousands of traces and focusing on pagefile reads and writes, we find that

  • Pagefile.sys reads outnumber pagefile.sys writes by about 40 to 1,
  • Pagefile.sys read sizes are typically quite small, with 67% less than or equal to 4 KB, and 88% less than 16 KB.
  • Pagefile.sys writes are relatively large, with 62% greater than or equal to 128 KB and 45% being exactly 1 MB in size.

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.

user68795

Posted 2009-10-06T14:33:42.273

Reputation:

1@PPC "Pagefile.sys reads outnumber pagefile.sys writes by about 40 to 1" So, no. (Also, the last sentence wouldn't make any sense if that were true. So, again, no.) – David Schwartz – 2016-10-18T17:41:18.823

2@DavidSchwartz: The problem is not number of writes compared to number of reads, it's more a number of writes per day, compared to the SSD endurance, and the placement algorithm by the OS. See Xavierjazz' note above on OP – PPC – 2016-10-20T06:53:49.777

9There is no doubt it will go faster. What this article does not discuss is whether this would cause excessive SSD wearout – PPC – 2012-08-10T16:00:57.433

19

Here is some S.M.A.R.T. data from an OCZ-AGILITY SSD that I have used in a Linux laptop for around two years.

I have a swap partition on the disk, and the only "tweak" I've made is to set swappiness = 0 in Linux. The windows swap profile is more or less like Linux swappiness = 0.

It's my personal laptop, so it's not used 8 hours a day (more like 1.5 hours), but I do quite a lot of development on it, so there is a lot of file creation going on.

  9 Power_On_Hours          1199
 12 Power_Cycle_Count       2753
184 Initial_Bad_Block_Coun  0
195 Program_Failure_Blk_Ct  0
196 Erase_Failure_Blk_Ct    0
197 Read_Failure_Blk_Ct     0
198 Read_Sectors_Tot_Ct     1311815826
199 Write_Sectors_Tot_Ct    1546123387
200 Read_Commands_Tot_Ct    22347850
201 Write_Commands_Tot_Ct   31599623
202 Error_Bits_Flash_Tot_Ct 55136
203 Corr_Read_Errors_Tot_Ct 54890 
204 Bad_Block_Full_Flag     0
205 Max_PE_Count_Spec       10000
206 Min_Erase_Count         266
207 Max_Erase_Count         2166
208 Average_Erase_Count     842
209 Remaining_Lifetime_Perc 92

The interesting parts are:

  • Power_On_Hours (I spend too much time in front of a computer.)
  • Max_PE_Count_Spec is 10000, which is the minimum number of reflashes a block can cope with.
  • Min, Max and Average Erase count tells a little bit about the robustness of the wear-leveling algorithm. I suppose it's quite OK that the worst block has been flashed about two times more often than average.
  • The remaining lifetime percentage, which is 92%.

So... I think it's safe to assume that the disk should last until I retire it for other reasons. (*touch wood) It's already too small...

Assuming the numbers scale, 40 hour/week would give a life time of at least 3-4 years - probably more, since I suspect I am more efficient at wearing out my disk at home... Fewer meetings... So, I think it's quite OK for a work machine, given the benefits.

100% / (40h/(1199/(2*52w)) * 8% = 3.6  // Did I get that right, eh...

So, my advice is: Get rid of the noisy mechanical drives and enjoy the silence :-)

It's awesome with an absolutely quiet laptop.


I retired the drive some time ago, after more than 5 years in service. I needed a bigger drive, and it was also nice to get a faster one. Some blocks have definitely died, but it looks like it could hold together a few more years.

By the way, it certainly survived the laptop it was originally installed in.

9 Power_On_Hours                  3965
12 Power_Cycle_Count              8755
184 Initial_Bad_Block_Count          0
195 Program_Failure_Blk_Ct           0
196 Erase_Failure_Blk_Ct             0
197 Read_Failure_Blk_Ct              0
198 Read_Sectors_Tot_Ct     5438181603
199 Write_Sectors_Tot_Ct    4223860468
200 Read_Commands_Tot_Ct     108147770
201 Write_Commands_Tot_Ct     87443515
202 Error_Bits_Flash_Tot_Ct     364621
203 Corr_Read_Errors_Tot_Ct     350922
204 Bad_Block_Full_Flag              0
205 Max_PE_Count_Spec            10000
206 Min_Erase_Count                940
207 Max_Erase_Count               7808
208 Average_Erase_Count           3119
209 Remaining_Lifetime_Perc         69
211 SATA_Error_Ct_CRC                0
212 SATA_Error_Ct_Handshake          0
213 Indilinx_Internal                0

user27163

Posted 2009-10-06T14:33:42.273

Reputation:

But swapiness = 0 means: swap only to avoid out of memory (and the default is 60), source: http://en.wikipedia.org/wiki/Swappiness

– Lukasz Czerwinski – 2013-06-03T08:33:53.600

Yes, reducing swapping somewhat, not disabling it. Plus, I rather wait for file operations than when alt-tabbing between windows... Btw, after almost two years, or 3018 power-on hours, the estimate remaining lifetime percentage is now 77 %. – None – 2013-06-03T20:57:42.277

19

I have a better answer: Why, when you can just buy more RAM? RAM is as cheap or cheaper than SSD space. It's also much faster, and it will never (well, almost never) degrade like SSD drives do.

Swapping memory to disk is a symptom of not enough RAM. If you need to speed up swapping, don't speed up the swap disk, upgrade your RAM and the swapping will go away. Swapping should be considered a last-resort backup plan anyway.

Ernie Dunbar

Posted 2009-10-06T14:33:42.273

Reputation: 679

-1 For being full of your self, +0.5 for having an OK answer; Then I rounded up. Admittedly, I have kept swap enabled for those rare times I pushed into the paged space and it crashed my OS before I had a chance to catch it. Now if it pages, I can usually tell and kill something before bigger issues arise. – Damon – 2015-05-22T09:09:19.327

RAM is not cheaper than SSD space anymore, and maybe your motherboard is already at its maximum RAM capacity. I've got 64GB in my workhorse machine; can't go any higher. – sudo – 2016-01-01T18:49:50.063

13Not anymore. Currently, SSD is about 4 times cheaper than RAM. Having a swap file is always good for throughput, no matter how much RAM you have (although it may impair responsiveness). – maaartinus – 2011-02-06T00:16:14.690

@maaartinus Yes cost per GB storage is better than RAM but what about (MB/s)/$? the OP cares about speeding up his system, not storage.

Normal current gen SSD drives have a transfer rate of about 280MB/s, the cheapest I could find on newegg with that speed was $99. DDR2 800 ram (very common) has 6000 MB/s transfer rate, 4Gb for $56. So SSD is 2.8 (MB/s)/$ and RAM is 107.4 (MB/s)/$.

Yea, you can fudge the numbers and use really expensive RAM and a cheep SSD, but even then I don't think SSD would be cheaper in throughput. – Scott Chamberlain – 2011-06-23T21:32:28.373

1@Scott Chamberlain I agree that using RAM leads to higher speed. Depending on the system, it may be the way to go. When you need a lot of memory, the RAM can get just too expensive, while you can get very good performance with the much cheaper SSD. The much higher throughput of the RAM need not influence the global memory throughput much, since most of the operations get done in memory anyway (you could consider the RAM as a sort of cache for the much larger SSD). The optimum lies quite often somewhere in between (i.e. buying some more RAM and some SSD). – maaartinus – 2011-06-23T23:25:51.197

11

A lot of people are saying "don't swap if you can help it", but this is misleading, at least for Windows (and probably for Linux too). Windows, esp. recent versions, will always try to fill up RAM with cached data that it thinks is going to be needed quickly, and will deliberately swap other stuff to disk. It does this irrespective of how much RAM you have. I have 4GB, only half in use, but swapping still happens. Disabling swapping is a bad idea too, because some programs can require huge amounts of memory reserved for them (think Photoshop), and you can easily get out of memory messages. It depends on usage, but swapping is always useful to have for extreme situations.

So SSDs are not a replacement for RAM (saying "get more RAM" is missing the point) but a possibly faster alternative to virtual memory on hard disks. Take a look at this review to see how SSDs can leave mechanical hard drives in the dust: "Hard-Drive Roundup June 2010"

Also remember it's the IOPS figure that's far more important than the transfer rate.

Another thing to consider is whether your current swap drive is also your main drive. For most people, the answer will be yes. That means the hard drive is having to access paged virtual memory whilst also accessing data and programs. In this case, having an SSD for paging is likely to make a noticeable improvement.

I'm looking for somebody who's tried this to give definitive info on performance, but on paper the case looks clear-cut.

David Pritchard

Posted 2009-10-06T14:33:42.273

Reputation: 111

Windows will not "swap other stuff to disk" in order to make more room for cached data, unless it's really unimportant data. – Jamie Hanrahan – 2019-03-03T03:01:02.797

2

Patrick Regan's answer about "swappiness" is pretty spot on: Depending on your usage, it might be fine, and if you're using Linux you can tweak "vm.swappiness" in sysctl (as described in an earlier question) for your use.

So I'm tempted to say yes, as long as you give lots of disk to your swap. I've been hearing lots about the internal controllers on SSD drives having super-tweaked algorithms to combat write wear, so in theory this would help -- give it lots of space, and set the kernel swappiness level low, and the SSD controller can spread the writes out and prevent any wear trouble.

So that got me to wondering what the largest swap partition could be. I locked onto your mention of "swap partition" and thought "Linux", so I looked into the maximums there.

It turns out you can create ridiculous things like 16 TB swap partitions, at least based on the kernel math. mkswap might not be able to actually initialize that partition, but the kernel supports it. However, the kernel can't use it. According to this, 16 GB is about the biggest swap partition you can make and use in a modern Linux kernel.

So yes, you can, if your usage is going to be fairly swap-free. If you'll be swap-heavy, though, maybe a cheapo USB key for ReadyBoost (or the Unix equivalent) would be a better fit -- that way when your swapping destroys the device from overwriting, it'll be cheap to replace and won't cost you the price of another SSD.

quack quixote

Posted 2009-10-06T14:33:42.273

Reputation: 37 382

3Without knowing the detail of the write-wear algorithms, you can't know that a larger partition will help. I was under the impression the write-wear algorithms worked at the page level, regardless of partitioning since the SSD is random-access. The whole point of those algorithms is to avoid excessive wear so why wouldn't they use the whole drive to spread the writes, even for small partitions? – Ben S – 2009-10-06T15:03:55.547

fair point. i was assuming the spread would be limited to within partitions. i guess the counterpoint would be that maintaining a list of what-page-is-where would get too out of hand if you didn't do some limiting, but we really don't know. – quack quixote – 2009-10-06T15:15:10.833

1

2016 Update

Performance

Some more fresh data about SSDs nowadays. They typically read, write 500 MB/s. A normal decent RAM's I/O is around 10-20 GB/s. However PCI-e SSD exist; they do have a good I/O rate (1-2 GB/s), but still they do perform like RAM in early-mid 2000s.

Performance ratios are:

  • If RAM is 100%
  • PCI-e SSD is around 10%
  • SSD is around 2,5-5%
  • HDD is around 0,25-1%

If you did have an HDD, your virtual memory might get a good increase in performance.

Price

Regular SSD became cheap, but PCIe SSD with good I/O is not really cheap yet. Just do the math; out of PCI-e SSD price you can buy a new motherboard with new RAM, and voila, problem solved.

On the other hand, since SSD became more affordable, they are very much available for low money, and actually I will reuse my old 96 GB SSD as virtual memory. I can't really sell it, so I can use it for virtual memory. Well, why not? It is still better than an HDD. If you have to have a page file, put it on a legacy drive.

Reliability

The following test shows that many of them fail after a while.

Failure

100-600 terabytes are really a lot of I/O, and if you have let's say 48 GB virtual memory, if you read and write all in and out, it means at least 2000 iteration before the first bad sectors, but if you have a reliable disk, it is more like 10000 or more. I would assume it is more than two or three years of usage.

Sum

I would use it as a virtual drive if I really need it, but if it is an available option, just expand your RAM as far as you can in necessity. Use this virtual memory only if you run out of options. On the other hand, you can use your older SSD for this purpose, and you can replace it for 30-40 USD any time if fails (probably won't for a long while), it can be useful.

PCI-e SSD for virtual memory: if you want to burn money, or if you have absolutely no other choice.

One last sidenote: if you now have only HDD, go and get an SSD, migrate your operating system, you will feel like you bought a new computer.

CsBalazsHungary

Posted 2009-10-06T14:33:42.273

Reputation: 111

1

Although the random read of SSD drives is very good, the random write performance can be very bad. Apparently some SSDs only provide 12 write IOPS, which is only a tenth of what a standard rotational disk provides(~120 IOPS), and even faster SSDs like the Super Talent SSD may only provide 50 random write IOPS.

On the other hand, it is possible for an SSD to perform thousands of operations per second, for example the Intel X25-M 160 GB 34 nm MLC G2 can perform 86001 (according to the Intel specification sheet) or even 153342 random write IOPS of 4k blocks.

So in conclusion, the swap performance of your SSD may well be better, but do not assume that this will be the case until you have checked the number of random write IOPS your SSD can achieve.

[1]: http://download.intel.com/design/flash/nand/mainstream/322208.pdf

[2]: http://www.legitreviews.com/article/1022/6/

gmatht

Posted 2009-10-06T14:33:42.273

Reputation: 2 084

3

It's pretty easy to check the IOPS before you buy now. if you take a look over ssd review, you'll see even the cheaper SSDs (I bought the one below for $130) are able to achieve 1700 IOPS. http://www.ssdreview.com/review/compare/kingston-ssdnow-v-100-64gb-25-inch-d100811a/iometer.html -- compared to a 7200rpm barracuda: http://www.ssdreview.com/review/compare/seagate-barracuda-xt-720012-st32000641as-2000gb-35-inch-cc13/iometer.html (300 iops) I'm not sure that 15k drives fair much better. You'll notice quite a few SSDs that are breaking 3k IOPS nowadays.

– cgp – 2011-03-21T03:19:44.570

0

FWIW: I've been using my pagefile.sys on my Intel SSD, for 10 months continuously. I don't know about Windows Vista or newer, but on Windows XP turning OFF the pagefile seems like a really bad idea. Windows must thrash on something, so thrashing on an SSD is much better than thrashing on a traditional HD ;-)

If this actually decreases the lifespan of the SSD, so what? I'll be buying larger ones probably once / year as the prices continually drop. At this exact moment in time, you will spend about US$2 / GB.

Chris O

Posted 2009-10-06T14:33:42.273

Reputation: 279

0

I would be inclined to say that the performance gain from it is not worth it, especially if you have a lot of RAM. If you have at least 2GB RAM, you probably won't page a ton anyway so the benefits would be minimal. Not to mention that SSD sizes are relatively small, so you may not want to eat up a few GB worth of pagefile on it anyway.

MDMarra

Posted 2009-10-06T14:33:42.273

Reputation: 19 580

0

I think it would depend on how much RAM you have and how your "swappiness" is set. I have a swap set up on my computers, but if I don't hibernate, I rarely write to it. I tend to not max out my RAM usage. But if you know you're hitting swap a lot, I'd say no. If you don't hit it a lot, I'd say go for it.

Patrick Regan

Posted 2009-10-06T14:33:42.273

Reputation: 174

2Well, if you're not using swap a lot, you won't benefit much from the speed too, so I would prefer leaving the swap in a traditional HD, for wear and space reasons. – R. Martinho Fernandes – 2009-10-06T14:47:40.987

This is true. I guess I hadn't thought of it that way. – Patrick Regan – 2009-10-06T14:56:42.753

-1

Unless you need the swap file (for suspend to disk for example), I would simply turn swapping off and get rid of your swap partition.

The point of swap is to provide an extra cache level. Since your SSD has a low latency, the gains of using swap are much lower.

If your system hardly ever swaps, then it makes even more sense to just get rid of it. I've been running a few Linux boxes without any swap for a few years now (on regular hard disk drives) without performance issues. Any box with more than 2 GB of RAM I just don't bother with swap for.

Ben S

Posted 2009-10-06T14:33:42.273

Reputation: 1 902