Probably one (or more) process on your system was running wild.
Use your Mac as usual. From time to time check the folder /var/vm and if you run across a lot of swap files open Terminal.app and enter:
ps xa | awk '{print $1}' | xargs -n 1 sudo vmmap | grep -A3 'Summary' > /Users/YourUserName/Desktop/vmmap_summary.txt
Depending on the number of running processes this will take about 30-60 seconds. Your account has to be able to run sudo
(=usually an admin account).
This creates a text file called vmmap_summary.txt on your desktop which contains some memory and swap information of all running processes sorted by PID. Some will fail because their process id is already gone.
Example (truncated to the first four PIDs):
==== Summary for process 1
ReadOnly portion of Libraries: Total=51.8M resident=12.9M(25%) swapped_out_or_unallocated=38.9M(75%)
Writable regions: Total=92.9M written=808K(1%) resident=2112K(2%) swapped_out=0K(0%) unallocated=90.8M(98%)
==== Summary for process 21
ReadOnly portion of Libraries: Total=77.0M resident=30.9M(40%) swapped_out_or_unallocated=46.1M(60%)
Writable regions: Total=88.5M written=1116K(1%) resident=5144K(6%) swapped_out=0K(0%) unallocated=83.4M(94%)
==== Summary for process 22
ReadOnly portion of Libraries: Total=150.1M resident=60.1M(40%) swapped_out_or_unallocated=90.0M(60%)
Writable regions: Total=93.2M written=1460K(2%) resident=5440K(6%) swapped_out=0K(0%) unallocated=87.8M(94%)
==== Summary for process 23
ReadOnly portion of Libraries: Total=77.2M resident=31.3M(41%) swapped_out_or_unallocated=45.9M(59%)
Writable regions: Total=96.9M written=1412K(1%) resident=2036K(2%) swapped_out=0K(0%) unallocated=94.9M(98%)
Check for any bad behaving process (swapped_out>>>0k).
To get the process name of a misbehaving PID and some more information enter:
ps aux | awk '$2 == PID { print $0 }'
Example output for a process with the ID 21 β ps aux | awk '$2 == 21 { print $0 }'
β would be:
root 21 0,0 0,0 2507740 6552 ?? Ss 10:03am 0:01.48 /usr/libexec/kextd
Now hunt down what may be wrong with the app or daemon.
You can safely delete anything in /private/var/folders/
but not the folder itself
sudo rm -rf /private/var/folders/*
Quit all apps before you do & reboot afterwards β¦ and whatever you do, don't touch anything else in /private/var/
, and do not delete /private/var/folders/
itself.
Rumor has it that one should not delete /private/var/folders/zz
. This article implies otherwise, but if you want to be on the safe side, use
cd /private/var/folders
for i in *; do if [ "$i" != "zz" ]; then sudo rm -rf "$i"; fi; done
sudo rm -rf zz/*
instead.
Best Answer
/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 runsudo 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
: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.