What is this folder? It's huge and I can use the extra room. I've read sleepimage isn't necessary—is this true? Should I just deal with it? Is the "private" folder emptied automatically, or would I have to do it manually? If it isn't useful (or needed), is there any way to prevent it from reappearing in the future?
-
1Are you still interested in the prevention tack on question? That might be better asked separately now that you have an answer to the main aspects of your query.– bmike ♦Commented May 2, 2012 at 16:14
-
Looks like Lri covered that below, but thanks for the tip– WolfCommented May 2, 2012 at 20:54
6 Answers
/var/vm/sleepimage
is used to store the contents of the RAM during hibernation, and the hybrid hibernation and sleep mode that Mac laptops use by default. If you have 8 GiB of RAM, /var/vm/sleepimage
takes about 8 GiB of disk space. I don't know why it isn't deleted after waking up from sleep though. It might be to ensure that there is enough free disk space for it or so that it won't be stored on non-contiguous blocks if disk space is low.
You can delete /var/vm/sleepimage
safely, but it will be recreated when you put the Mac to sleep. If you run sudo pmset -a hibernatemode 0; sudo rm /var/vm/sleepimage
, the Mac will use a normal sleep mode (like desktop Macs by default) and it won't recreate /var/vm/sleepimage
.
From man pmset
:
hibernatemode = 0 (binary 0000) by default on supported desktops. The system will not back memory up to persistent storage. The system must wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.
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 disk image.
hibernatemode = 25 (binary 0001 1001) is only settable via pmset. The system will store a copy of memory to persistent storage (the disk), and will remove power to memory. The system will restore from disk image. If you want "hibernation" - slower sleeps, slower wakes, and better battery life, you should use this setting.
- 0 (traditional sleep mode) enables fast wake up and sleep, saves disk space, and reduces writing to the drive.
- 3 (hybrid hibernation and safe sleep mode) enables fast wake up and sleep and enables restoring state after a power loss.
- 25 (hibernation) saves energy and enables restoring state after a power loss.
I used hibernatemode 0 with my MacBook Air. Even if the MacBook Air went to sleep when the battery was nearly empty, the battery didn't usually drain out completely during sleep. /var/vm/sleepimage
took about 4 GiB of disk space, and writing it hundreds or thousands of times might have reduced the lifespan of the SSD.
Addition: What Dan Barrett said about the sleepimage re-creation is true. However there's a way to get around it and therefore permanently free the disk space occupied by sleepimage.
The whole steps:
disable hibernation mode:
sudo pmset -a hibernatemode 0
delete /private/var/vm/sleepimage:
sudo rm /private/var/vm/sleepimage
create an empty file and name it 'sleepimage':
sudo touch /private/var/vm/sleepimage
change its flag to immutable:
sudo chflags schg /private/var/vm/sleepimage
In this way the system cannot re-create sleepimage anymore. This worked perfectly for me and I've not seen any problem on my Mac for 4 months.
Don't remove /private/var/vm it is your swap files which the OS constantly uses.
When you need less swap or you reboot the OS will reduce the number of files it uses here.
-
Reminds me of the saying. If it aint broke, don't fix it!– iProgramCommented Jun 14, 2015 at 17:51
-
6I deleted my entire vm folder thinking that the system will recreate when needed, but that did not happen. When the system wanted to use swap files, it froze and restarted. I now have created the vm folder and swapfile, hoping this will fix the issue. So, DON'T delete it! Commented Jul 11, 2015 at 1:24
An additional note to the top answer:
Since you can either choose to disable the sleepimage, or activate it but then be forced to keep it after wake up, i found a dirty little trick for my preferred solution: Have a sleepimage but delete it after wakeup to free the disk space. If you are someone like me who constantly hovers at around 2-6 GB free space on your small SSD, this might be your solution.
Just point the sleepimage to your .Trash
folder and empty your trash bin after wake up.
sudo pmset -a hibernatefile ~/.Trash/sleepimage
This is only a viable solution, if you only use one account on your mac. You wont be able to easily delete the sleepfile from another account (Of course you could if the other account has sufficient rights, but it would loose it's simplicity because it would not just mean clicking on the trash bin).
If for whatever reason you want to return to the factory settings, just type
sudo pmset -a hibernatefile /var/vm/sleepimage
(Note: I use 10.8, this might change in other versions, just check man pmset
to be sure.)
If it's not taking too much space (like in your case) I would leave as it is. Things in the private folder are not meant to be messed with. It's part of the UNIX system your Mac is build on and shouldn't be visible. It's why they call the folder private. But software, like you used, made it visible, which is not a good thing.
That being said, you can delete this sleep image without any problem, but I wouldn't recommend it. If you really need those 4GB, try to use a hard drive for your movies, music or so and save space with your own files, not the systems files.
-
3The next time your Mac goes to sleep it re-creates the sleep image, so there's no point in removing it. @sean: don't increase your RAM, the sleepimage file will be as large as the RAM installed in your system. Commented May 2, 2012 at 11:01
-
I only have 15 GB left on my laptop, and the /private/var/vm is taking up about 12 GB that I could be using. It's not immediately urgent right now, but I'm considering it. Commented Nov 1, 2015 at 15:10