Thursday, March 1, 2007

Overcommitted to the old kernel

If you want to make sure your Linux kernel does not over commit memory you can run this:
 sysctl -w vm.overcommit_memory=2
and edit /etc/sysctl.conf to make the change survive a reboot. After all, you think, how rude would it be if some greedy process asks for RAM killing your well-behaved process in the confusion. How rude indeed.

Now let's just say you're in some sleep-addled state and you've done this not realizing that the server you are logged into is running Linux 2.4 where this setting is undefined. Let's also say that this is a production server with over 250 people logged in. For effect, we should add that it's after-hours and the server is over 1000 miles away.

Now that the kernel refuses to allocate any RAM at all, what do you do? You can't run 'sysctl' again and even if you could run a friendly 'shutdown -r now', the machine probably wouldn't get very far. You feel crippled–'vi' is right out and even your 'cat' needs RAM. Luckily your trusty shell is still open and already has all the RAM it needs. This will save you:
 echo 0 > /proc/sys/vm/overcommit_memory
Now go home before you do anything else stupid.

0 comments: