Dealing with sleepimage and swapfiles

Discussion in 'Mac Basics and Help' started by Trojan Man, May 6, 2013.

  1. Trojan Man macrumors newbie

    Joined:
    May 6, 2013
    #1
    Hi all,

    So after some time scouring these forums, I confronted my massive hidden usage of storage under the 'Other' category with OmniDiskSweeper. I found a folder called 'private' with an 8.6 GB sleepimage and 60 GB of swapfiles. This is using a massive chunk of my 120 GB, and I was wondering if it's safe to delete these files or whether anyone has any alternate solutions - it's getting to the point where Chrome and MS Word are becoming unresponsive following the "startup disk almost full" notification. Thanks!

    -T
     
  2. maflynn Moderator

    maflynn

    Staff Member

    Joined:
    May 3, 2009
    Location:
    Boston
    #2
    Reboot and your swap files will disappear, you can disable the sleep image by issueing the following command in the terminal (found in Applications->Utilities)

    Set sleep mode in shell: sudo pmset -a hibernatemode 0
    Remove the image: sudo rm /private/var/vm/sleepimage
    Create a blanked file: sudo touch /private/var/vm/sleepimage
    Make file immutable: sudo chflags uchg /private/var/vm/sleepimage
     
  3. benwiggy, May 6, 2013
    Last edited: May 6, 2013

    benwiggy macrumors 68020

    Joined:
    Jun 15, 2012
    #3
    60 Gb of Swap is a lot -- as said, a reboot will clear those, but perhaps you might benefit from more RAM, if you can install it in your Mac model.

    The sleepimage is important, if you want your Mac to remember what it was doing when it wakes from sleep. Disabling it will have consequences in this regard.

    It's generally a bad idea to go deleting invisible system files. However, the 60Gb recovered from the Swap should go a long way, but if it is creeping back quickly, then something else might be at play.
     
  4. Trojan Man thread starter macrumors newbie

    Joined:
    May 6, 2013
    #4
    Thanks so much - a simple reboot did the trick. I hadn't considered it initially because I had rebooted only a couple days ago; the fact that it crept back so quickly is somewhat unsettling, but the issue of the startup disk being almost full is solved for now. Again, I appreciate your time and assistance.
     
  5. Fishrrman macrumors G3

    Joined:
    Feb 20, 2009
    #5
    "The sleepimage is important, if you want your Mac to remember what it was doing when it wakes from sleep. Disabling it will have consequences in this regard."

    I disable the sleep image function and delete the sleep image file.

    Having done so, I've had no problems...
     
  6. benwiggy macrumors 68020

    Joined:
    Jun 15, 2012
    #6
    What happens when your battery runs out?
     
  7. Fishrrman macrumors G3

    Joined:
    Feb 20, 2009
    #7
    "What happens when your battery runs out?"

    Well, I'll assume that the MacBooks powers off and you have to plug in the charger to re-charge it…!

    I've had my MacBook Pro for 3 years now, and I can only recall the battery running low enough to invoke a "power-down" once or perhaps twice. I just put the charger on it, and back to normal...
     
  8. benwiggy macrumors 68020

    Joined:
    Jun 15, 2012
    #8
    If you had a sleep image, the memory would be retained. Without it, you boot up, having lost any unsaved data.

    I'm curious -- what happens when your laptop goes to "sleep", if there is no sleep image? If it can't save a sleep image, does it continue to power the RAM (which means shorter battery life while "sleeping")?

    What is the problem with a sleep image -- is it the size you object to, or do you think the continual writes will shorten the life of the SSD?
     
  9. chaseychasem macrumors regular

    Joined:
    Aug 4, 2012
    #9
    Having switched to hibernatemode 0, I'd like to second these queries. If my battery is totally drained, the computer simply reboots once plugged in and woken up, i.e. I just need to ensure I've saved my work first? What sort of warning is involved prior to old-fashioned sleep? Will I still have the reserve power notification shortly before it conks out, or not at all?
     
  10. Fishrrman macrumors G3

    Joined:
    Feb 20, 2009
    #10
    With the sleep image disabled, I get a warning that I'm down to approximately 2-3% power. At that point, I just plug the power adapter in.

    That's only happened a couple of times, because I generally don't wait until power has dropped to that low a level, before re-charging…
     
  11. benwiggy macrumors 68020

    Joined:
    Jun 15, 2012
    #11
    But it's worth pointing out that, at that point, if you don't or can't plug the power in and the machine runs out of juice, you will lose anything in memory and have to reboot once you have a power source.
    Obviously, that's less of a problem with Autosave and Resume.

    It's also worth pointing out that if the Mac can't sleep, it's going to use more power to keep the RAM powered when you're not using it.
     
  12. chaseychasem macrumors regular

    Joined:
    Aug 4, 2012
    #12
    If it can't hibernate, you mean?
     
  13. benwiggy macrumors 68020

    Joined:
    Jun 15, 2012
    #13
    Indeed.
     
  14. chaseychasem macrumors regular

    Joined:
    Aug 4, 2012
    #14
    Good to know, thanks. Unless it's a massive difference in battery life we're talking about, I'd prefer that to 16GB writes to the SSD each time my computer goes into hibernation mode 3.
     
  15. benwiggy macrumors 68020

    Joined:
    Jun 15, 2012
    #15
    On a modern SSD, you have nothing to fear from writes. The days of preciously counting the writes until the drive dies are over.
     
  16. chaseychasem macrumors regular

    Joined:
    Aug 4, 2012
    #16
    Heh, okay. Any idea how to undo sudo touch /private/var/vm/sleepimage and sudo chflags uchg /private/var/vm/sleepimage, then? :)
     
  17. benwiggy macrumors 68020

    Joined:
    Jun 15, 2012
    #17
    touch simply creates a file of zero K. chflags uchg makes it unchangeable.

    Use "chflags nouchg" instead, and the file should get over-written. Or you can delete it and the system will create a new one.
     
  18. chaseychasem macrumors regular

    Joined:
    Aug 4, 2012
    #18
    Great, thank you!
     

Share This Page