Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

whitedragon101

macrumors 65816
Original poster
Sep 11, 2008
1,336
334
Number 3 on the SSD tweaks thread is turn off hibernation mode
https://forums.macrumors.com/threads/1505922/
"Another feature of Mac OS turned on by default on laptops is, that it saves all the memory to disk when entering sleep mode. This is to ensure your laptop does not lose your work if it runs out of battery while “sleeping”. "

By sleep mode does this mean every time I close the lid this save happens?
If so does it happen instantly or after a given time?

Also if hibernation mode is turned off doesn't this mean if the machine is accidentally unplugged you loose all your work if you run out of battery?
 

davidlv

macrumors 68020
Apr 5, 2009
2,291
874
Kyoto, Japan
that depends ...

Number 3 on the SSD tweaks thread is turn off hibernation mode
https://forums.macrumors.com/threads/1505922/
"Another feature of Mac OS turned on by default on laptops is, that it saves all the memory to disk when entering sleep mode. This is to ensure your laptop does not lose your work if it runs out of battery while “sleeping”. "

By sleep mode does this mean every time I close the lid this save happens?
If so does it happen instantly or after a given time?

Also if hibernation mode is turned off doesn't this mean if the machine is accidentally unplugged you loose all your work if you run out of battery?
Turning hibernation mode off is a good idea if your priority is saving space on the SSD (the sleep image is usually the size of the physical RAM, may be smaller is certain cases). It can be a bad idea if you are in the habit of not saving your work to disk before you put the machine to sleep. That itself is in my opinion a very bad idea, and how much time does it take to hit Command+s?
Not sure which setting prescribes the amount of time that elapses before the hibernation sets in, but it is not usually immediately on going into sleep.
In any case, you will be doing yourself a favor by developing the habit of saving your work often, not just before sleep. Anyone who has lost an hour's or worse of work because they did not "save" will agree with that sentiment.
 

Dovahkiing

macrumors 6502
Nov 1, 2013
478
466
When you simply close the lid, you are putting the computer to 'sleep'. In this mode, the RAM is still powered on and as such the computer can instantly resume right where you left off next time you open it.

But what if the RAM loses power during sleep? Well then all it's contents would be lost. "Hibernate" is a mode your computer uses to avoid this scenario. Your computer writes the contents of RAM to a file on the hard drive. That way, if it loses power, it can still load the sleep image back into RAM upon the next boot up. This isn't as fast as resuming from sleep, but still is faster than a regular boot and can save your files.

Typically you would expect the sleep image to be about as big as however much RAM you have installed. If you have 8GB of RAM, then your sleep image would be about 8GB in size. So you can see that on a small hard drive you can save a lot of space by disabling this feature.

However, I think Mavericks does some fancy file compression on this sleep image now. I have 8GB of RAM and when I went to remove the sleep image file I saw that it was only just over 1GB in size. So I decided not to bother. I don't know if it's like this for everyone but you can check for yourself by going to terminal and entering:

ls -lh /private/var/vm/sleepimage
 

whitedragon101

macrumors 65816
Original poster
Sep 11, 2008
1,336
334
When you simply close the lid, you are putting the computer to 'sleep'. In this mode, the RAM is still powered on and as such the computer can instantly resume right where you left off next time you open it.

But what if the RAM loses power during sleep? Well then all it's contents would be lost. "Hibernate" is a mode your computer uses to avoid this scenario. Your computer writes the contents of RAM to a file on the hard drive. That way, if it loses power, it can still load the sleep image back into RAM upon the next boot up. This isn't as fast as resuming from sleep, but still is faster than a regular boot and can save your files.

Typically you would expect the sleep image to be about as big as however much RAM you have installed. If you have 8GB of RAM, then your sleep image would be about 8GB in size. So you can see that on a small hard drive you can save a lot of space by disabling this feature.

However, I think Mavericks does some fancy file compression on this sleep image now. I have 8GB of RAM and when I went to remove the sleep image file I saw that it was only just over 1GB in size. So I decided not to bother. I don't know if it's like this for everyone but you can check for yourself by going to terminal and entering:

ls -lh /private/var/vm/sleepimage

At what point does the hibernate file get written? As soon as you close the lid or does it wait for a certain time or lower battery life before writing it?
 

davidlv

macrumors 68020
Apr 5, 2009
2,291
874
Kyoto, Japan
At what point does the hibernate file get written? As soon as you close the lid or does it wait for a certain time or lower battery life before writing it?
Not 100% sure, but judging from the info on pmset variables noted on this forum, I think the sleep image file gets written to disk at about 1.67 hr after going into sleep.
Info on pmset;
Open a Terminal shell (in the /Applications/Utilities folder)
pmset -g
will list all the current power settings/device settings.
1. set hibernate mode to 0
sudo pmset -a hibernatemode 0
hibernationmode 0 is normal sleep, data kept in ram, nothing written to disk
2. delete the unnecessary sleep file (since hibernate is disabled) to regain disk space equal to memory (saves the same amount of disk space as your RAM, eg. 8 GBs, valuable on an SSD),
You can use the Go to folder menu to delete the file, found in the /var/vm/ folder, and named sleepimage. Reboot and simply delete that file,. Or use this:
sudo rm /var/vm/sleepimage or sudo rm /private/var/vm/sleepimage
The sleep image file is actually in /Private/var/vm/ but /var/vm/ is a symbolic link to that location.
Optional: Create a blanked zero-byte file so the OS cannot rewrite the file:
sudo touch /private/var/vm/sleepimage
Make file immutable:
1. sudo chflags uchg /private/var/vm/sleepimage
or 2. sudo ln -s //dev/null/var/vm/s;eepimage

If pmset -g shows: autopoweroff**1,
disable this automatic hibernation mode (happens even if hibernation mode is set to 0 on the new Mac mini 2012 and iMac)
sudo pmset -a autopoweroff 0
4. set the safe sleep timer (standbydelay) to 20 hours, default is 4200 (1.67 hr)
sudo pmset -a standbydelay 72000
5. sudo pmset -a standby 0
While researching this, I noticed that bit 3 of hibernatemode encourages the dynamic pager to page out inactive pages prior to hibernation. So this appears to be why I have swap used after sleeping (even though my hibernatemode is 0, so bit 3 is off). I disabled this new, possibly buggy behaviour by switching off standby: sudo pmset -a standby 0
Note: I can't give credit here where it is due, forgot who posted this originally. :)
 

davidlv

macrumors 68020
Apr 5, 2009
2,291
874
Kyoto, Japan
Thanks

Do you know if Apple do this for their SSD only retina MBP?
The pmset -g terminal command will show what the hibernation mode is set to, if you have one of those computers, and haven't changed the setting.
I assume it is set to "mode 3".
hibernatemode = 3 (binary 0011) by default on supported portables. The system will store a copy of memory to persistent storage (the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from the disk image (var/vm/sleepimage).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.