18

I was trying to enable hibernate on my laptop, when I came across this post, where enabling hibernation on an SSD disk is discouraged.

Then I saw, that that post was four years old. Has anything changed between 2015 and 2019, or should I still not enable hibernation on my laptop's SSD disk?

Melebius
  • 11,431
  • 9
  • 52
  • 78
OZ1SEJ
  • 1,235
  • 3
  • 19
  • 31
  • 4
    I have swap on all my SSDs with hibernation. Hibernation takes very little resource of SSD compared to normal use. It was paranoia then and now there is no reason not to have swap on SSD at all. – Pilot6 Aug 13 '19 at 18:32
  • 2
    You could always run sudo swapon -a when you're about to hibernate, and then sudo swapoff -a when the system has returned from hibernation. – RonJohn Aug 14 '19 at 04:25

2 Answers2

22

Todays SSD are much larger than they were 4 years ago, making the write cycles involved from hibernating less significant for wearing.

Modern SSD come with 100-300 TBW (terabytes written), i.e. are guaranteed to be able to write 100-300 TB before they fail. This seems to be be plenty but consider that with each hibernation you may write up to the whole amount of RAM you have built in. Each hibernation will in the worst case write 16 GB of data on a laptop with 16 GB of RAM.

A SSD with 100 TBW will then last for

100.000 : 16 = 6250 hibernate cycles
4 hibernations a day makes this 1562 days or
4,3 years

Note that during these 4 years we just hibernated. We had not written anything else on the SSD.

Of course the kernel compresses RAM before writing, there are SSDs that come with 300 TBW or more, we may only want to hibernate once a day, or we have 4 GB of RAM only, so the time span until the drive fails may be much longer.

Still today, hibernating contributes significantly to the the write load on a SSD. Booting from SSD will not write much of data on the other hand. For low RAM machines that don't hibernate too often the life span of a modern SSD may be sufficient.

Takkat
  • 142,284
  • 5
    Good to hear some common sense after all of the FUD re SSDs. I have 2 Crucial - MX500 2 TB 2.5" SSDs and these have TBW of 700TB. So the life of the SSDs will be significantly greater than the life of the system itself. One upvote from me :) – andrew.46 Aug 13 '19 at 22:48
  • 3
    Note that the manufacturer-listed TBW is an extremely conservative estimate: the Tech Report performed an experiment to determine what the actual TBW value is, and all of the tested drives achieved at least double their rated TBW without failure. And this was with older, smaller drives. It's also important to note that after the drive has exhausted its writes, it will still remain readable, so you won't lose any data. – Ian Kemp Aug 14 '19 at 06:24
  • 3
    Does hibernation write all of the RAM to disk? Or just the parts used? It wouldn't seem to make any sense to write e.g, cached disk data to the hibernation image since it's already on the disk. – ilkkachu Aug 14 '19 at 08:46
  • 4
    @ilkkachu It only writes what's used. Interestingly, that does seem to include part of cache... I did a quick test on a system with Linux 4.19; it has 32GiB memory, of which about 4G was used by programs, and 14G by buffer/cache. According to the logs, it wrote about 10G during hibernate, and after resume memory usage was about 4G + 6G buffer/cache. So it looks like it only saves what is used, and "used" includes some of the caches, but not everything. I have no idea how it determines what cache to keep, and what to discard. – marcelm Aug 14 '19 at 10:15
  • @marcelm, huh, weird. – ilkkachu Aug 14 '19 at 10:20
  • 2
    The file size is set as kernel parameter to 2/5 of RAM. See this question. Making this file larger will speed up hibernation if you have a large enough SSD. – Takkat Aug 14 '19 at 10:25
  • So if hibernation is used overnight with suspend for shorter periods you get to 17 years, which is presumably greater than the expected lifespan of the hardware anyway. Longer still if the machien is only used 5 days a week. – Chris H Aug 14 '19 at 12:55
  • @Takkat Ah! That explains why my image was ~10GB, and why it kept ~6GB caches. But how would a larger image speed up hibernation? It would require writing more to disk, after all. – marcelm Aug 14 '19 at 14:10
  • This answer is significantly wrong in that hibernating a system with 16GB of ram does not use 16GB of swap. That would only be the case if all 16GB were filled with anonymous/dirty pages - roughly speaking, if applications had allocated (via C malloc or similar in other languages) nearly 16GB of memory. In reality, most of your memory is page cache backed by files on disk, meaning it can just be discarded under memory pressure or when hibernating; it doesn't need to be written out because the kernel can regenerate it on demand by reading the files backing it. – R.. GitHub STOP HELPING ICE Aug 14 '19 at 17:47
  • 1
    @R.. hibernating will not use all of your swap but it may do so in a worst case scenario. Per default settings it will not use more than 40% of the machine's RAM. – Takkat Aug 14 '19 at 17:57
  • @Takkat It will try not to use more than 40%; if more than 40% is allocated by programs, it will have to save more than the default setting. – marcelm Aug 14 '19 at 21:22
6

When I bought my SSD (not a top brand), the manufacturer's usage life estimate suggested I might expect an eighty year lifetime based on a reasonable write activity, even when using the drive for swap as well as OS and data storage.

SSD hardware hasn't gotten worse in the four years I've had mine, so you should be fine treating your SSD as you would have a platter drive ten years ago, with an expectation that it will outlast a similar capacity platter drive if not abused.

Compared to ordinary in-use swap, hibernation is nearly no usage at all -- so even in 2015 there ought to have been no problem with then-current hardware.

Zeiss Ikon
  • 5,128
  • 3
    this answer would be better with numbers to back it up. – qwr Aug 14 '19 at 04:58
  • 4
    I agree with qwr: what the marketing department says about the lifespan (especially when they include the weasel word "might") shouldn't be the leading sentence in a stackexchange answer. – Luc Aug 14 '19 at 07:24
  • 1
    Unfortunately, I've had the SSD for at least four years, don't recall the brand, don't care to open up my desktop machine to check, and doubt the specs for a drive this old are still readily available. I arrived at the 80 year figure from write life in gigabytes per day at what the mfgr. claimed as 8 year life at a huge number of gigabytes per day. – Zeiss Ikon Aug 14 '19 at 11:04