14

I recently started running into a lot of memory issues on my mac running High Sierra. Rather than the force quit window coming up, my system would freeze completely and the only way to recover is to force a reboot.

After some investigating, I found out that my system is not creating any swap files even when the memory pressure is critical. There is nothing in the /private/var/vm/ directory.

I have already tried sudo launchctl load -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist.

Is there any other way to enable swapping? Or to run some diagnostics?

Additional details:

I am booting from an external Thunderbolt SSD (I don't know if this is the cause).

Below is the output from vm_stat. If I do anything memory intensive at this stage, my system will freeze.

Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                                4116.
Pages active:                            854231.
Pages inactive:                          825841.
Pages speculative:                        27754.
Pages throttled:                              0.
Pages wired down:                        606483.
Pages purgeable:                          22070.
“Translation faults”:                  75731290.
Pages copy-on-write:                     401121.
Pages zero filled:                     49766457.
Pages reactivated:                     17690835.
Pages purged:                           1577284.
File-backed pages:                       503400.
Anonymous pages:                        1204426.
Pages stored in compressor:             6563399.
Pages occupied by compressor:           1875311.
Decompressions:                        21012443.
Compressions:                          32102441.
Pageins:                                2172708.
Pageouts:                                 35123.
Swapins:                                      0.
Swapouts:                                     0.

Edit:

Some more details:

This is the output from diskutil ap list

APFS Container (1 found)
|
+-- Container disk4 6BE5FDB5-A68F-4CBF-A404-68AE73E61C10
    ====================================================
    APFS Container Reference:     disk4
    Capacity Ceiling (Size):      499898105856 B (499.9 GB)
    Capacity In Use By Volumes:   452259872768 B (452.3 GB) (90.5% used)
    Capacity Available:           47638233088 B (47.6 GB) (9.5% free)
    |
    +-< Physical Store disk3s2 39853349-6B62-4961-99DE-811BA56465EC
    |   -----------------------------------------------------------
    |   APFS Physical Store Disk:   disk3s2
    |   Size:                       499898105856 B (499.9 GB)
    |
    +-> Volume disk4s1 99688E85-E9EF-3688-A324-913D00FF6A0E
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk4s1 (No specific role)
    |   Name:                      System (Case-insensitive)
    |   Mount Point:               /
    |   Capacity Consumed:         449420767232 B (449.4 GB)
    |   FileVault:                 No
    |
    +-> Volume disk4s2 729366E4-48AA-45A3-95DA-8871B8A29778
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk4s2 (Preboot)
    |   Name:                      Preboot (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         20357120 B (20.4 MB)
    |   FileVault:                 No
    |
    +-> Volume disk4s3 431C0191-2B1F-480C-94D0-AF4748E6D213
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk4s3 (Recovery)
    |   Name:                      Recovery (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         509820928 B (509.8 MB)
    |   FileVault:                 No
    |
    +-> Volume disk4s4 5DE0EA6B-CA57-4226-B038-2E256FCC5B98
        ---------------------------------------------------
        APFS Volume Disk (Role):   disk4s4 (VM)
        Name:                      VM (Case-insensitive)
        Mount Point:               Not Mounted
        Capacity Consumed:         2147504128 B (2.1 GB)
        FileVault:                 No

And the output from mount:

/dev/disk4s1 on / (apfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk2 on /Volumes/Storage (hfs, local, journaled)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)

Solution (Updated): A number of good solutions suggested. After revisiting the issue again, I would recommend lint's solution below. It's the most general way that accounts for changes in volume names.

2
  • Look in this thread for an explanation what to do: apple.stackexchange.com/questions/126669/…
    – LexS
    Mar 16, 2018 at 8:37
  • @Lexs thanks for your answer, but I don't think that thread contains anything related to my problem? Or am I missing something?
    – kayoz
    Mar 16, 2018 at 9:35

12 Answers 12

8

I have had the same problem running High Sierra (and Mojave since) off an external SSD. I haven't tried Glorfindel♦'s suggestion to wipe the disk to Sierra on HFS+ before restoring to High Sierra, which seems like a lot of work.

I have, however, been using my own launch daemon with a bash script since January, similar to chrisgooley's solution, however, my script also checks which volume ID to mount. I thought I'd share my solution with the dynamic check for the correct volume ID.

Initially, I hardcoded the volume ID as well but this was problematic because whenever the system booted with additional drives attached, the volume ID would change the swap volume would fail to mount.

My script and daemon are below:

mountvm.sh

#!/bin/bash
# Mount the APFS VM volume if it isn't already mounted

VM_VOLUME=$(/usr/sbin/diskutil list | grep "VM" | awk '{ print $7 }') 
# echo "VM Volume is $VM_VOLUME"
for i in {1..5}
do
    if [ ! -e /private/var/vm/sleepimage ]
    then
#       echo "$(date "+%a %d/%m/%Y %I:%M:%S%p") > VM volume not yet mounted..."
#       echo -n "$(date "+%a %d/%m/%Y %I:%M:%S%p") > "
        /usr/sbin/diskutil mount -mountPoint /private/var/vm/ $VM_VOLUME
        break
    else
#       echo "$(date "+%a %d/%m/%Y %I:%M:%S%p") > VM volume already mounted..."
        if [ $i -lt 6 ]
        then
#           echo -n "$(date "+%a %d/%m/%Y %I:%M:%S%p") > Confirming in "
            for count in {2..1}
            do
#               echo -n "$count min..."
                sleep 60
            done
            echo
        fi
    fi
done

exit 0

com.local.mountvm.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.local.mountvm</string>
    <key>ProgramArguments</key>
    <array>
        <string>[/path/to/script]/mountvm.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Some notes:

Change the [/path/to/script] in the plist to where ever you place the bash script.

Remove the # on the echo lines in the bash script to troubleshoot (you'll need to run the script in Terminal with sudo or specify a stdout path in the plist).

The script checks whether /private/var/vm/sleepimage exists. If it doesn't, then the swap volume isn't mounted and tries to mount the correct volume. If it does, it will check again four more times in two minute intervals before exiting. The reason I added this was because I found if I simply tried to mount the volume as soon the daemon loaded, it would fail.

9

I had the same problem when I installed High Sierra on external SSD.

Volume disk3s4 647DA4A9-7E85-4523-A4D2-F0392D3789D4
        ---------------------------------------------------
        APFS Volume Disk (Role):   disk3s4 (VM)
        Name:                      VM (Case-insensitive)
        Mount Point:               Not Mounted
        Capacity Consumed:         4294987776 B (4.3 GB)
        FileVault:                 No

Solution:

  1. Create a plist file as root user and put it in /Library/LaunchDaemons/ folder. It has to be written in reverse domain notation like this:

    /Library/LaunchDaemons/local.mountdisk3s4.plist
    
  2. Just copy this xml data in your plist file and change the name of APFS VM Volume with yours.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
         <key>Label</key>
         <string>THE NAME OF FILE</string>
         <key>ProgramArguments</key>
         <array>
              <string>/sbin/mount_apfs</string>
              <string>YOUR APFS VOLUME</string>
              <string>/private/var/vm</string>
         </array>
         <key>KeepAlive</key>
         <dict>
        <key>SuccessfulExit</key>
        <false/>
         </dict>    
    </dict>
    </plist>
    

    In my case it looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
         <key>Label</key>
         <string>local.mountdisk3s4</string>
         <key>ProgramArguments</key>
         <array>
              <string>/sbin/mount_apfs</string>
              <string>disk3s4</string>
              <string>/private/var/vm</string>
         </array>
         <key>KeepAlive</key>
         <dict>
        <key>SuccessfulExit</key>
        <false/>
         </dict>    
    </dict>
    </plist>
    
  3. Reboot your Mac

4

The dedicated VM APFS volume is not mounted properly:

+-> Volume disk4s4 5DE0EA6B-CA57-4226-B038-2E256FCC5B98
    ---------------------------------------------------
    APFS Volume Disk (Role):   disk4s4 (VM)
    Name:                      VM (Case-insensitive)
    Mount Point:               Not Mounted
    Capacity Consumed:         2147504128 B (2.1 GB)
    FileVault:                 No

It should be mounted to the Mount Point /private/var/vm.

Entering mount in Terminal should reveal something like:

...
/dev/disk4s4 on /private/var/vm (apfs, local, noexec, journaled, noatime, nobrowse)
...

The reason is unclear. At least some swap files have been created in the past because 2.1 GB (= two swapfiles à 1 GiB) are consumed by VM.


A temporary workaround is to specify another swap file directory. After disabling SIP, this can be accomplished by modifying the file /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist with sudo nano ... or LaunchControl.

Original:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>EnableTransactions</key>
    <true/>
    <key>Label</key>
    <string>com.apple.dynamic_pager</string>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>POSIXSpawnType</key>
    <string>Interactive</string>
    <key>ProgramArguments</key>
    <array>
        <string>/sbin/dynamic_pager</string>
    </array>
</dict>
</plist>

Mod:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>EnableTransactions</key>
    <true/>
    <key>Label</key>
    <string>com.apple.dynamic_pager</string>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>POSIXSpawnType</key>
    <string>Interactive</string>
    <key>ProgramArguments</key>
    <array>
        <string>/sbin/dynamic_pager</string>
        <string>-F</string>
        <string>/vm/swapfile</string>
    </array>
</dict>
</plist>

If the directory /vm doesn't exist, create it:

sudo mkdir /vm
sudo chmod 755 /vm

Reboot your Mac afterwards. Enable SIP again!


In my opinion this is related to the 10.13.3 Supplemental Update. At least in my various High Sierra VMs additional folders /vm were created - each containing one abandoned swapfile0. The actual swap directory is /private/var/vm -> disk1s4 (APFS VM volume) though - tested with sudo memory_pressure -l critical in Terminal.

I have to further investigate this.


To really fix the problem removing and re-adding the somehow broken VM APFS volume should help:

  • Restore the default com.apple.dynamic_pager.plist file
  • Check whether the folder /private/var/vm exists
  • Boot to High Sierra Recovery Mode
  • Open Terminal in the menubar > Utilities and enter diskutil ap list to get the APFS details
  • Remove the APFS VM volume:

    diskutil ap deleteVolume <av_vmUUID> #<av_vmUUID>: UUID of the APFS Volume with the VM role
    

    In your case av_vmUUID is 5DE0EA6B-CA57-4226-B038-2E256FCC5B98 so:

    diskutil ap deleteVolume 5DE0EA6B-CA57-4226-B038-2E256FCC5B98
    
  • Add an APFS VM volume:

    diskutil ap addVolume diskX APFS VM -mountpoint /private/var/vm -role V
    

    with diskX: APFS Container Reference of the container with the UUID 6BE5FDB5-A68F-4CBF-A404-68AE73E61C10 shown in the diskutil ap list (probably disk3, disk4 or disk5)

    The volume will be created but it won't get mounted because the specified mountpoint doesn't exist in the base system of the Recovery Mode!

  • Reboot your Mac and first check if VM is mounted to /private/var/vm with mount. The test it with sudo memory_pressure -l critical.
8
  • Thanks for the detailed answer, but unfortunately this is still not working for me. There is nothing in my /vm/ folder after applying this and restarting. I tried the memory_pressure test and no swap was being created. I did notice that I kept getting a "vm_swap_create_file failed at XXX secs" log in the console though. And the vm disk is still showing as unmounted.
    – kayoz
    Mar 16, 2018 at 13:30
  • @kayoz Added a possible solution
    – klanomath
    Mar 16, 2018 at 21:34
  • Thanks again for all the time you've taken to help me solve this. Unfortunately, removing and creating the VM volume still does not work. After re-creating the volume, its size reduced to 20KB. When I restart in normal mode, the volume goes back up to 2GB and remains unmounted.
    – kayoz
    Mar 19, 2018 at 10:05
  • @kayoz I try to find another solution! Did you use some hack in the past to move the VM to another volume? Or does the TB disk contain a "fresh" HighSierra system (=no upgraded system)?
    – klanomath
    Mar 19, 2018 at 10:13
  • I have never touched the VM stuff before. The TB disk does not have a fresh system. It used to be Sierra, which was upgraded to High Sierra. I did originally migrate my system to the TB disk via a time machine backup though.
    – kayoz
    Mar 19, 2018 at 13:14
1

I have the same issue after upgrade. My way simply is erasing APFS container then using Time Machine to restore Sierra with HFS+ then restore High Sierra with APFS partitions. Below are my configs that make it work.

MacBook-Pro:~ root# diskutil apfs list
APFS Container (1 found)
|
+-- Container disk1 96CC8155-6433-4240-B445-3E909F80E1CF
    ====================================================
    APFS Container Reference:     disk1
    Capacity Ceiling (Size):      250790436864 B (250.8 GB)
    Capacity In Use By Volumes:   221076267008 B (221.1 GB) (88.2% used)
    Capacity Available:           29714169856 B (29.7 GB) (11.8% free)
    |
    +-< Physical Store disk0s2 0D0BAEFE-FBC0-496D-9260-5F2A5D6B0793
    |   -----------------------------------------------------------
    |   APFS Physical Store Disk:   disk0s2
    |   Size:                       250790436864 B (250.8 GB)
    |
    +-> Volume disk1s1 5AA2CDA5-EAD1-4D9C-BEE0-E85957526A37
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk1s1 (No specific role)
    |   Name:                      Macintosh HD (Case-insensitive)
    |   Mount Point:               /
    |   Capacity Consumed:         218261549056 B (218.3 GB)
    |   FileVault:                 No
    |
    +-> Volume disk1s2 4BC0480C-2FED-4B48-A3A5-5E133B707776
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk1s2 (Preboot)
    |   Name:                      Preboot (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         19046400 B (19.0 MB)
    |   FileVault:                 No
    |
    +-> Volume disk1s3 DF8D07CD-27C0-4EB2-A939-2D3E2E64EB66
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk1s3 (Recovery)
    |   Name:                      Recovery (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         509820928 B (509.8 MB)
    |   FileVault:                 No
    |
    +-> Volume disk1s4 27BDB6EB-9BE8-417E-8B03-D2C03E64DD30
        ---------------------------------------------------
        APFS Volume Disk (Role):   disk1s4 (VM)
        Name:                      VM (Case-insensitive)
        Mount Point:               /private/var/vm
        Capacity Consumed:         2147504128 B (2.1 GB)
        FileVault:                 No
MacBook-Pro:~ root# 
MacBook-Pro:~ root# 
MacBook-Pro:~ root# diskutil mount -mountPoint /private/var/vm disk1s4
Volume VM on disk1s4 mounted
MacBook-Pro:~ root# 


MacBook-Pro:~ root# vi /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
MacBook-Pro:~ root# cat /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>EnableTransactions</key>
    <true/>
    <key>Label</key>
    <string>com.apple.dynamic_pager</string>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>POSIXSpawnType</key>
    <string>Interactive</string>
    <key>ProgramArguments</key>
    <array>
        <string>/sbin/dynamic_pager</string>
                <string>-F</string>
                <string>/private/var/vm/swapfile</string>
    </array>
</dict>
</plist>
MacBook-Pro:~ root# ls -l /sbin/dynamic_pager
-rwxr-xr-x  1 root  wheel  43920  1 19 16:32 /sbin/dynamic_pager
MacBook-Pro:~ root# ls -l /private/var/vm/swapfile*
-rw-------  1 root  wheel  1073741824  3 28 00:36 /private/var/vm/swapfile0
1
  • I see you've tried to edit your answer, but the system didn't recognize you. Please create an account and ask via the Contact Us form to have it merged with your old one.
    – Glorfindel
    Mar 27, 2018 at 16:57
1

I have exactly the same symptoms. I installed High Sierra 10.13.4 onto a freshly formatted APFS external, thunderbolt SSD. Activity Monitor shows no swap space, and diskutil apfs list shows that the VM partition is not mounted, just as above. I have been getting repeated panics when I run out of memory (my computer only has 4 GB of RAM).

My solution, which I haven't tested yet, is to make a Carbon Copy Clone of the external disk, then erase and reformat it (using the "Partition" command of Disk Utility) as Mac OS Extended (Journaled), and then restore using CCC. This should give me back my VM.

1

I ran into this issue when I upgraded to Mojave. My OS is installed on an external SSD. My fix ended up being similar Michael Golban's but I needed an extra command.

I ended up writing a small bash script and loading it in with a LaunchDaemon.

/usr/local/sbin/mount_swap.sh

#!/bin/bash
/sbin/mount_apfs disk3s4 /private/var/vm
diskutil mount -mountPoint /private/var/vm disk3s4

com.local.mountswap.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
     <key>Label</key>
     <string>com.local.mountswap</string>
     <key>ProgramArguments</key>
     <array>
          <string>/usr/local/sbin/mount_swap.sh</string>
     </array>
     <key>KeepAlive</key>
     <dict>
    <key>SuccessfulExit</key>
    <false/>
     </dict>
</dict>
</plist>

As soon as these commands were run during testing, the "Swap Used" line in the Activity Monitor would start showing positive values.

1

I've encountered this very same problem on one occasion and fixed it with Michael Golban's simplest solution above, i.e adding a plist to directly mount the APFS VM Volume.

Unfortunately, that solution didn't work with other Macs because the disk volume numbering randomly changed for some unidentified reason. That's when I began trying the various above scripts, but couldn't find a 100% reliable one. Lint's proposition doesn't work if /private/var/vm/sleepimage does exist prior to mounting the APFS VM volume on /private/var/vm/, which was my case. So I started writing my own script and noticed the VM Volume still wasn't mounted after boot, and realized the volume could get unmounted during the boot process. After many rewrites and tests, I'm now happy to share a working solution.

/Library/LaunchDaemons/local.mountvm.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
        <string>local.mountvm</string>
  <key>Program</key>
        <string>/usr/local/bin/mountvm.sh</string>
        <key>KeepAlive</key>
        <dict>
                <key>Crashed</key>
                <true/>
                <key>SuccessfulExit</key>
                <false/>
        </dict>
</dict>
</plist>

/usr/local/bin/mountvm.sh

#!/bin/bash
# set -x

# This script is intended to fix a problem where macOS (above 10.13) won't mount its dedicated virtual memory APFS volume 
# when run from an external SSD drive. Should work using macOS 10.13 and above (10.14.6 successfully tested). It logs its activity in /Library/Logs/mountvm.log.


# Just to make the rest more readable, -n is used to trigger echo -n and -c is used to clear the logfile
Log_input () {
    case $1 in
    "-c")
        echo "$(date) : $2" > /Library/Logs/mountvm.log 
        ;;
    "-n")
        echo -n "$(date) : " >> /Library/Logs/mountvm.log
        ;;
    *)
        echo "$(date) : $1" >> /Library/Logs/mountvm.log 
        ;;
    esac
}


# Makes sure we have an APFS Volume onboard, otherwise exits
if [ "$(/usr/sbin/diskutil ap list)" == "No APFS Containers found" ]; then
    Log_input "-c" "No APFS Volume found, exiting."
    exit 255
fi

# Grabs VM volume string from system disk (should work even with several OS disks connected)
ROOT_DISK=$(/usr/sbin/diskutil ap list | grep -B 2 -E '/$' | grep disk | awk '{ print $6 }' | cut -c 1-5)
VM_VOLUME=$(/usr/sbin/diskutil ap list | grep -A5 $ROOT_DISK | grep "(VM)" | awk '{ print $5 }')

# Makes sure we have a VM Volume to mount (if anyone can help with a regex matching disk0s1, disk1s4 etc. please reach out)
if [ "$(echo $VM_VOLUME | cut -c 1-4)" != "disk" ]; then
    Log_input "-c" "Unable to find a VM Volume to mount, exiting."
    exit 255
fi


# From here we should be safe to proceed

# Mount attemps counter
MOUNT_ATTEMPTS=0

# Clears log previous entries
Log_input "-c" "Starting mount_vm.sh, VM Volume is $VM_VOLUME"

# Mounts the VM volume, then keeps checking it remains so every ten seconds during 5 minutes 
while [ $SECONDS -lt 300 ]
do 
    /usr/sbin/diskutil ap list | grep -A5 $VM_VOLUME | grep "Not Mounted" >> /dev/null
    VM_status=$?
    case $VM_status in
    "0")
        ((MOUNT_ATTEMPTS++))
        Log_input "Attempt to mount $VM_VOLUME #$MOUNT_ATTEMPTS"
        Log_input "-n"
        /usr/sbin/diskutil mount -mountPoint /private/var/vm/ $VM_VOLUME >> /Library/Logs/mountvm.log
        ;;
    "1")
        Log_input "$VM_VOLUME is already mounted, waiting..."
        ;;
    *)
        Log_input "grep command error, exiting."
        exit 255
        ;;
    esac
    sleep 10
