Oct 132013
 

I discovered this cool feature of Linux quite by accident. zRAM is a block device (i.e. a “disk”) where the contents are compressed and stored in memory, which makes it sound rather mundane and hardly very interesting. However in use, it does appear to be quite nifty; sufficiently so that Google are enabling it for Chrome OS. So why?

The way that it is usually configured is as a swap space … so in effect, zRAM is used to compress normal memory, trading processor utilisation for more memory. What should happen is that instead of hitting the performance brick wall of suddenly paging to disk when you hit the memory limits of your machine, the zRAM is used instead eating a bit of processor time but with any luck keeping everything within memory rather than going to disk. It should have no effect during normal operation, but during temporary surges of memory utilisation, it should allow things to proceed at more or less normal performance.

That’s the theory anyway; but if it were not the case would Google be enabling it by default?

Of course in addition to using it as a swap device, there are other possible uses for zRAM devices :-

  1. As an L2ARC cache device for those using ZFS.
  2. To use as a block device for very hot disk spots in examples such as Exim’s retry database – which can be safely discarded on reboot.
  3. Or any other cache whose contents can be safely discarded at any point.

The last point is worth remembering. Because zRAM devices are contained within main memory, their contents are discarded when the power goes away.

Configuration

To use zRAM, we need to load the zRAM module, and choose how many devices to make at the same time. Some people believe that it makes sense to create as many devices as you have cores, as that gives each core (or thread) a device to spend it’s time compressing. To do this, we add the following to the /etc/rc.local file (assuming a Debian system) :-

/sbin/modprobe zram zram_num_devices=$(cat /proc/cpuinfo | grep processor | wc -l)

By default the zRAM will allocate 25% of the main memory to all of the zRAM devices; personally I think that is reasonable enough. However it seems that as soon as you set the number of devices, the size defaults to zero … so we have to set the size of the device as we configure it. Once created, you will have to decide how to use the devices. In my case, I wanted to use half of the devices for swap and half for L2ARC, which I did by adding the following to /etc/rc.local :-

size=$(( ($(cat /proc/meminfo | awk '/^MemTotal/ {print $2}')*1024) / (4 * $(cat /proc/cpuinfo| grep "^processor" | wc -l)) ))
#       Complex way of determining the size of each zRAM device
for dev in /dev/zram*
do
  base=$(basename $dev)
  echo $size > /sys/block/${base}/disksize
  odd=$(( $(echo $dev | sed -e "s/^.*zram//") % 2 ))
  if [ $odd = 0 ]
  then
    /sbin/mkswap $dev
    /sbin/swapon -p 32767 $dev
  else
    zpool remove pool0 $dev > /dev/null 2>&1
    zpool add pool0 cache $dev
  fi
done

This is a rather complex way of doing it, and doesn’t contain much in the way of error checking, but it does work.

Oct 122013
 

Sometimes people get amused when they see my blog’s tag line (“Grumbles from the Growlery”), because they get the word “growlery” confused with the word “growler”. Just to show this isn’t that sort of blog, I’m going to define it.

It’s a room for growling in; nothing more and nothing less. See “Bleak House” by Charles Dickins which has: “This, you must know, is the growlery. When I am out of humour, I come and growl here.”.

Other definitions come from :-

  1. The Collins dictionary: “a place to retreat to, alone, when ill-humoured”.
  2. The Phrontistery list of unusual words (you have to scroll down): “a retreat for times of ill humour”.

And you can probably find many other definitions yourself.

The Growlery

The Growlery

 

Oct 122013
 

If we are getting to the stage that autonomous vehicles can drive themselves – probably safer than most human drivers – do we need to think about whether a human driver is necessary at all? Although there are people who enjoy driving, not everyone does and even those who do may not enjoy it all the time.

Why bother with a driving license if you can get a robot driver to do all your driving for you?

Oct 042013
 

Ralph Miliband, Ed Miliband, and the Daily Mail. No prizes for guessing who the villain is; even blue-rinsed Conservative party card carrying reactionaries are beginning to think that the Daily Mail is on a sticky wicket with their latest story. But that part can all be best summed up with :-

The Daily Mail have somehow decided that Ralph was an evil person, hated Britain, and so Ed Miliband is an inappropriate person to lead the country. Which is bizarre on several levels, but rather than concentrating on whether Ed is suitable or not, or looking into the Daily Mail’s deranged reasoning, let’s have a look at poor old Ralph.

After all, Ralph is dead so he is hardly in a position to defend himself, so someone should do it for him. The Mail picked up on something he wrote shortly after arriving in Britain (after encountering anti-semitism: “The Englishman is a rabid nationalist. They are perhaps the most nationalist people in the world …”. Whilst it may be a little extreme, it is understandable coming from a Jewish refugee arriving in London in the middle of war fever, and not being aware of the Battle of Cable Street.

And of course Ralph was a prominent Marxist which is the sort of thing that will cause any Daily Mail editor to start frothing at the mouth. As a Marxist, Ralph was probably not too keen on the monarchy, and the British establishment. But hating the way that Britain is governed is not the same as hating Britain.

What the Daily Mail would rather have you overlook is that Ralph fought for this country during the war. And at the end of the war, he chose to stay in this country rather than return to Belgium, or take up any number of opportunities in the USA. Sure he was a Marxist and if he had managed a worker’s revolution and liquidated the whole of the Daily Mail, I would be the first to call him evil.

Let’s be honest, if we have to pick one of the Daily Mail or Ralph to label as “evil”, then the only answer is the Daily Mail.