Saturday, June 23, 2012

Setting up an SSD with Linux

Recently I bought an SSD to replace the deceased hard drive. It can be a straight reinstall, however if you want to get the most out of your SSD and ensure a long life it can pay to take a few extra steps.

SSDs are not like mechanical media in any way, shape or form. They are a very advanced Solid State device with complex firmware which aids it in extending its life as long as possible. What eventually can kil an SSD is writing to it. Every cell can only survive a certain number of write operations. They have technology to account for this by spreading out write operations and other such things, but a finite number is still finite.

Here is what I did. It may not be the best way to go but it is what I chose after much reading on the subject.

Partitioning


SSDs as I mentioned earlier have cells. Discrete blocks of memory. Depending on the manufacture these can be different sizes. What we want is to make sure that the data that is written to the SSD is aligned to these cells. If it isn't, it will be writing to more cells than necessary, causing a slight slow down, and of course wearing extra cells prematurely.

Honestly I'm struggling to come up with a decent analogy so I'll just say we want what the computer is reading and writing to line up with the cells. The easiest way is to align partitions to the MiB. No, not men in Black. MibiBytes. This can be done when setting up partitions in GParted. It has the option to align to MiB. Use that when partitioning for your nice new OS.

You should choose either Ext4 or even btrfs as they both support TRIM which is a special SSD specific thing for extending its life. This is a good thing.

Tweaks


Now that you are seeing me using your nice shiny install, these are the next steps I took.

Making the OS more drive friendly

I edited /etc/fstab to change the entries for my ext4 partitions.  Here's a simplified version of what I changed.

/dev/sda1 / ext4 rw,errors=remount ro,noatime,nodiratime,discard 0 0 
 
Don't worry about what partition it is. It's just a tweak of what was in my /etc/fstab. The important thing there is "noatime,nodiratime,discard"
What noatime does is stop the OS from updating the date stamp on a file every time it is accessed, which should be alright for a home system. If you want to keep an eye on file accesses you might want to omit it and nodiratime which as you may have guessed is the same but for directories.
"discard" is a funny beast which all you really need to know is that it is meant to play nice with TRIM, assuming your SSD supports it.

Save now if you want.  I hope you were making your changes as su or root, otherwise you've just wated a couple of minutes.

While we have /etc/fstab open, we might as well make a couple more changes if you have a good chunk of RAM to play with.

Putting temporary files in RAM


If you want to cut down on writes, you can shift your temporary files to RAM. Of course that can fill up your RAM if your system generates a lot of them. You can do this by using tmpfs.
The following added to /dev/fstab or edited if you already have separate partitions for any of these will put your temporary files in RAM.

tmpfs   /tmp       tmpfs   defaults,noatime,mode=1777   0  0
tmpfs   /var/log   tmpfs   defaults,noatime,mode=0755   0  0
tmpfs   /var/tmp   tmpfs   defaults,noatime,mode=1777   0  0
tmpfs   /var/spool tmpfs   defaults,noatime,mode=1777   0  0
  
You may not want to put /var/log in RAM. I didn't because i like my logs to persist after reboot. Which ones you add is a personal choice.

Changing drive scheduling

"What's that?" Well, it's how the operating system decides what gets priority when accessing a drive, and what order the data gets accessed in.

By default linux uses CFQ. Which is Completely Fair Queuing. The thing about this is it is more suited to rotating media as one of its features is ordering data to take advantage of where the hard drive platters are at a given point in time to increase throughput. We don't need this.

"deadline" is much more suited to an SSD.

the following lines were added to "/etc/rc.local" above "exit 0" on my system to make access to the SSD more suitable whilst maintaining CFQ to spinning media.

echo deadline > /sys/block/sda/queue/scheduler
echo 1 > /sys/block/sda/queue/iosched/fifo_batch
 
After this, depending on the specifics of your system you may need to do this.

sudo chmod +x /etc/rc.local

to make the script executable.

Other things to do

There are other steps you can take like reducing the swappiness of the swap partition if you have one. I have one but didn't bother because as yet the computer hasn't touched /swap.
You can also move or just symlink your browser cache to /tmp, or even create your own tmpfs mountpoint for it if you want. There are other optimisations too but the ones I outlined are the ones I chose to do.

I take no responsibility for broken hardware, corrupted software or lost data. All I did was tell what I did and why, and all this was after using my own brain and doing my own research so don't go crying to me if you blindly entered things into a text editor and your neigbours dog kennel burst into flames because you didn't know what forces you were meddling with.

References

Here are a few of the places I looked to for information. It's not complete but it is good reading. What is in these pages may not agree with what I did. I'm not saying that I'm right. I just chose to do things my way so YMMV.

Crunchbang linux article on optimising for SSD

Debian User Forum topic on SSD booting

APCMag article on SSD optimization

Good luck!

Wednesday, February 22, 2012

Using the Battlefield 3 EOD effectively

Do you play Battlefield 3? Well then have you noticed the funny robot that Engineers unlock which nobody seems to use? That, my friends, is the EOD BOT.

