How To: Speed Up Linux by Minimising Swapiness

Swappiness is a setting in the Linux kernel which controls how amenable to paging things in memory out to disk the kernel is (like using virtual memory in Windows), and in Ubuntu it comes with a default value of 60 – which for a box with lots of memory is too high in my humble opinion. The range of values goes from 0 (never use the swap file unless absolutely critical) to 100 (page stuff out to file whenever it feels like).

You can easily check your current swappiness value like this:

And you can change the swappiness of the system on the fly (but it’ll go back to the value in the sysctl.conf file after a reboot) like this:

My laptop has 4GB of RAM, and even with a bunch free, Linux decides to swap stuff out to file quite often with a swappiness setting of 60, which can slow the box to a crawl. To fix this, and permanently insist that all physical RAM is used up before starting any paging at all,, simply change the setting to something like 10 like this:

Then, when the file is open, either add the line vm.swappiness=10 to the bottom of the file, or if it already exists just modify the value, then reboot.

To find out more about the whole swappiness thing, try this article.

Winscape – Virtual Windows

How nice would it be to have the view out of your windows be, well, anything? I’d have something with the ocean in it I think. The Golden Gate bridge bit looked really nice & that’s got water, so it’d be a good start. The train journey one would prolly make me a bit nauseous though!

Where or what would you have?

How To: Switch a VirtualBox Windows Guest Hard Drive from IDE to SATA Mode

By default, any Hard Drives you create for your Virtual Machines use a virtual IDE controller, which takes more CPU to operate and is slower in operation than a virtual SATA controller. So, it’d be nice to just flick a switch and say Use a virtual SATA controller instead and get instantly higher disk performance, right? Only Windows will BSOD on you if you try that, so you have to do a bit of tweaking first for it to work.

1.) While Vista and Windows 7 come pre-installed with SATA drivers, XP does not – so if your virtual guest OS is XP you’ll need to go get the Intel Matrix Storage Driver from here. Note: Please see the bottom of this article for Windows 7 IDE to SATA instructions.

Update: Some people have reported that Intel have changed the version of the Matrix Manager and it no longer works with VirtualBox (see comments), so instead, why not try this, which is the version of the Intel SATA Matrix Manager driver I used when I did this originally. Launch the installer and slap Next/Next/Finish until it’s installed.

Install Intel Matrix Storage Driver

2.) Next we need to remove our current IDE/ATAPI Drive Controllers from the Device Manager, so right click on My Computer and select Manage from the pop-up menu, then click on Device Manager in the left pane of the Computer Management window and expand the IDE ATA/ATAPI controllers section in the right pane.

Manage My Computer

IDE ATA/ATAPI Controllers

3.) You should see Primary and Secondary IDE Channels, plus some other bits as pieces as shown in the screenshot above – now it’s time to delete them by selecting each one in turn and then pressing the delete key on the keyboard. It might look like a dodgy thing to do, but trust me – I found this trick out while working as a Subsystem Integration bod. If you’ve got one build running on one piece of hardware, and you want to transfer the entire build (via ghost or whatever you want) to another piece of hardware with different controllers, you’ll get a BSOD unless you first delete the drive controllers like this, backup your build, and then ghost it to your new hardware setup.

After you delete each one Windows will say you need to reboot for changes to take effect – don’t. Get rid of as many device controllers as you can, and don’t worry if the Primary IDE controller comes back on its own as soon as you’ve removed it, it’s just there to keep things ticking over until you finally do reboot.

Remove IDE Controller

Don't Reboot Windows Yet

4.) Power off (not suspend) your Virtual Machine then click on the Settings button with the machine you’re working on selected. Then, under the Storage item of the left pane remove your virtual machines hard drive from the IDE Controllers section, add a New Controller and choose SATA Controller, then add your virtual hard drive to the new SATA Controllers section as shown below:

Switch Virtual Hard Drive From IDE to SATA

5.) Boot up your virtual machine and once logged in let it thrash around setting up your new devices. Once it’s done that, it’s gonna be rather keen to reboot. Let it.

Windows is keen to reboot

6.) After you’ve rebooted from the above step, hover your mouse cursor over the drive activity icon and you’ll see it’s running under a SATA controller; lower cpu usage and faster disk throughput is deservedly yours :)

VirtualBox running SATA controller

Note: VirtualBox will set SATA Controllers 0 through 4 to work in IDE compatibility mode by default, so you might want to switch to SATA Controller port 5, or anything higher than 4 to run in true SATA mode, only when I tried this (after first leaving it as port 0 and booting, admittedly) the machine couldn’t find the drive if I switched it to 5. Could be try that before rebooting after IDE -> SATA controller change, but I’m not in the mood to go through all that again.

If you want more info, try: Understanding and Configuring Virtual Box Hard Disks

Cheers!

Credits: Article based on and adapted from Matt Bottrell‘s IDE -> SATA changeover technique found here.

Update for Windows 7 IDE to SATA migration: If you want to switch a drive from a IDE controller to a SATA controller in Windows 7, then you need to perform the following steps:

  1. Make sure that both a SATA and your current controller are being presented to Windows. The SATA controller doesn’t need to have any disks attached to it. Once you have done so boot up Windows.
  2. Remove the IDE controller as described in the above URL [which is Step 2 in this article -r3dux]. Shutdown Windows from inside the guest.
  3. Move the image over to the SATA controller by removing it from your current controller and adding it to the SATA controller
  4. Boot up Windows again and it should boot into Windows, detect the changes and prompt you to restart when done as per the above instructions

Props to NetMusician.org for the Win 7 adaptation!