在Windows中我一直都是禁用虚拟内存的。感觉这样可以快一些。还可以减少不必要的硬盘读写。对于MacOSX也有同样的想法。在网上搜索了一下,有一些使用SSD的兄弟为了保护SSD,延长寿命,也想关闭mac的dynamic_pager。找到以下两个方法可以帮助我们关闭MAC的虚拟内存:
方法一:
- Open Terminal in the Applications -> Utilities folder. Type the following, hitting Return after each command.
cd /etc — this brings you to the file you want to work with
sudo cp /etc/rc /etc/rc.orig — this makes a copy of the file etc/rc called etc/rc.orig; enter administrative password when asked.
sudo pico /etc/rc — this brings you into a text editing program to edit the file; enter administrative password when asked. - Use the arrow keys to go down until you see one of these lines:
- In osx 10.3.x: dynamic_pager -F ${swapdir}/swapfile
- In osx 10.2.x: dynamic_pager -H 40000000 -L 160000000 -S 80000000 -F ${swapdir}/swapfile
- Type # at the beggining of the dynamic pager line. Hit Control-X to save file then answer Y and hit Return.
- Type exit — this logs you out of the Terminal session.
- Now delete the old swap files securely. In osx 10.3.x, type sudo srm /private/var/vm/swapfile*. In osx 10.2.x, you should use a security application such as PGP to securely delete any remaining swap files located in /private/var/vm/. The swap files are named: swapfile*
- Restart your computer and check to make sure swap is off. Start terminal and type ls -al /private/var/vm/ — this lists the contents of /private/var/vm/. You should see no files named: swapfile*
方法二:
- sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
- sudo rm /private/var/vm/swapfile*