Virtual memory disk is a technology that simulates part of the memory (RAM) as a hard disk by software.
Since memory has a speed of up to several gigabytes per second, using simulated hard drives under appropriate circumstances can greatly enhance system performance and protect hard drives and privacy.
Mac OS X is a Unix-type system that natively supports creating ramdisks on the command line. So you can eliminate the need to buy iRamdisk, tmpDisk such chicken ribs software.
If you carefully follow this tutorial step by step, you can easily create a Ramdisk that is automatically created upon startup
1. Open Dashbord and go to the script editor (as it was called in 10.10) in utilities. Enter the following:
do shell script "
if ! test -e /Volumes/\"Ramdisk\" ; then
diskutil erasevolume HFS+ \"RamDisk\" `hdiutil attach -nomount ram:/ / 2097152 `
fi
mkdir /Volumes/Ramdisk/TempDownloads
mkdir -p /Volumes/Ramdisk/Library/Developer/Xcode/DerivedData
mkdir -p /Volumes/Ramdisk/Library/Developer/CoreSimulator/Devices
mkdir -p /Volumes/Ramdisk/Library/Caches/Google
mkdir -p /Volumes/Ramdisk/Library/Caches/com.apple.Safari/fsCachedData
mkdir -p /Volumes/Ramdisk/Library/Caches/com.netease.163music
mkdir -p /Volumes/Ramdisk/Library/Caches/Firefox
"Copy the code
You can create a 1GB virtual ram disk. 2087152=1024*1024*1GB*2 (the last 2 must be multiplied). Instead of creating a 1GB integer, you actually created something around 1.07GB. It may be the system’s way of calculating the disk size, but this formula is definitely correct. (If it is 2GB then it is 1024*1024*2GB*2=4194304, change this number body can be.)
2. Save the above script in APP format to become an executable file.
3. Open the System and Preferences – Users and Groups – Login TAB
4. Click the small lock in the lower left corner to unlock it and press the plus sign to join the script we just wrote to realize the automatic startup of the script and create a 1GB virtual disk.
In addition to creating the disk, this script also creates several folders within the disk:
The root directory has TempDownloads and a Library folder. There are Caches and Developer folders in the Library folder. (Caches for Chrome and Safari browser Caches, Developer for Xcode temporary compilation space files)
5. Next, use the browser cache and Xcode temporary compilation space to create a surrogate (a soft link, like a Windows shortcut) on the memory disk.
Make sure to exit Safari, Chrome, and Xcode first, and then enter them on the terminal (one by one).
rm -rf ~/Library/Caches/Google
rm -rf ~/Library/Caches/com.apple.Safari
rm -rf ~/Library/Developer/Xcode/DerivedDataCopy the code
The above three commands remove the temporary cache folders of three programs on disk. Rest assured, 100% safe. As soon as you open the program, these three folders will be automatically generated.
6, before executing the following three commands, we must execute our script, open our ram disk on the desktop or in the finder, and see the directory we created in it, to execute the following program:
ln -s/Volumes/Ramdisk/Library/Caches/Google ~/Library/Caches/Google
ln -s/Volumes/Ramdisk/Library/Caches/com.apple.Safari~/Library/Caches/com.apple.Safari
ln -s/Volumes/Ramdisk/Library/Developer/Xcode/ ~/Library/Developer/Xcode/DerivedDataCopy the code
7. Then, open Safari or Chrome or Xcode to test and see that their cache files are generated in the relevant directory on the memory disk. At the same time, if we open the original directory of these programs, we will find that they will automatically jump to the corresponding directory of the RAM disk, and no garbage will be generated in SSD. We are done here. All the above commands only need to be entered once, and will be automatically available after startup.
You are advised to disable hibernation mode. The default hibernation mode of the Mac is 3, which is a mixed hibernation mode. When you close the cover and save the work to the memory, you also save a copy of the work to the local disk in case of power failure. For laptop, this mode is redundant, low battery or choose to turn off. Mode 3 means that the work in memory will be saved to a sleep image file on disk, which again causes a lot of reads and writes.
For compatibility, it is recommended to simply change the mode to 0, that is, only enable sleep mode. (Close lid work only save to memory), close sleep:
sudo pmset-a hibernatemode 0Copy the code
To prevent the file from being regenerated after a restart. (Not recommended, not necessary)
sudo touch /private/var/vm/sleepimage
sudo chmod 000 /private/var/vm/sleepimageCopy the code
Other related commands:
pmset -g | grepHibernate (View the current Hibernate schema)ls -lh /private/var/vm/sleepimage (check the size of the sleepimage file)Copy the code
In the future, if you need to turn on hibernate mode, you can set this value to the default:
sudo pmset -a hibernatemode 3Set hibernatemode to the default value3Sudo rm /private/var/vm/sleepimageCopy the code
A few tips and instructions:
-
Xcode compilers generate a large number of intermediate files, usually hundreds of megabytes or more, which is necessary to place on memory disks.
-
If you want to restore the original cache locations of the three programs, just type the three commands starting with rm -RF again.
-
If the RAM disk is full, you can manually clear it or automatically clear it after restart.
-
Linking the whole ~/Library/Caches/ to the memory disk is not recommended, because there is a com.apple.helped folder, which automatically downloads help files to hundreds of megabytes using programs like Xcode. After each cleaning, it will be re-downloaded and generated, which will seriously consume resources. He might as well be lying on the hard drive.
-
Except for these three programs, the cache of other programs is generally too small to worry about. Cleared instead of affecting the program’s startup load time. Just clean it every two weeks with cleanMyMac. (Let go of com.apple.helped, the files were helped semiannually, as long as they were not excessively large and were several gigabytes in size.)
-
If the directory is linked to the Ramdisk, the cleaning software will not help you to clean it. You can only manually clean it, or restart it automatically.