Page 1 of 1

Using Ramdisk as rawdisk for swapspace in Windows

Posted: 9. Nov 2008, 06:48
by Dwarf
I've just been experimenting with this, since it looked to me as an interesting topic to explore. Most of the people were interested in the use of ramdisk for storing windows pagefile. My intention was to try both with the pagefile and the photoshop swap file (though not at the same time)

Since I haven't found any "complete guides" to do this, i've decided to post it here. Hope it will be useful. So, here's how i achieved it under Ubuntu distro:

Code: Select all

sudo gedit /boot/grub/menu.lst
then, look for for something like this:

Code: Select all

title		Ubuntu 8.10, kernel 2.6.27-7-generic
uuid		b360edaf-a86e-48a9-b209-721656f194b7
kernel		/boot/vmlinuz-2.6.27-7-generic root=UUID=b360edaf-a86e-48a9-b209-721656f194b7 ro quiet splash
initrd		/boot/initrd.img-2.6.27-7-generic
quiet
and at the end of this line, add ramdisk_size=VALUE_IN_MB ... example:
kernel /boot/vmlinuz-2.6.27-7-generic root=UUID=b360edaf-a86e-48a9-b209-721656f194b7 ro quiet splash ramdisk_size=768000

so, now there is:

Code: Select all

title      Ubuntu 8.10, kernel 2.6.27-7-generic
uuid      b360edaf-a86e-48a9-b209-721656f194b7
kernel      /boot/vmlinuz-2.6.27-7-generic root=UUID=b360edaf-a86e-48a9-b209-721656f194b7 ro quiet splash ramdisk_size=768000
initrd      /boot/initrd.img-2.6.27-7-generic
quiet
exit and save the file, then restart the system to change the size of ramdisk, since the ramdisk init and creation are taking place during boot.

Useful link on ramdisk creation: http://ubuntuforums.org/showthread.php?t=182764

When the system restarts, you can check your ramdisk by mounting it (sudo mount /dev/ram0 /media/ramdisk) and browsing to its mount point and checking it's free space. If everything went fine, you can proceed to create rawdisk vmdk file that points to your ramdisk. Before doing so, you should unmount the ramdisk (sudo umount /dev/ram0)

So, the next step is to make a filesystem on ramdisk and create a .vmdk file:

Code: Select all

sudo mke2fs /dev/ram0

Code: Select all

sudo VBoxManage internalcommands createrawvmdk -filename /home/username/.VirtualBox/VDI/ramdisk.vmdk -rawdisk /dev/ram0
And you should get this output:

Code: Select all

VirtualBox Command Line Management Interface Version 2.0.4
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

RAW host disk access VMDK file /home/username/.VirtualBox/VDI/ramdisk.vmdk created successfully.
before importing .vmdk file into VirtualBox, you must change its ownership, since the owner is root:

Code: Select all

sudo chown your_username /home/username/.VirtualBox/VDI/ramdisk.vmdk
Then, open your VirtualBox, select your Windows VM, and go into Hard disk section and browse for .vmdk files. You should find ramdisk.vmdk or whatever you named it and be able to set it as an additional hard drive.

Next and final step is to start the virtual machine. During boot, the system could inform you of detecting new hardware as mine did, and you should right-click My Computer and go to Manage. There you should go to Disk Management and you should see your new disk labeled as "Unallocated" and a Wizard "Initialize and convert disk" should pop-up. You just need to select your drive to be initialized and converted, and then right-click Unallocated space and select "New volume" to create partition. For some reason, you can only set up the drive as Dynamic drive, so the only option for this drive is to create Simple dynamic disk.

So that's it. I hope it'll be of use to someone. :)

Posted: 9. Nov 2008, 17:28
by Sasquatch
Why not just increase the RAM for the VM? And if you want a RAM Disk, you can always create one on the Guest. I see little advantages of this approach compared to a Guest side RAM disk.

Posted: 10. Nov 2008, 05:54
by Dwarf
Sasquatch wrote:Why not just increase the RAM for the VM? And if you want a RAM Disk, you can always create one on the Guest. I see little advantages of this approach compared to a Guest side RAM disk.
well, i did it from my own couriosity :)
i saw many topics on that theme and, and wanted to explore, so when i finaly did it, i said to myself why not make a guidelines for others who want to try.
anyway, you are definitely right, i havent had any noticable increase in performance even when i used 2Gb ramdisk which is ridiculous, and the guest side ramdisk is indeed easier to setup and try - though it will let you use only the part of the ram thats mapped to the vm and the second disadvantage should be that guest ramdisk software itself is being virtualized, so should be somewhat slower than this approach. Anyway, again, most of us apprechiate performance increases that are noticable in everyday use, and this one is not that kind of situation ;)