done


# Wait another 10 seconds...
sleep 10

# before writing final log input
case $VM_status in
"1")
    if [ $MOUNT_ATTEMPTS -eq 0 ]; then
        Log_input "$VM_VOLUME was alreaddy mounted at script startup and remained so until script exited after $SECONDS seconds elapsed." 
    else
        Log_input "$VM_VOLUME remained mounted after $MOUNT_ATTEMPTS attempt(s), exiting after $SECONDS seconds elapsed." 
    fi
    ;;
"0")
    if [ $MOUNT_ATTEMPTS -gt 0 ]; then
        Log_input "$VM_VOLUME kept getting unmounted after $MOUNT_ATTEMPTS attempts, exiting after $SECONDS seconds elapsed." 
    fi
    ;;
esac

exit 0

Notes :

  • on some Macs I noticed that mountvm.log may end without its final entries, meaning the script got killed. It seems the KeepAlive conditions set in local.mountvm.plist aren't enough to restart the script which may lead to a non working virtual memory situation.

  • I also noticed that /private/var/vm folder and its content may be owned by the local administrator account instead of root, which I've been unable to correct even with SIP disabled.

1
1

The following command fixed the issue on my macOS Mojave (10.14.6). I'm also using a bootable external HDD.

sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true

This command allows the system to mount the drive earlier in the process (before login). So, I think it make it available when the system needs (normally too soon) to update the default path of the swap.

