Skip navigation

Over 3GB of swap files with 16GB of RAM?

27601 Views 73 Replies Latest reply: Jun 23, 2013 9:25 AM by chef098 RSS
  • nalundgaard Calculating status...
    Currently Being Moderated
    Aug 19, 2012 5:03 PM (in response to nalundgaard)

    Well, here's what appears to be my culprit... no hints as to the source. For now, I am disabling hibernation (by running sudo pmset -a hibernatemode 0 in terminal). That seems to correct the issue entirely.

     

    Anwyay, heres my log snippet. I bolded the parts that appear to correspond to the swapping, which is happening during the hibernation process:

     

    ********************************************

    8/19/12 6:52:42.262 PM com.apple.time[11]: Next maintenance wake [Backup Interval]: <date: 0x7f9258e12bb0> Sun Aug 19 19:16:07 2012 CDT (approx)

    8/19/12 6:52:42.262 PM com.apple.time[11]: Requesting maintenance wake [Backup Interval]: <date: 0x7f9258e12bb0> Sun Aug 19 19:16:07 2012 CDT (approx)

    8/19/12 6:52:42.277 PM WindowServer[1336]: Created shield window 0xa4 for display 0x042803c0

    8/19/12 6:52:42.307 PM WindowServer[1336]: device_generate_desktop_screenshot: authw 0x7fbee4d00370(2000), shield 0x7fbee2a63870(2001)

    8/19/12 6:52:42.414 PM WindowServer[1336]: device_generate_lock_screen_screenshot: authw 0x7fbee4d00370(2000), shield 0x7fbee2a63870(2001)

    8/19/12 6:52:43.000 PM kernel[0]: hibernate image path: /var/vm/sleepimage

    8/19/12 6:52:43.000 PM kernel[0]: sizeof(IOHibernateImageHeader) == 512

    8/19/12 6:52:43.000 PM kernel[0]: AirPort_Brcm43xx::powerChange: System Sleep

    8/19/12 6:52:43.000 PM kernel[0]: kern_open_file_for_direct_io(0) took 1 ms

    8/19/12 6:52:43.000 PM kernel[0]: Opened file /var/vm/sleepimage, size 17179869184, partition base 0x0, maxio 400000 ssd 1

    8/19/12 6:52:43.000 PM kernel[0]: hibernate image major 1, minor 0, blocksize 512, pollers 4

    8/19/12 6:52:45.000 PM kernel[0]: (default pager): [KERNEL]: ps_allocate_cluster - send HI_WAT_ALERT

    8/19/12 6:52:45.000 PM kernel[0]: macx_swapon SUCCESS

    8/19/12 6:52:45.000 PM kernel[0]: (default pager): [KERNEL]: ps_select_segment - send HI_WAT_ALERT

    8/19/12 6:52:45.000 PM kernel[0]: macx_swapon SUCCESS

    8/19/12 6:52:45.000 PM kernel[0]: (default pager): [KERNEL]: ps_select_segment - send HI_WAT_ALERT

    8/19/12 6:52:45.000 PM kernel[0]: macx_swapon SUCCESS

    8/19/12 6:52:45.000 PM kernel[0]: (default pager): [KERNEL]: ps_select_segment - send HI_WAT_ALERT

    8/19/12 6:52:45.000 PM kernel[0]: macx_swapon SUCCESS

    8/19/12 6:52:48.000 PM kernel[0]: (default pager): [KERNEL]: ps_select_segment - send HI_WAT_ALERT

    8/19/12 6:52:48.000 PM kernel[0]: macx_swapon SUCCESS

    8/19/12 6:52:52.000 PM kernel[0]: hibernate_alloc_pages flags 00000000, gobbling 0 pages

    8/19/12 6:52:52.000 PM kernel[0]: hibernate_setup(0) took 9067 ms

    8/19/12 6:52:54.000 PM kernel[0]: IOThunderboltSwitch(0x0)::listenerCallbackStatic - Thunderbolt HPD packet for route = 0x0 port = 11 unplug = 0

    8/19/12 6:52:54.000 PM kernel[0]: IOThunderboltSwitch(0x0)::listenerCallbackStatic - Thunderbolt HPD packet for route = 0x0 port = 12 unplug = 0

    8/19/12 6:52:54.000 PM kernel[0]: hibernate_page_list_setall start 0xffffff803fb45000, 0xffffff82393ac000

    8/19/12 6:53:01.000 PM kernel[0]: hibernate_page_list_setall time: 490 ms

    8/19/12 6:53:01.000 PM kernel[0]: pages 1364096, wire 458314, act 356698, inact 63640, cleaned 0 spec 239390, zf 246054, throt 0, could discard act 0 inact 0 purgeable 0 spec 0 cleaned 0

    8/19/12 6:53:01.000 PM kernel[0]: hibernate_page_list_setall found pageCount 1364096

    8/19/12 6:53:01.000 PM kernel[0]: IOHibernatePollerOpen, ml_get_interrupts_enabled 0

    8/19/12 6:53:01.000 PM kernel[0]: IOHibernatePollerOpen(0)

    8/19/12 6:53:01.000 PM kernel[0]: encryptStart 13310

    8/19/12 6:53:01.000 PM kernel[0]: writing 1355102 pages

    8/19/12 6:53:01.000 PM kernel[0]: hibernate_machine_init: state 2, image pages 458110, sum was 45082592, image1Size 28d87a00, conflictCount 4589, nextFree 51bf

    8/19/12 6:53:01.000 PM kernel[0]: IOHibernatePollerOpen(), ml_get_interrupts_enabled 0

    8/19/12 6:53:01.000 PM kernel[0]: IOHibernatePollerOpen(0)

     

    ********************************************

    Any hints appreciated, but at this point I am filing a bug report with Apple. This is an annoying waste of my SSD's write cycles. Technically, hibernation in general is, so I guess it's just as well.

  • nalundgaard Level 1 Level 1 (5 points)
    Currently Being Moderated
    Aug 19, 2012 6:02 PM (in response to megagram)

    So sad! But at least we clearly have the same issue. I did file a bug report with apple about the issue, so we will see.

     

    Just a detail on hibernatemode... 3 is, I believe, a sort of "smartsleep" mode where it writes out memory and goes into normal sleep immediately (RAM still powered), but after a set time it goes into deep sleep—hibernation, if you have it unplugged. If you look at pmset -g in Terminal, you'll see all your power-related settings:

     

    pmset-g.png

     

    You can see above, I am in hibernatemode 1 for testing (so I don't have to wait). If you are in hibernatemode 3, at least on a MacBook Pro Retina or other recent MB(P/A) laptop, you should also see a field called standbydelay. This is the time (in seconds) that your machine will stay asleep on battery power before transitioning into full hibernation. You can check this out yourself when you're in hibernatemode 3: look at your output from the above command, and note the time next to standbydelay. For starters, put your machine to sleep for a short while and wake it up. You will see it wakes instantly, especially if you have a Macbook Pro Retina . Now, put it to sleep again and wait until after the standbydelay has passed. You'll notice that it takes much longer to wake up, because it's reading your RAM from the sleepimage, because, again, it powered the RAM down and fully hibernated. those of us with tons of RAM will notice this doubly, literally, because it takes 2x as long to read 16GB from an SSD as it does to read 8GB.

     

    Anyway, sorry if I'm being too wordy—when you go to hibernatemode 0 you will only sleep, and when your battery dies, it will be essentially the same as if your computer crashed... you'll have to reboot. Considering that only takes a few seconds longer than waking from hibernation (on the rare occasions it does happen), and with most apps now saving their state across reboots anyway, it's not that big of a deal. You will likely notice, though, that if you leave your computer asleep in hibernatemode 0 and unplugged for a long time, when you wake up again, the battery will be drained a lot more. If you're on the road and looking to conserve battery to the maximum, this may be a major consideration. For me, not that big of a deal. YMMV, right?

     

    Hopefully this is the temporary fix for us. I've only been trying it this afternoon, so I am not 100% on it being a sure workaround. But here's hoping.

     

    Cheers!

  • Paul_at_Tahoe Calculating status...
    Currently Being Moderated
    Aug 29, 2012 12:28 AM (in response to megagram)

    I have the same issue, 3GB swap file with 0 page outs. I have 16GB ram on the new mbpro retna display running Mt Lion. 

    I may change the hibernate settings as has been suggested here.

    This is the only OS I've ever seen that builds a large swap file with 0 page outs and lots of free ram... My unix system tuning background says vm bug... Apple needs to fix it. 

  • MacJonny Calculating status...
    Currently Being Moderated
    Aug 30, 2012 3:16 AM (in response to nalundgaard)

    I had the same issue on my MBPr (on my 3rd replacement for screen issues, but that's another story)

    Huge swap files without any pageouts and lots of ram free. My setup was MBPr 512gb, 16gb on ML.

     

    Did some research and it turns out this is definitely attributed to power management and specifically standby mode.

     

    Sleep mode is when everything powers down but RAM is preserved by keeping its power on.

    Standby mode is when the contents of the RAM are written to the disk and it too powers down bringing the whole system in a minimum power consumption mode.

     

    Only the new macs have a standby mode.

     

    http://support.apple.com/kb/HT4392

     

    How this works:

    after the mac has been in sleep for 4200 seconds (default value) or 70 mins,

    all the contents of the RAM (which was still drawing power) are written to the disk

    then the RAM is powered down as well.

     

    This is what creates the swap file!

    The size of the swap files depends on the amount of RAM that was being used when switching from sleep to standby mode.

     

    Upon waking, the swap file is passed back from the disk to the RAM. That is why there is a short delay (5-20 sec, YMMV) for the mac to wake.

     

    this delay is avoided if you wake your mac before it has a chance to enter stanby (<70 mins)

     

    How to solve it:

     

    It has been suggested to change hibernation mode. This works but it has other RISKS!

     

    there are three hibernation or sleep modes (for our purposes hibernation=sleep here)

     

    Mode=0

    default for desktop macs: RAM always stays powered. it is not written to disk and if you lose power you lose what was stored in RAM

     

    Mode=3

    default for laptops: RAM stays powered but is also written to disk. If power is lost the contents of RAM are retrieved from disk and no data is lost.

    This is what all the laptops have been using until the introduction of standby mode with MB air and MBPr.

     

    Mode=25

    RAM is written to disk and powered down. when waking data is restored from disk.

     

    see: https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages /man1/pmset.1.html

     

    If you change to hibernate mode=0 or 1 (1 is not supported by apple) when your battery dies you will lose what was in the RAM.

     

    Standby mode is essentially a mix of mode=3 and mode=25 with a set delay between them.

     

    The bottom line:

     

    If you want to get rid of the swap files DO NOT change your hibernate mode. Just disable the standby mode.

     

    What you get: your mac will not dreate the swap file. It will wake instantly no matter how long it has been in sleep for. If your battery dies while in sleep mode, you will not lose any data as they are ssaved to disk as well.

    The only downside is that without standby mode, your battery will drain faster when the mac is sleeping and not connected to power. (that said it should last a couple days in sleep mode)

    What apple advertises as 30 day standby mode is the actual standby mode not the sleep mode.

    If you are ok with that, (this has been the bahaviour of all macs until the MBPr and the new Airs that support standby) go ahead and disable standby mode.

     

    but DO NOT change your hibernate mode.

     

    to disable standby:

     

    type in terminal:

     

    sudo pmset -a standby 0

     

    it will ask for your password

    type it (even though nothing will appear on screen for security reasons) and hit enter

     

    DONE!

     

    BONUS the best of three worlds...

    you can instead change the time it takes for the mac to enter standby mode.

     

    IMHO this is the best solution.

     

    make your mac go to standby mode after 6 or so hours of sleeping. that way you get all the benefits plus the battery savings and you only have to wait longer to wake if you havent used it in over 6 hours. This of course means that if you wake it after 6 hours the huge swap files will be there again.

     

    if that sounds good to you change the defaut value from 4200 to what suits you. (6 hours would be 21600)

     

    to do that:

     

    sudo pmset -a standbydelay 21600

     

    That's it! Hope this helped

    Sorry for the long post. Had to make sure it is all clear.

  • nalundgaard Level 1 Level 1 (5 points)
    Currently Being Moderated
    Aug 30, 2012 5:44 AM (in response to MacJonny)

    You have provided slightly more technical detail than I did about he power management settings.

     

    However, you are incorrect that standby mode should cause the system to write its active memory to swap. This is patently false. Upon hibernation, the mac writes out the contents of its RAM to /var/vm/sleepimage. If you place your Mac in standby mode, you will see this file created after you've woken it up. The system writes out the RAM to this file in its entirety, and restores it again once you wake the computer up. This is not the same as the swapfile(s), which are where the system stores memory that it cannot or does not want to store in main memory.

     

    This writing to swap in addition to writing to sleepimage is exactly what our problem is, and it is definitely either a bug or an undocumented behavior that is not normal.

  • MacJonny Level 1 Level 1 (0 points)
    Currently Being Moderated
    Aug 30, 2012 8:13 AM (in response to nalundgaard)

    Nalundgaard, you are absolutely right!

    I was mistakenly referring to swap and sleepimage as the same thing.

     

    However, the fact remains that all my experiments show that after disabling standby and restarting,

    No matter how long the mac has slept, the swap files do not take up all the space anymore.

     

    I use istat pro to check the size of swap easily.

     

    Can someone else please confirm. Disable standby, restart, let it sleep for at least 70 mins and then check whether the swap is huge again.

     

    All my experiments show that it does not come back.

     

    This has solved the huge swapfile issue for me.

  • nalundgaard Level 1 Level 1 (5 points)
    Currently Being Moderated
    Aug 31, 2012 4:05 PM (in response to MacJonny)

    Yes, that's what I've done as well (see my previous post). Disabling standby keeps the swapfile empty and also makes your laptop wake up much faster. As I mentioned, it does make your battery drain faster while sleeping. That doesn't bothered me. I've been using hibernatemode 0 for over a week now (since that last post), with an uptime of 8 days. My swap is still empty.

     

    So, this resolves the issue. I still think the paging out without incrementing pageout count must be a bug, but I guess I don't know. Maybe it is saving some other volatile state information there, e.g. the GPU RAM or something. The pageout amount seems awfully high for that though (GPU only has 1GB RAM on my mac), and I would think it ought to clear out after waking if it were intentional.

  • MacJonny Level 1 Level 1 (0 points)
    Currently Being Moderated
    Aug 31, 2012 4:41 PM (in response to nalundgaard)

    can  I just ask what the benefit of hibernate mode 0 is if you already disabled standby? this puts you at risk of losing everything if you have sudden loss of power... (not likely on a laptop but what if you are at 5% and leave the mac running? eg.)

     

    I only disabled the standby mode without changing hibernate mode and feel it solves everything.

     

    Regarding the swap file my theory is that it saves the contents of wired memory there in order to be able to quickly transfer them into the sleepimage upon entering standby. that way it does that faster.

     

    If you do some experiments you will see that the size of the swapfile is about the same size as the memory you have wired before you sleep your mac as i mentioned before.

    I cannot be sure but it seems like a plausible explanation.

     

    Anyway, glad we solved this... now if I could get a MBP without IR problems i would be a happy camper.

  • nalundgaard Level 1 Level 1 (5 points)
    Currently Being Moderated
    Sep 2, 2012 10:49 AM (in response to MacJonny)

    There is one benefit to hibernatemode 0, and that is that your system will never write /var/vm/sleepimage, which is how it stores your memory state. The file is the size of your RAM (in my case, 16GB) and can be a significant consumer of disk space of you only have a 256GB SSD in your MBPR. Also, writing out your system memory to the SSD every time your put your Mac to sleep causes significant additional write cycles on your SSD and may shorten its life. I am not sure to what degree this is a concern.

     

    Having said that, you're right that using hibernatemode=3 (and maybe 25, I haven't tried it) and standby=0 is another method of avoiding the unregistered pageouts—with the above caveat that you'll be losing space on your hard drive in the amount of your RAM size, etc. So I owe you an apology for misunderstanding the difference between what you were doing and what I was doing. I didn't read your post thoroughly enough and I apologize for that. It's clear there are two solutions to the problem with different tradeoffs. Hibernatemode 0 frees more disk space and reduces SSD write cycles, but if your battery dies while the laptop is asleep, you lose whatever was in your RAM. Hibernatemode 3 and standy 0 causes more disk usage and more SSD writes, but if your battery dies, you will still recover your RAM from disk and be able to pick up where you left off rather than have a forced reboot. Both solutions, though, prevent the writing to the pagefile.

     

    So, that's cool.

     

    I also went and read the manual page for pmset in more detail after re-reading your original post more carefully. I saw this section:

     

    hibernatemode takes a bitfield argument defining SafeSleep behavior. Passing 0 disables SafeSleep altogether, forcing the computer into a regular sleep.

     

    ____ ___1 (bit 0) enables hibernation; causes OS X to write memory state to hibernation image at sleep time. On wake (without bit 1 set) OS X will resume from the hibernation image. Bit 0 set (without bit 1 set) causes OS X to write memory state and immediately hibernate at sleep time.

     

    ____ __1_ (bit 1), in conjunction with bit 0, causes OS X to maintain system state in memory and leave system power on until battery level drops below a near empty threshold (This enables quicker wakeup from memory while battery power is available). Upon nearly emptying the battery, OS X shuts off all system power and hibernates; on wake the system will resume from hibernation image, not from memory.

     

    ____ 1___ (bit 3) encourages the dynamic pager to page out inactive pages prior to hibernation, for a smaller memory footprint.

     

    ___1 ____ (bit 4) encourages the dynamic pager to page out more aggressively prior to hibernation, for a smaller memory footprint.

     

     

    Bits 3 and 4 raised my eyebrow. It looks like for some reason the hibernation process includes having the dynamic pager (this is the part of the kernel that manages swap file creation, paging out, etc) page out the inactive pages in RAM to the disk before hibernating "for a smaller memory footprint." I am not sure why it's doing this. With an SSD it should be fine to just purge inactive memory altogether—you're going to have to hit the disk to get it back whether it's re-reading the file it was originally in OR reading from the pagefile. So, I don't get that at all. It sounds misguided to me, and certainly it sounds like the system is doing this willynilly—hibernatemode 3 (0000 0011) doesn't activate bit 3 or 4, and yet it clearly causes this behavior. It looks to me like it should only happen in hibernatemode 25 (0001 1001), which has bits 0, 3, and 4 set, so it's unfortunate that pmset doesn't appear to behave exactly as advertised.

     

    Still, at least now I have a reasonable guess as to why this paging out was happening. For me, that basically concludes the issue. pmset is doing something normal, but it's doing it even when you don't ask it to. And now we've figured out a couple of ways to prevent the behavior with a variety of tradeoffs, I think we're in good shape despite Apple's apparently-out-of-date documentation.

  • Whadafuq Calculating status...
    Currently Being Moderated
    Sep 5, 2012 6:30 AM (in response to nalundgaard)

    Thank you so much for posting this! I am now able to extend the standby delay time on my Macbook Pro Retina! So happy now! Thank you!!!!

  • cjcj Level 1 Level 1 (55 points)
    Currently Being Moderated
    Sep 22, 2012 12:20 AM (in response to nalundgaard)

    nalundgaar and MacJonny thanks for all your posts, appreciated reading throught he discussion and for all the guidance.

  • pcunix Level 1 Level 1 (0 points)
    Currently Being Moderated
    Oct 17, 2012 6:07 AM (in response to megagram)

    I have something like this happening on my iMac.

     

    Swapfiles build up:

     

    -rw------- 1 root wheel 67108864 Oct 17 07:14 /var/vm/swapfile0

    -rw------- 1 root wheel 67108864 Oct 17 08:33 /var/vm/swapfile1

    -rw------- 1 root wheel 134217728 Oct 17 08:34 /var/vm/swapfile2

    -rw------- 1 root wheel 268435456 Oct 17 08:34 /var/vm/swapfile3

    -rw------- 1 root wheel 536870912 Oct 17 08:33 /var/vm/swapfile4

    -rw-------  1 root  wheel  1073741824 Oct 17 08:44 /var/vm/swapfile5

     

    There is lots of paging:

     

    Mach Virtual Memory Statistics: (page size of 4096 bytes)

    Pages free:                         482166.

    Pages active:                      1021364.

    Pages inactive:                     899727.

    Pages speculative:                   54463.

    Pages wired down:                   686699.

    "Translation faults":             11470989.

    Pages copy-on-write:                479343.

    Pages zero filled:                 7490105.

    Pages reactivated:                  569332.

    Pageins:                            585417.

    Pageouts:                            60520.

     

    And it's

     

    1922   339 100.1 11.5 1444524 10855052 /System/Library/.../Contents/MacOS/DashboardClient

     

    consuming 100% CPU.

     

    If I kill it, the Dock just restarts it - only a "killall Dock" gets rid of it.

     

    I run no Widgets, hibernate mode is 0 as it should be on an iMac and I don't know what causes this.  It seems somewhat random - DashboardClient isn't normally running and then suddenly it fires up and soon after the machine is on its knees.    I've been trying to figure out if it's something I do but so far I just do not know..

  • nalundgaard Level 1 Level 1 (5 points)
    Currently Being Moderated
    Oct 17, 2012 8:52 AM (in response to pcunix)

    I would try hosing your dashboard preferences and caches for starters, but I have no idea. For what its worth, your problem is entirely unrelated to the one described in this thread. You may be best served by starting a new topic rather than adding to this one.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (2)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.