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.

Friday, August 20, 2010

Open Source Immune Efficiency. A small bug can kill.

I have been using open source software for well over a decade and have noticed an alarming trend.
Many fine software packages which had multiple collaborators and countless hours work have been killed by a show stopping bug.

The most recent chich has come to my attention is Rhythmbox.

Rhythmbox is an excellent audio player program for linux which allows music to be put in a collection and arranged using playlists, sorted and various other nice features. I liked the way it worked and was happy.

In the last six months or so I have encountered a show stopping bug. It is the sort that can bring about the fall of a program. The sort of bug I am referring to is a finger pointing bug where nobody will accept responsibility. People say "It isn't my problem, blame package X". this continues until someone says "It's an upstream issue" and the bug never gets fixed in spite of multiple reports.

I can not use Rhythmbox anymore because there is a bug which causes a crash with certain container formats. Rhythmbox, dbus and GStreamer are all involved, but the buck seems to have been passed to saying it is a GStreamer upstream issue.
Go and have a hunt. this issue dates back more than a year. many people have dealt with it the same way I have. Grudgingly using another alternative.
if people are offered a choice between a program which should do what they want but breaks, or a suboptimal program which works, they will choose the latter.
if you need to move house, would you choose a moving van with a seized motor or a fully functional station wagon? Exactly.

Sure, in this case Rhythmbox breaks because GStreamer causes a segfault. Call me old fashioned, but we used to use input sanitization. At worst Rhythmbox should acknowledge the crash, and move on to the next file.
It's not even an error during playback. Just population of the collection.

One bug is killing this mighty beast. Much like many other packages which I can't remember specifics about anymore besides leaving a bad feeling when I try to recall them.

If you haven't tried Rhythmbox I still urge you to give it a try. You may not have any files which inflame this bug. If you liked the pre KDE4 Amarok, you'll probably like this.

That's my rant for today. Agree or disagree, that's what i think.

Thursday, May 6, 2010

The karmic experience: Was it just a Lucid dream?

Ubuntu Lucid Lynx is now out of beta and in the wild for the general public as a finished product.

I have personally been waiting for this release since about November of 2009.

The predecessor for lucid was somewhat of an unloved child. 9.10 Karmic Koala had many new features. many of these features were not complete or did not function correctly. Karmic was not ready for release when the deadline elapsed. As a result it's entire lifespan was a torrent of updates, desperately attempting to fix the situation.

Over the last couple of days I have updated both the dual core 64 bit AMD based desktop and my 32 bit netbook to lucid to see how well it's updater works.

The update is relatively painless and almost everything still works perfectly. the updater does ask questions which the novice would find utterly daunting such as which device and / or partition to install the bootloader and whether to remove unsupported programs.

On the desktop it grumbles a little about USB on startup but everything seems fully functional which I would consider a win.

On the netbook there are a few issues such as no splash screen and a slow-ish boot. But once again everything is functional.

I would recommend doing a clean install if possible to avoid upgrade-itis.

Is it worth upgrading from Karmic?

Yes. The positives far outweigh the negatives. SMB file sharing seems to be working properly again. USB drives haven't been glitching out and changing permissions at random.

The context menus in nautilus have been expanded and integration with Ubuntu One, an online storage / sharing system has been improved.
I could go on, but I feel the best way to explain it is that Lucid is to Karmic as windows 7 is to Vista. Not a total revamp but a lot of subtle repairs and upgrades which go towards making a far less frustrating user experience.

The only complaint I have is that the window buttons in Gnome have been moved to the left. Thanks for that Shuttleworth.
It is possible to move them back with a file edit though.

i was so close to moving back to another non-Ubuntu based distribution because of Karmic. I was even trying other distributions and operating systems. However Lucid has stopped me. To be honest I only upgraded out of morbid curiosity, expecting a tragic unworkable mess. After using it for a while I was pleasantly surprised as it would seem Ubuntu's fall into decay and ruin has been halted.

I would recommend lucid to existing users and to people who are curious about Linux.
To the curious, there are live CDs available which let you try it out without affecting your system. The downlaoded image can also be put on a USB drive or SD card and optionally set up with some persistent storage so other programs can be installed and your files can be kept. great for system recovery or just taking your system with you.

My conclusion: Lucid is good. Try it.