enter image description here

0

I am in this situation too, booting from a USB3-connected Samsung T5 SSD. I tried lint's solution, however in my case the command

/usr/sbin/diskutil list | grep "VM" | awk '{ print $7 }'

generates two answers, as both the internal hard-drive and the external SSD contains a swap (VM) partition. I can't come up with a solution to this problem (automating the mounting process at boot) myself, so can someone help?


[Pinetops] Oddly, I cannot add a comment, so I will edit your "answer" instead. I was in a similar situation (macOS Mojave booting off of a Samsung T5 1GB SSD). I too see two answers when running the above diskutil command, so I think that lint's answer will not work for me (plus, I see a file named /private/var/vm/sleepimage even though the VM is not mounted). However, I gave Michael Golban's answer a try and it worked with minimal effort. First, I had to figure out which VM was to be mounted when I boot off of the Samsung SSD. I did this with the following command and then looked to see which disk was mounted to /.

/usr/sbin/diskutil ap list

The relevant result for me was:

+-> Volume disk5s1 14706492-442E-3E44-84D8-C3A216EAB040
|   ---------------------------------------------------
|   APFS Volume Disk (Role):   disk5s1 (No specific role)
|   Name:                      Ext macOS (Case-insensitive)
|   Mount Point:               /
|   Capacity Consumed:         417911861248 B (417.9 GB)
|   FileVault:                 No

