Linux Memory Usage

I recently became concerned about the performance of a particular application (cmatrix on the 1080p screen – it looks beautiful but it’s quite choppy) so I began some investigating and turned up some surprising statistics.

Uptime: 12:53; of that time, Chrome has been running for most of it and we all know web browsers are notorious for leaking all over your RAM.  Chrome is better than firefox but still pretty leaky.  On Windows XP, it was not uncommon for chrome to be using more than half a GB of RAM.

Now, the surprising thing is, Linux has managed to gobble up all my RAM.  But has it?  If you observe carefully, I’ll explain to you why Linux has -not- gobbled up all of my RAM (despite what ‘top’ tells me) whereas Windows, had it been given the same constraints, would’ve.

The way Linux handles memory usage differs extraordinarily to Windows.  If something leaks in Windows, that RAM is unrecoverable, especially after the application has quit.  However, in Linux, if something leaks, once the application quits, all the memory Linux allocated it is returned to Linux in the form of ‘cached’ memory.  In other words, the memory doesn’t get -deleted-, so if the application comes back and wants it again it’s entitled to the same memory (efficiency++) but if another application wants to use the memory that application -was- using, Linux isn’t gonna say no.  In other words, the memory is still ‘in use’ but it’s also still ‘available’ to new applications who request it.

This presents a difficult situation when you’re measuring RAM usage – do you count the memory as ‘in use’ or as ‘available’?  Well, ‘top’ (and some other tools) see it as ‘in use’, and ‘free’ will also tell you (on the Memory line) that it’s ‘in use’.  However, ‘free’ also has a “-/+ buffers/cache” line which basically takes the buffered memory into account, giving you a fuller picture of how much RAM is available to new applications.  So when you’re measuring RAM, you should use -that- line in your statistics.  Not the above raw figure which counts unreferenced (‘dead’) memory as ‘used’.

Windows XP, on the other hand (but don’t quote me about Vista or 7, I’m unfamiliar with the new kernel but I’m pretty sure it’s the same story in terms of memory allocation), trusts applications to free memory.  If they don’t, Windows will never reclaim the lost memory (not until a reboot anyway).  I’m unsure exactly how the kernel works (only Microsoft know) for this behaviour to be apparent, but I’m not the only one to have made that observation, and I can assure you Windows XP, if left to its own devices, will start swapping out pages like there’s no tomorrow after a couple of days (depending how much RAM you have).

Suffice it to say, if you run WinXP, you’re gonna get slowdown after a while, if you run Linux you can (in theory) continue running it forever.  Note that kernel leaks (which are rare but do happen) and certain other situations (eg video driver bugs) can cause a required reboot due to memory loss, but the situation is far rarer in the Linux world than in Windows.

It is owing mainly to this reason (and the kernel’s greater stability, owing to a better design and fewer crash-inducing bugs) that Linux servers are able to run for…

chris@w1zard:~$ uptime
20:54:58 up 125 days,  4:24,  2 users,  load average: 0.00, 0.00, 0.00

Yup, w1zard (my server) has now been running for 125 days, 4 hours and 24 minutes without a reboot.  The load average statistics being 0.00 is due to the quad core processor; the system doesn’t strain under the minute amount of traffic it’s required to handle (mail only at the moment, too).  I’m very proud.
Have fun hacking!

Ubuntu and HDMI audio

Ok, so I got the video part of the HDMI output working with a couple of deft mouseclicks and the help of my previous workings with nvidia control panel, but when it came to audio…

First off, I go internetting, ask the mighty Google how the heck it is to be done.  I happened upon a post detailing steps to get a GT240 to work, whereupon I hit snag after snag, eventually crippling my entire audio setup.

Eventually, I found that my saving grace was “alsa-utils reset”, but the internet did not tell me this – rather, my brother pointed it out (him being an audiophile and a closet ubuntu geek).  I managed to get my speakers back, and seeing as I wanted to watch a film and had spent a good few hours troubleshooting audio things I decided HDMI audio can wait until it works ‘out of the box’.  Especially considering, as I said earlier, it’s actually a downgrade in speaker quality.

That said, it appears my tweeters have blown (muddy, muffled sounds coming from the hifi at the moment; my brother diagnosed it as blown tweeters, but he didn’t properly examine the patient so I don’t think he’d want to be quoted on that).

Those poised to criticize Ubuntu for not supporting HDMI ought remember that it is an immature technology (HDMI, that is, not Ubuntu) and is steeped in DRM.  Aside from the ethical problems I have with DRM, it also creates lots of technical hassle for projects wishing to use technologies that rely on it.  Especially if the company responsible for the DRM is uncooperative or demands financial recompense for their support in making technology work with it.  The mind boggles at why consumers put up with this kind of treatment, but I guess conglomerates preclude us from having much choice.

Have fun hacking!

Open Letter to three Tewkesbury Candidates (Alistair Cameron, Laurence Robertson and Matthew Sidford)

Dear Tewkesbury Candidates (or at least, the ones who publish their email address),

I’m a constituent living in Tewkesbury, trying to decide who I should vote for on thursday.

I would like to know each of your opinions on the Digital Economy Act. I would like to know your more general opinion of Copyright vs Copyleft, and whether internet censorship is a justifiable enforcement of copyright law.

I would also like to know what operating systems you are each familiar with and to what extent you are familiar with each. After all, if you are passing legislation regarding digital media and the use/abuse thereof, I should hope you are at least aware of a significant range of operating systems, their distribution methods and their compatibility with Digital Rights Management.

The Internet, and legislation surrounding it, affects us all. I would like to be reassured that those who are creating this legislation understand the core principles of it. Concisely, what is the internet for?

Cybercrime and cyberterrorism are also immediate threats to the safety and welfare of United Kingdom residents. What safeguards are being taken to ensure users of the internet are protected against security crackers, malicious software, privacy invasion and internet-based attacks; do you feel the current legislation is sufficient? Does it protect without infringing on civil liberties?

Remote devices – such as smart phones, tablet PCs and laptops – often include Digital Rights Management software to prevent users from infringing copyright. Have you ever been unable to use any device in the way in which you want to due to this software? Do you think the software is justifiably restrictive?

There are many software platforms available on the market today, but the main three are NT (eg Microsoft Windows), BSD (eg Apple Mac OSX) and Linux (eg GNU/Linux). Which of these (or any other) do you use? Which of these (or any other) do you think represents the most accurate analogy for your political party, and why?

I look forward to hearing from you before the general election. I appreciate I may not receive my answers until after I have voted due to the busy nature of yourselves at this time.


Christopher Browne