Prolong lifetime of MacBook’s SSD by disabling swap and other minor tweaks

Prolong lifetime of MacBook’s SSD by disabling swap and other minor tweaks

0. Prologue

After replacing 128GB SSD with a 500GB one in my 7 year-old MacBook Air, I’ve noticed a serious issue… Since 4GB RAM is very limited (and not designed) for the contemporary macOS, it runs out of memory very often especially when I opens multiple tabs in browser and edits photo in Lightroom simultaneously. It isn’t a big deal because there is swap mechanism, which stores data to disk when the (physical) memory is not enough. However, since the SSDs have finite numbers of P/E (program / erase) cycles, the more intensive the swap uses, the sooner the SSD would be worn out. The lifetime of SSD basically depends on its type of NAND flash. For the SSD I installed, WD SN750 500GB, it uses TLC NAND and declares it has 300TB-write endurance.

SMART information checked with smartmontools

Unfortunately, if the SSD is used as system disk with limited RAM, it will be worn out rapidly by the swap mechanism. For example, my MacBook with new SSD has powered on for 161 hours, and it has been written for ~663GB data(!). To tackle this issue, I should either upgrade my MacBook ($) or try to limit the usage of memory by disabling swap and doing minor tweaks.

1. Disable swap

Be careful! Disable swap would cause kernel panic if there is not enough RAM for processes. Take it at your own risk.

1.0. Disable SIP

From macOS 10.11 to present, there is a built-in system integrity protection (SIP) for preventing malicious modification. To disable swap, first we have to turn SIP off.

  1. Power-off MacBook first, hold Command (⌘) and R, and then start-up the MacBook.
  2. You should see a macOS utilities window.
  3. From the utilities menu, select “Terminal”
  4. Type csrutil disable and press return, the screen should display a message the SIP is already disabled.
  5. From the  menu, press restart to restart MacBook.

1.1. Disable swap

To check the current mode that system manages memory, type sysctl -a vm.compressor_mode in terminal. The default mode is 4, which represents compressing memory and using swap. To disable swap, we should change the mode from 4 to 2, which means compressing memory only.

To modify vm.compressor_mode, type sudo nvram boot-args="vm_compressor=2". Again, anyone running computer without swap file should monitor memory usage carefully to avoid kernel panic!

1.2. Enable SIP (Recommended)

After disabling swap, we should enable system integrity protection (SIP) again for security reason. The steps are similar to disabling swap, and the only difference is the command. Type csrutil enable instead to enable SIP. If you want to disable spindump furtherer (listed below), you should enable SIP later.

2. Disable unused processes

2.0. Disable spindump and tailspind

Here we use launchctl to unload two services, and rename the files.

  1. sudo launchctl unload -w /System/Library/LaunchDaemons/
  2. sudo mv /System/Library/LaunchDaemons/ /System/Library/LaunchDaemons/
  3. sudo launchctl unload -w /System/Library/LaunchDaemons/
  4. sudo mv /System/Library/LaunchDaemons/ /System/Library/LaunchDaemons/

2.1. Disable mds_stores

mds stands for “metadata server”, which is a part of Spotlight in macOS. It indexes for all devices to provide effective search functionality. If you never use Spotlight, you could disable it for saving CPU and memory usage.

To prevent it from indexing all devices, type sudo mdutil -a -i off in terminal.

If you want to enable it again, just replace the command with sudo mdutil -a -i on.

2.2. Disable Adobe CC services

Although Adobe provide amazing products like Lightroom and Photoshop, its background services consume memory and CPU even when the Adobe-related program is not running.

The service corresponding to Adobe CC services is located at /Library/LaunchAgents/com.adobe.AdobeCreativeCloud.plist, to prevent it from auto-launching from log-in, we will use launchctl again: type launchctl unload -w /Library/LaunchAgents/com.adobe.AdobeCreativeCloud.plist in terminal.

To enable it, just replace unload with load in the command.

3. Tab suspender

If you open a lot of tabs in the browser every time like me, you should consider suspending inactive tabs while you are not browsing the website or AFK, to limit the memory usage of browser. The following method is recommended. It is risky to use third-party extensions such as The Great Suspender since it might contain malware.

Microsoft’s Edge has announced built-in “sleeping tab” feature recently (2020/09). To enable it, simply go to Settings → System → Save resources.

Furthermore, you can modify timeout to suspend the inactive and set the allow-list in the configuration page.

A. SMART monitor tools

The disk health information can be inspected with smartmontools. To use it on macOS, either install precompiled package here (download smartmontools-x.x-x.dmg one) or install via brew:

brew install smartmontools

After installing, you can run the command in

smartctl -a disk0

where disk0 is the device name referring to the inspected disk. Device name can be found via Disk

Device name shown in bottom right corner.

Device information such as serial number, temperature, bytes written and read will be shown in the terminal. Note that some NVMe admin commands are not supported currently via smartctl, therefore some detailed NVMe information will not be shown correctly.

Leave a reply