2009-01-29

How to save a few KB on the NSLU2.

With only 32MB RAM the slug is definitley a piece of hardware in which optimisation is a true investment.

Using all those services like NFS, Samba and so on, one really has to look that swapping will not happen or even worse, the slug runs out of swapable pages and kills tasks.

There are many sites out on the net, discussing many kinds of ways how to optimise all of the NSLU2 (main page for sure: nslu2-linux.org) - even the fat way. But I stumbled upon a very old kind of optimisation: The use of the shell.

Nowadays the bash (Bourne Again Shell) is so well known, with all its features ... but it needs RAM. Not so much, but more than something more pure, simpler but less comfortable: The sh (Shell - what else?). (external hint: UNIX shell differences and how to change your shell)

A short example using 'screen' for a rtorrent task:
---------------------------------------------------
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 2695 0.0 0.8 4228 252 pts/1 Ss 19:37 0:02 /bin/bash
user 2712 58.5 12.1 134912 3636 pts/1 RN+ 19:39 21:11 rtorrent

The same thing not using 'bash' but 'sh':
---------------------------------------------------
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 4038 0.2 5.5 3360 1660 pts/1 Ss 20:17 0:00 /bin/sh
user 4044 61.4 10.8 133812 3268 pts/1 RN+ 20:17 0:22 rtorrent

"But the 'sh' uses more on '%MEM' as it shows!" - Voices echo through the woods ...

... as far as I know 'VSZ' is the number one has to check - it show the real used memory including the virtual memory - so 'sh' uses less memory than 'bash' (external hint: PS -> RSS and VSZ Question (vague man page?)). Btw. '%CPU' was only as high at this moment because of a hashing. Normally rtorrent eats up only 2%-10%.

It is not much memory to save, but checking all scripts from crontab or maybe a HDD-sleeper-script and many more ... it accumulates.