MacOS – APFS decreases space randomly

apfsdisk-spacehigh sierramacos

Since I upgraded to macOS High Sierra, one week ago, I have noticed that each time I wake the computer from sleep, the space left on the drive have decreased by a, somewhat, random amount.

I have very little free space on my drive – too little actually – so I usually keep an eye on it during each session I'm using the computer.

My first notice was that the assumed left space of about 6GB was only about 5. The day after the space was down to ~150MB! I did some cleanup, removed Xcode derived data, cleaned out cashes etc, and restarted. I think I got back to about 3-4GB.

Fast forward to the day before yesterday. Then I cleaned out a lot of junk and I had about 17GB of free space. Yesterday I only had just below 16GB, and today I only have ~10GB. After a reboot I got 12.5GB, but I also removed about maybe a 500MB yesterday, so I should at least have more than 16GB if everything was working the way I was expecting it.

What I have tried to 'solve' the problem is to see if closing apps increases the space – and it does – but not that much so I regain all 'lost' space. I also cleaned out cashes and Xcode derived data. But since I did this the first time, there is usually not much of a gain here.

I have a MBP Retina, i7, with 16GB of memory and ~500GB of disk. The computer is from 2013, I think. I regularly use Xcode, Safari, iTunes, Messages. Sometimes also Affinity Photo, Aurora HDR, Luminar and qbittorrent.

Searching on google, it seems like I'm the only one having this kind of problem. Or is there someone else having similar issues with decreasing space on the drive?

All help on this issue is welcome!

Best Answer

In my experience, there are two major culprits for this unexplained disk usage:

  1. Time machine
  2. Swap

One possibility is time machine. If you open Disk Utility, you may see a section labelled "Other Volumes", these are likely to be time machine backups. If you do see this, then you can open a command shell and enter:

df -h

On my machine, I get output similar to:

Filesystem                                                             Size   Used  Avail Capacity   iused               ifree %iused  Mounted on
/dev/disk1s1                                                          465Gi  442Gi   18Gi    97%   5512606 9223372036849263201    0%   /
devfs                                                                 196Ki  196Ki    0Bi   100%       678                   0  100%   /dev
/dev/disk1s4                                                          465Gi  5.0Gi   18Gi    23%         5 9223372036854775802    0%   /private/var/vm
map -hosts                                                              0Bi    0Bi    0Bi   100%         0                   0  100%   /net
map auto_home                                                           0Bi    0Bi    0Bi   100%         0                   0  100%   /home
map -fstab                                                              0Bi    0Bi    0Bi   100%         0                   0  100%   /Network/Servers
com.apple.TimeMachine.2017-10-19-174031@/dev/disk1s1                  465Gi  428Gi   18Gi    97%   5078237 9223372036849697570    0%   /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/Smakolyk/2017-10-19-174031/Smakolyk
com.apple.TimeMachine.2017-10-19-072101@/dev/disk1s1                  465Gi  423Gi   18Gi    97%   3858374 9223372036850917433    0%   /Volumes/com.apple.TimeMachine.localsnapshots/Backups.backupdb/Smakolyk/2017-10-19-072101/Smakolyk

Here you can see that I have local two time machine backups, and these will be using space. Apple have more information about local time machine backups.

You can disable local snapshots with:

sudo tmutil disablelocal

This should turn off the feature and free up the space. You can turn it back on with

sudo tmutil enablelocal

The second option is swap, this you can most easily see in /var/vm:

$ ls -lh /var/vm
total 10485760
-rw------T  1 root  wheel   1.0G  9 Oct 08:30 sleepimage
-rw-------  1 root  wheel   1.0G 18 Oct 14:00 swapfile0
-rw-------  1 root  wheel   1.0G 18 Oct 15:09 swapfile1
-rw-------  1 root  wheel   1.0G 19 Oct 21:25 swapfile2
-rw-------  1 root  wheel   1.0G 19 Oct 09:11 swapfile4

As you can see, I have 4GB in swap on my machine, and this is also taking up space on the disk.