So now I know that the VM should be on disk5. I look further down in the output of diskutil and I see:

+-> Volume disk5s4 8FF45FA5-EDB8-4812-947A-C1163BBDF5C4
    ---------------------------------------------------
    APFS Volume Disk (Role):   disk5s4 (VM)
    Name:                      VM (Case-insensitive)
    Mount Point:               Not Mounted
    Capacity Consumed:         10737463296 B (10.7 GB)
    FileVault:                 No

Viola! It should be mounting disk5s4 as swap space. So I followed Michael Golban's answer, substituting disk5s4 everywhere he used disk3s4 in his specific example. After a reboot, diskutil ap list shows that disk5s4 is properly mounted.

+-> Volume disk5s4 8FF45FA5-EDB8-4812-947A-C1163BBDF5C4
    ---------------------------------------------------
    APFS Volume Disk (Role):   disk5s4 (VM)
    Name:                      VM (Case-insensitive)
    Mount Point:               /private/var/vm
    Capacity Consumed:         10737463296 B (10.7 GB)
    FileVault:                 No

Also, vm_stat shows non-0 values for Swapins and Swapouts.

Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                               15355.
Pages active:                           1504355.
Pages inactive:                         1006398.
Pages speculative:                       593600.
Pages throttled:                              0.
Pages wired down:                        695931.
Pages purgeable:                         217108.
"Translation faults":                  20908140.
Pages copy-on-write:                     566900.
Pages zero filled:                     14492420.
Pages reactivated:                      1136316.
Pages purged:                            693655.
File-backed pages:                      1424716.
Anonymous pages:                        1679637.
Pages stored in compressor:             1427995.
Pages occupied by compressor:            378113.
Decompressions:                          426681.
Compressions:                           3751860.
Pageins:                                2715810.
Pageouts:                                 14437.
Swapins:                                 438359.
Swapouts:                                917646.
0

