Apple - What are the "sleepimage" and "swapfile" documents?

swapfile0, swapfile1 and so on are swap files. You can sort of think of them like "backup" RAM. When your computer doesn't have enough RAM to accomodate the memory requests of all your programs (which is almost always, this is normal), it uses these files to "write out" part of what it had in RAM.

The sleepimage has a very similar use, except it's used only when your Mac hibernates/wakes up.

Deleting any of the swapfile* files is likely to mess up your system, but you can safely delete sleepimage. However, it's kind of pointless, it will probably be recreated the next time you put your computer to hibernation. If you really want to delete it, you'd have to use sudo rm, since root owns the file.

Finally, it's normal for the sleepimage to take up to 4 GB; it will usually take the same space as your RAM.

EDIT 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. See this post with more information.


Those are part of the virtual memory system: swapfile* contains literally swap data, which is memory content that has been pushed out to disk.

The sleepimage is used for suspend and resume support; when the system hibernates, that is where the memory data is stored.

Deleting either would cause significant problems: sleepimage is the same size as RAM, and would need to be recreated to sleep; the swap files are memory that is in use, and would cause serious problems to delete.

If you use less swap, the system will automatically deallocate those files, though, and free that disk space.


I just deleted my sleepimage and everything works fine, and to permanently prevent it from reappearing, follow the steps outlined in the comments of this article

Summary…

  • Can I safely delete sleepimage from my Mac?
  • Yes, you can remove sleepimage and it will just be created again automatically the next time your Mac is put to sleep. To delete sleepimage, type the following command into the Terminal:

    sudo rm /private/var/vm/sleepimage

You’ll be asked for the administrator password to gain access to remove the file, this is normal.

The sleepimage file is only needed for the safe-sleep function where your data is saved to the HDD before sleeping, if you want to permanently reclaim this disk space you can do so using the following commands in a terminal window. This will revert your computer to the older sleep method, which will sleep faster and wake faster but does keep your data in memory during the sleep period.

to check which mode is active

pmset -g | grep hibernatemode

to change mode 0= old style sleep 3= new (save to disk style)

sudo pmset -a hibernatemode 0