SD card performance tuning on Chromebook
This guide assumes you're pushing your Chromebook to do interesting things, like running Ubuntu Linux and playing DotA 2 via Steam.
You want your game to load as fast as possible, right? Right.
File systems: What you need to know
When you format a storage device - like a hard disk or SD card - you choose a file system, or method of arranging data. Wikipedia has a good roundup of how they vary per OS.
Three things you need to know:
- A choice of file system can affect performance.
- A file system has characteristics like 'how rapidly will it wear out an SD card'.
- A given OS on a device will only understand certain file systems. For example, Windows has no idea how to read a device formatted with the Linux file system ext4.
On Windows, everything runs a Microsoft-defined format called VFAT. VFAT is the de facto format used by most devices like cameras.
On Linux, there are many more filesystems, and they're more actively developed. What's best for gaming on an SD card?
- The file system used by ChromeOS and Android is a Linux format called ext4. I'll show you how to format your SD card to match this.
- While your card is ext4, it won't be readable by Windows. Who cares right?
- A basic test shows ext4 and VFAT at default settings have roughly the same read performance.
- If we configure the readahead setting, I get a read change from 16.67 MB/s -> 17.69 MB/s or about 6% improvement. Theoretically this should reduce a load time of 120s to 113s.
1. Check VFAT speed
My SD card - a SanDisk Ultra 32GB - came out of the box formatted as VFAT. Let's get a baseline measurement of read speed before we mess with anything. We can use a tool called
hdparm to get an easy reading.
You'll remember from the previous post that on Chromebook, the SD card device is normally
/dev/sdb1, so let's run hdparm against it.
We measure more than one data point because we are good scientists:
$ sudo apt-get install -y hdparm $ sudo hdparm -t /dev/sdb1 /dev/sdb1: Timing buffered disk reads: 54 MB in 3.02 seconds = 16.89 MB/sec Timing buffered disk reads: 50 MB in 3.02 seconds = 16.56 MB/sec Timing buffered disk reads: 50 MB in 3.02 seconds = 16.54 MB/sec
It looks like my SD card with VFAT gives about 16.67 MB/s.
2. Reformat as ext4
Chromebook and Android use ext4 as their filesystem. Therefore ext4 is cool as shit, therefore that's what we're going to use. LOGIC.
You can check this by looking for
/dev/sda1 - your Chromebook's internal disk - in your
Put your safety goggles on. If you're going to reformat a device, do it with care - if you don't pay attention you could theoretically format your Chromebook internal disk, which I don't recommend.
Re-formatting your SD is going to remove all the data on there. Just so that's clear.
Be strong, you are an internet hero.
We will need tools
We're going to use an easy GUI tool called
gparted - first install it:
$ sudo apt-get install -y gparted
The tool now appears in your
Applications menu under
If you are fancy and have custom entries in the file
/etc/fstab, go ahead and comment them out now (and reboot for good measure). If you've never heard of that, don't worry.
- Plug in your SD if not already.
- We need to eject it in ChromeOS. The physical SD stays in the Chromebook! We're just removing the mount.
- Confirm it's not mounted:
$ mount | grep sdb1should return nothing.
- Fire up
Applications -> System -> GParted. You'll be prompted for your root password because this is serious adult business.
- Admire the colourful GUI. The different partitions on your internal disk are displayed - we're not really interested though.
- Look for the dropdown at top-right, so we can switch to look at the SD. As we can guess by now,
sdais your internal disk (DANGER, WILL ROBINSON) and
sdbis your SD card. Select
- You will see a couple of entries in the table below. Click on the partition labelled
/dev/sdb1. It should show roughly the right size for your SD card (29GB for my 32GB card).
- Finally use the menu to
Partition -> Format as... -> ext4, like this (in the screenshot my partition is already ext4, ignore that):
It won't take long, less than a minute.
When that's done, physically unplug your SD and re-insert it so that ChromeOS remounts. Look for it in ChromeOS explorer - you'll see it mounts with a new and exciting directory called
lost&found already there.
$ mount | grep sdb1:
/dev/sdb1 on /var/host/media/removable/SD Card type ext4 (rw,nosuid,nodev,noexec,relatime,dirsync,data=ordered)
Great - it's now ext4.
One last step: We need to set the SD card owner.
Since we formatted the card as
root, ordinary users won't have write permissions by default. A normal vfat card looks like this when plugged in:
$ ls -l /var/host/media/removable drwxr-xr-x 8 ubuntu ubuntu 32768 Jan 1 1970 SD Card
ubuntu is your username in Linux - you own the SD card directory. Compare this to your new ext4 SD card:
$ ls -l /var/host/media/removable drwxr-xr-x 3 root root 4096 Aug 23 16:51 SD Card
So let's fix it with a recursive
$ sudo chown ubuntu:ubuntu -R SD\ Card/
... where you replace
ubuntu with your Linux username.
3. Check ext4 speed
Let's see if ext4 is faster on our SD card.
$ sudo hdparm -t /dev/sdb1 Timing buffered disk reads: 52 MB in 3.11 seconds = 16.70 MB/sec Timing buffered disk reads: 50 MB in 3.00 seconds = 16.66 MB/sec Timing buffered disk reads: 50 MB in 3.01 seconds = 16.63 MB/sec
Nope, it's basically the same, 16.67 MB/s.
One easy thing to tune is the size of the read cache. This is how much memory is set aside by Linux to predict what's going to be read next from the card.
Read performance is a good optimisation target for most games, where we're loading game data much more than writing it.
By default this is set very low, and we can gain from adjusting it. What's the default setting? Let's check (I'm using
blockdev as it gives clean output):
$ sudo /sbin/blockdev --getra /dev/sdb1 256
So on my Chromebook 256kB is set aside for read caching.
Let's try some different settings and check their impact using
$ sudo /sbin/blockdev --setra 512 /dev/sdb1 $ sudo hdparm -t /dev/sdb1 Timing buffered disk reads: 54 MB in 3.10 seconds = 17.44 MB/sec ...more tests...
The max you can specify is
--setra 2048. I get these numbers:
256 16.66 MB/sec 512 17.44 MB/sec 768 17.70 MB/sec 1024 17.68 MB/sec 2048 17.69 MB/sec
So a 3x readahead increase to 768kB gives best results for my card.
This is a pretty simple test so nudging it a bit higher to 1024 seems a reasonable idea.
You are special
Your SD card will vary! Do this exercise yourself and find the right number for you.
Make it sticky
This setting is lost when you reboot. For running Steam on Chromebook, I use this script to help me do the mount and set the readahead at the same time - feel free to rip it off.
This is only scratching the surface of file system tuning - let me know if you have other successful tips for a blazing SD.