I had a similar experience, but my setup is a bit unusual. I have:

  1. Originally a Fusion Drive (128SSD+1TBHDD), which I swapped the HDD for a third party SSD (Crucial MX500 (1TB)). And yes, I recreated the Fusion drive after the swap. So, now I am back to the original Fusion Drive of 1.2TB, but composed of two SSDs (both APFS).
  2. A bit more RAM than most systems, at 32GB (originally 16GB, upgraded to 32GB).
  3. Three external drives, 2 SSDs connected via USB 3.0 (AKA 3.1v1), one at 500GB (APFS) and the other at 256GB (HFS+), and the third drive is a regular HDD at 3TB (HFS+), also connected via the same USB bus.
  4. Running Mojave.

Now, here's where/when the problem presented itself: I decided to convert the 256GB SSD to APFS. Conversion went all right. No issues. HOWEVER, as soon as that finished, my monitoring tool (iStat) started showing an extra drive labeled "VM". I was suspicious... Also unique in my case: I run virtual machines using Parallels. As I said, I was curious as to what this new drive labeled VM was doing in my iStat menu... I kept poking around and realized this was supposed to be the swap file. I opened up Activity Monitor and to my surprise my memory was nearly maxed out, and the swap file value was reading 0, which is NOT correct. OS X is supposed to start paging things onto the swap drive, instead of running out of memory.

