A RAM disk is a virtual drive created in a free area of RAM that the OS sees as a normal local hard drive. The advantage of RAM Drive is its very high read/write speed (up to 10 times faster than SSD and up to 2-3 times faster than NVME M.2). A RAM disk can be used on computers with large amounts of RAM to store cache and temporary application files. Mostly RAM drive is used to store browser cache, temporary SQL databases, graphics or video rendering application cache, etc. This improves application performance and significantly offloads physical disks. The contents of the RAM disk are usually erased when the computer is restarted.
Contents:
- Create a RAM Disk Drive on Windows 10 and 11
- Creating In-Memory RAM Drive on Windows Server
Create a RAM Disk Drive on Windows 10 and 11
Windows 10 and 11 don’t have built-in tools for creating RAM drives, so you’ll need to use third-party apps(AMD RAMDisk, ImDisk, PassMark OSFMount, StarWind RAM Disk, etc.).
In this example, we will look at the open-source ImDisk Toolkit (https://sourceforge.net/projects/imdisk-toolkit/). Its advantages:
- Free
- Lightweight
- There is no limit to the size of the RAM drive
- Saves RAM drive files to the local disk when the computer is turned off.
- Download and install the ImDisk Toolkit program by running install.bat;
- Once the installation is complete, open the RamDisk Configuration shortcut on your desktop;
- On the Basic tab, you need to specify the size of the RAM drive(it is generally recommended that no more than 20-30% of the RAM should be allocated for this purpose), assign a drive letter, and choose whether the RAM drive should start automatically on Windows boot;
- You can use environment variables or symbolic links to automatically redirect TEMP folders to the RAM disk;
- Click Mount to enable RAM Drive. Open File Explorer and check that a new drive of the specified size appears;
- By default, the contents of the RAM drive are cleared when Windows restarts. You can automatically save the contents of the RAM disk to a local folder when you turn off the computer. To do this, go to the Data tab, specify the target directory, and check the option Synchronize at System Shutdown. The contents of this directory are copied to the RAM disk when the operating system boots.
You can move certain application caches to the RAM disk using Windows symbolic links. For example:
Edge Cache:
mklink /j "%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Cache\" "R:\edge\Default\Cache"
mklink /j "%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Code Cache\" "R:\edge\Default\Code Cache"
mklink /j "%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Service Worker\CacheStorage\" "R:\edge\Default\Service Worker\CacheStorage"
Microsoft Teams Cache:
mklink /j "%userprofile%\AppData\Roaming\Microsoft\Teams\Cache\" "R:\ msteams\Cache"
mklink /j "%userprofile%\AppData\Roaming\Microsoft\Teams\Code Cache\" "R:\msteams\Code Cache"
mklink /j "%userprofile%\AppData\Roaming\Microsoft\Teams\Service Worker\CacheStorage\" "R:\msteams\Service Worker\CacheStorage"
Or you can change the cache path in the app settings. For example, to enable the Google Chrome browser to store data on a RAM drive, add the following parameter to its shortcut:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disk-cache-dir="R:\Chrome"
Google Chrome will cause less wear and tear on your SSD drive in this mode.
Check RAM drive read/write performance using the Crystal Disk Mark Tool. In this test, a DDR4 RAM disk’s read/write speed is 2-3 times faster than an SSD NVME M.2 drive.
Creating In-Memory RAM Drive on Windows Server
In Windows Server, you can create a RAM drive without using third-party tools. You can use the iSCSI driver to allocate a part of the RAM on the server.
Install the iSCSI Target Server role using the Server Manager (File and Storage Services -> File and iSCSI Services).
Open ports for the iSCSI service in the Windows Defender Firewall. You can allow access in the Windows Firewall graphical management console, or you can enable firewall rules using PowerShell:
Set-NetFirewallRule -Name MsiScsi-in-TCP -Enabled True
Set-NetFirewallRule -Name MsiScsi-out-TCP -Enabled True
To allow traffic to the loopback interface for iSCSI, change the value of the DWORD parameter AllowLoopBack to 1 in the HKLM\Software\Microsoft\iSCSI Target registry key. You can change the registry parameter from PowerShell with a command:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\iSCSI Target' -Name AllowLoopBack -Value 1
Then create a 5GB virtual RAM drive:
New-IscsiVirtualDisk -Path "ramdisk:testRAM.vhdx" -Size 5GB
Now you need to create an iSCSI target pointing to the IP address of your server (not localhost!):
New-IscsiServerTarget -TargetName targetRAMDisk -InitiatorIds @("IPAddress:10.1.1.200")
Connect the RAM disk to the created iSCSI target:
Add-IscsiVirtualDiskTargetMapping -TargetName targetRAMDisk -DevicePath "ramdisk:testRAM.vhdx"
Go to Server Manager and select Tools -> iSCSI Initiator.
Specify the IP address of your server in the Targets tab and click Quick Connect to add your iSCSI target.
You can connect the iSCSI Target with the command:
Get-IscsiTarget | Connect-IscsiTarget
Now open the Disk Management Console (diskmgmt.msc)
and check that you have a new 5GB drive. This is the RAM disk we created. Initialize the disk, create a partition and format it, and then assign a drive letter.
You can initialize a RAM disk and assign a drive letter using the built-in PowerShell cmdlets to manage disks and partitions.
Get-Disk | Where partitionstyle -eq 'raw' | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "disk2" -Confirm:$false
Now you can move app files to the RAM drive and reconfigure your software to use it.
When the server is restarted, the RAM disk is removed with all its contents and must be re-created.
Unfortunately, the test showed that the performance (iOPS) of a RAM disk created via an iSCSI target on Windows Server was almost 2 times lower than that of an ImDisk RAM disk.
Use the following commands to remove your RAM drive:
Remove-IscsiVirtualDiskTargetMapping -TargetName targetRAMDisk -DevicePath "ramdisk:testRAM.vhdx"
Remove-IscsiServerTarget -TargetName targetRAMDisk
Remove-IscsiVirtualDisk -Path "ramdisk:testRAM.vhdx"