Posted: 15. Jan 2009, 07:10
by veeall
I tried this and it really speeds up photoshop if ramdisk is used as photoshop swap space, but unfortunately i cannot find a way to free the RAM after virtual machine is closed. Any hint?

Thanks!

edit:
Q: Why not just assign more RAM to windows?
A: I assigned 2GB to windows but noticed that while working in Photoshop it does not use all available memory but starts to use scratch disk instead. I have set Photoshop to use 85% of memory, but total memory usage doesn´t go higher than 1.1GB so additional 1GB of RAM swap space would make a difference.

Posted: 15. Jan 2009, 07:22
by TerryE
It is a lot easier just to assign the memory to Windows directly. About the only time that I think that this would really be useful is if you had loads of RAM in your host but you'd maxed out on a 3.5Gb VM and were still paging.

Posted: 15. Jan 2009, 07:45
by veeall
To possibly pinpoint a problem here´s my specs:
4GB RAM
Photoshop 6.0 (yes! The Old)
Windows XP and Windows 2000 both behaved likewise.
AMD DualCore 4200+
no AMD-v.
Virtualbox 1.5-2.1 all the same.
Host is Slackware Linux 12.1

And as i said windows total memory usage hardly goes over 1.1GB while swaping a lot. I tried if Windows reuses memory occupied by ramdisk but it seems not being the case also.

Thanks for info on how to unload vmdk-ramdisk from memory without rebooting if there is a way to do it. If no then what the hack, Virtualbox is still awesome.

Posted: 15. Jan 2009, 16:55
by TerryE
I wonder why you are using such an obsolete version of VBox. 1.6.6 is the last (and pretty stable) version of the 1.x series.

Posted: 15. Jan 2009, 20:36
by veeall
I am using latest Vbox. I´ve been using versions of 1.5 to 2.1 and this memory limit is noticeable in every version. I guess it may be something to do with the old Photoshop version i´m using, cannot blame Virtualbox. Just that this vdmk-ramdisk-how-to became really handy to maximize PS power in this situation.

So thanks, Dwarf, for posting it.

Posted: 15. Jan 2009, 22:31
by Sasquatch
Why not increase the RAM and disable the pagefile on the Guest? That should prevent PS to use it, as it's no longer there. Unless it's starts to bug you that you don't have a swap file.

Posted: 16. Jan 2009, 01:55
by veeall
It probably starts to bug me pretty soon because while working with .psd files of ca 400MB of size it is not possible to fit all data in RAM alone.

I tested photoshop file loading time with and without ramdisk by loading 355MB multilayer psd to photoshop, it filled 2GB of ramdisk straight away with 1.5GB of data in tmp file and keeping this data in ramdisk gave me about a third faster file loading time than with regular scratch disk. I suppose the same difference comes up when accessing cached data while editing the file.

The problem with my vm is that windows total memory usage does not grow over about 1.1GB even if i assign more RAM to virtual machine. I just tried it by assigning 2560MB of RAM to winXP, i have Photoshop memory limit set to 85% and was loading a 541MB PSD file, memory usage stopped just at 1.13GB as reported by windows Task Manager. Then i loaded another 128MB PSD and while photoshop tmp file increased to 1.8GB, RAM usage stayed low at 1.13GB in windows. I guess it might have something to do with ancient Photoshop version i have (6.0). Can anybody verify if this memory quirk exists with newer Photoshop?

But probably it really is better for me to create ramdisk in guest, that way problem with photoshop memory handling is worked around, and i suppose RAM would be freed after shutting down the VM. Also vdmk based ramdisk is needed to be formatted and assigned a drive letter upon every boot in windows.

Posted: 16. Jan 2009, 02:18
by TerryE
If you are going to use a RAMdisk, then why not just configure /tmp to be a ramdisk? Create a dynamic VDI for your pagefile.sys, add it to your XP machine, format it add it to your system, move your page file to it then shut down the machine, and release and unregister the VDI. Now bzip2 the VDI to a backup before you shudown your host PC (otherwise it well get lost). This bz2 will be tiny since the disk will be nearly all zeros.

Now wrap your start VM in a small script that checks to see if the /tmp/pagefile.vdi exists and if not then it unpacks the bz2 file back onto /tmp. Register the VDI and reattach it to the VM before starting it. You reverse the process on shutdown, except that you don't need to resave the pagefile VDI unless of course you want to hibernate your VM.

Hey Presto! you now have the speed of RAMdisk without the need to dedicate one to your VM.

Posted: 16. Jan 2009, 03:16
by veeall
Actually i tried this before and it worked well with win2000 but misbehaved in winXP. Maybe i did something wrong. I´ll investigate into it some more. Thanks!