I had a hunch that the OS is missing something when it converts a volume to APFS and that rebooting was all I needed to get things back in order. Well, in MY case, that did the trick. After the reboot the system started paging back to the swap file as it should, and iStat no longer showed the "mysterious" VM drive. And all my drives were in their correct respective file system versions.

Sorry. I know this probably does not help resolve the original question, but it might shed some light on the inner workings of the problem.

Be well everyone, Rapha.

0

Thank you for this question and answers! I've been looking for a solution for this problem off and on for months until I stumbled on this page.

I'm running an iMac booted on an external thunderbolt SSD. Breathed new life into the machine and I don't want to take the front panel screen off to change the hard drive. The awesome thing about Thunderbolt is the computer treats an external drive as if it were attached internally.

This answer is modified from Lint's answer. Credit to him for the work. The site wouldn't let me add a comment to his answer so I'm posting here.

Made some changes to his script:

  1. I have a backup clone of my OS drive which also has a VM volume. Lint's script was returning two VM results for me. This modification allows you to enter in your OS hard drive name and the correct VM volume will be returned and mounted.

  2. Lint's script looks for a sleep image. For two computers I'm applying this fix to, the script was finding the sleep image even though the VM wasn't mounted. The result was the script did not mount the VM.

  3. I got rid of the if statement to check for a mounted volume and just try to mount the volume 5 times no matter what. If the volume is already mounted, no harm is done and you get a message the volume is mounted. Did this because I too was having issues with mounting using the launchd daemon.

  4. wrote echo statements to a log file so I could see the script output when testing during a reboot.

  5. If running the script to test, you need to sudo sh mountvm.sh.

  6. the VM volume un-mounts once a user or possibly all users log out. I added the launch daemon to /Library/LaunchDaemons so it will run as root. As long as you don't log out of your user, the VM will stay mounted. If you reboot the computer the script should re-mount the VM.