The EOD BOT is a very underrated tool in BF3. The following is a little writeup on some of its features and limitations, and why you should give it another try.

*Attacking*
The EOD isn't just for repairs. It is also a destructive powerhouse! Due to its robust nature,small size and repair tool it can do many things that can't otherwise be done.

The EOD repair tool is also a weapon, not unlike the Engineer torch. It can be used to destroy vehicles, arm / disarm MCOMs and burn players.
When attacking a vehicle it can actually be driven underneath. most easily by the front or rear. Once there it is very hard for the enemy to attack it, so you can continue on your merry way, burning their tankto oblivion. Be mindful of the enemy making a hasty retreat though, as when the tank is empty the EOD starts to repair, usually leading to the enemy hopping back into their freshly repaired tank and dispatching your poor 'bot. Alternately they can also still shoot you. It's just a bit harder.

The repair tool can burn infantry. Glancing damage with the fire from the torch, or an instant kill from the tip of the torch. It's a bit tricky to steer so plan ahead for that attack.
The repair tool can also be used to set off some explosive items in the map, causing incidental damage to a nearby enemy. Don't worry too much about damaging it. It's really very tough!

Because the EOD is a vehicle, it can perform "Roadkill" kills. The movement speed is roughly running pace on flat ground which can be enough if the enemy is stationary. If you like, extra speed can be picked up by going down hill.

It also has the ability to push players / smaller objects around. There are many possibilities there, like pushing a sniper off a ledge or infantry out in front of a tank. Use your imagination! Your EOD is there to help you WIN!

*Moving around*
The EOD BOT deters people because of its quirky controls. Stick with it, and read along for a better understanding.
As mentioned it moves at roughly sprint speed. Faster downhill and slower uphill.
Because it is small, you have to bemindful of obstacles. It can get caught up on fallen trees, in craters, on kerbs and between rocks. It also gets stuck on the white tiled area near the hole in the ground going into the subway tunnel in Metro. That last one is a bug, I'm sure so be careful not to try crossing that with your robot friend.

With a good runoff, the EOD can climb stairs. It can also go down stairs. Just stay off the throttle and try to keep it pointing downhill.
Gutters can be a problem. Try to hit them at full speed at an angle.

Steering can be difficult at first. just try to think of it as a really light, tiny tank. If you try to steer while accelerating froma stop it can start spinning, so be careful of takeoffs.
Getting it going after an impact can also be a bit hard. It tends to spin round a lot and not really go anywhere. Its behaviour is much like the post-sudden-stop behaviour of other vehicles. Either wait a couple of seconds, or go easy accelerating and try not to steer.

the camera / torch direction control can be difficult as there is no easy way to tell which direction the camera is facing in relation to the bot. So only move it when you need to.

*Features*
This is a brief look at what makes the EOD unique which hasn't already been covered.

The EOD is very tough and it takes direct fire to destroy it. It is possible for the EOD to survive repeated glancing attacks from a tank, which mostly just sends it flying every time. It also recovers very quickly from damage and doesn't seem to have a minimum threshold between minimum self repair and destruction, so if it hasn't been destroyed, you're good to go again in a few seconds.

The EOD is a vessel for your players soul. like many player controlled things, it leaves your actual player a zombie, and vulnerable. Be careful of where you decide to park to use your EOD, as anyone can walk up and kill you. You can also push your lifeless body around with the 'bot. If you are prone, the 'bot will become ensnared and you will be able to lead your living corpse around prone crawling. Your player will still be controlling the EOD even when you are falling.
If you drive your EOD through water, you will be abruptly disconnected. I believe this is the same mechanic at work as being ejected from a vehicle when the water is too deep.

It doesn't take any fall damage. Driving it off Damavand Peak helipad a few times proved this. The HMMWV on the other hand does take fall damage. The gunner in the HMMWV also did not take fall damage well. Honestly I had far too much fun driving it off the peak. I have also played through a few rush maps end to end as an attacker using nothing but the EOD.

The EOD can also do line of sight spotting. Not as useful as a MAV perhaps, but at teh same time people don't tend to notice the EOD. Happy Hunting!

The HUD visible while using the EOD miscalculates the objective distances. Possibly based on the position of the Engineer controlling it. The headings are still correct.

The EOD can pick up enemy mines just like a real live Engineer. Go ahead and give it a try.

*Reactions to the EOD BOT*

People react strangely to the EOD. Use this to your advantage. One of the following will happen:

  • You will be ignored. Go ahead and kill some enemies, burn some tanks and take those MCOMs!

  • You will be the life of the party! Enemies come out in the open, trying to shoot the wildly weaving, flamethrower wielding, tough as nails robot. In the mantime your friends should dispatch them summarily.

  • You will be feared. The confused and scared enemy will run backwards, grappling with their weapons and firing wildly all over the place as the robotic menace steadily advances on them.

I hope you enjoyed my little writeup on a tool which I believe should be used far more in Battlefield 3.