Thank you Lint! And everyone else who helped to answer this question! I now have a mac that isn't crashing because the memory is filling up!

Change the OS_BOOT_NAME variable to the name of the Hard drive you are booting into.

#!/bin/bash
# Mount the APFS VM volume if it isn't already mounted
OS_BOOT_NAME="X"
echo $(date) > /Library/Logs/mountvm.log
VM_VOLUME=$(/usr/sbin/diskutil list | grep -A5 "APFS Volume $OS_BOOT_NAME " | grep "VM" | 

awk '{ print $7 }') 
echo "VM Volume is $VM_VOLUME"
echo "VM Volume is $VM_VOLUME" >> /Library/Logs/mountvm.log

for i in {1..5}
    do
        /usr/sbin/diskutil mount -mountPoint /private/var/vm/ $VM_VOLUME >> /Library/Logs/mountvm.log
                sleep 60
                echo "Mount Attempts: $i"
        echo "Mount Attempts: $i" >> /Library/Logs/mountvm.log
    done

exit 0
-1

Mac OSX High Sierra is a linux derivative of sorts, and many linux OS's recommend disabling swap when installing to an SSD as the type of storage used in a swap partition puts a high load on the magnetic media of the ssd in a potentially destructive way. So, I would guess that High Sierra disables swap space on ssds as standard. My preferred option is to install the swap space on a separate traditional drive.

https://askubuntu.com/questions/652337/why-no-swap-partitions-on-ssd-drives

3
  • 1
    MacOS is not a Linux derivative - In fact the basic design predates Linux. Its swap is rather different - also swap on hard disk rather than SSDS will slow the system massively.
    – mmmmmm
    Aug 20, 2018 at 16:31
  • I agree with miller, that it is not advisable to put swap on your primary SSD. Swap on any UNIX system is volatile and constant writes will eventually cause issues with the SSD and sectors will have to get remapped due to failed magnetic media. And if the disk fails, then your system will not boot. A non primary SSD for swap would definitely be much faster than a traditional platter based external disk and would be the way to go.
    – john
    Oct 12, 2018 at 6:38
  • As for the linux<->macOS, Chicken/egg discussion: are all derivatives of Dennis Ritchie's AT&T Unix. en.wikipedia.org/wiki/Unix
    – john
    Oct 12, 2018 at 6:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .