Memory saving ideas

Forum: DSL Tips and Tricks
Topic: Memory saving ideas
started by: alih

Posted by alih on May 23 2008,22:20

(typing this from a P266/32M machine)
Here's my experience with memory saving. Apart from the obvious turning off the background and the icons I came to think that bash eats too much memory. At a normal run of X, there are 3 bashes:
1) root's login shell;
2) user's login shell;
3) interpreter of startx.

I've dealed with them all to get bash-free memory. Here's how I did it.

1) I haven't found any better than append this to /etc/profile:
Code Sample

if [ x"/bin/bash" = x"$0" -a "$(whoami)" = "root" ]; then
    exec su - dsl

This gives up root login shell. It will probably be bad for single-user mode but I don't care.

2) Added this to /home/dsl/.bash_profile:
alias startx="exec startx"
When you quit X, bash will be respawned by init. It works exactly as if bash was alive all this time except returning to the home directory.

3) Edited /usr/X11R6/bin/startx: changed the interpreter to /bin/ash and a couple of constructs looking like
Code Sample
if ! X; then Y fi
Code Sample
if X; then :; else Y fi

Now when I start X torsmo shows 4.7M of taken memory (your mileage may vary since I have things like cardmgr). Together with kernel memory, it's about 8M of 32. So 32M isn't not that small after all :)

Hope that might help somebody.

Posted by curaga on May 24 2008,08:05
Nice :)

To further save on resources, use $UID="0" instead of $(whoami)="root", since starting an app is way heavier than reading an environment variable.

Also you might want to compile your own kernel for that machine, it's a good way to spare some ram too.

Edit: Actually, why even put that into /etc/profile? Root's bashrc already does that (in runlevel 5 and without exec though), so it's kinda just duplicating effort

Posted by WDef on May 29 2008,10:41
Code Sample if ! X; then Y fi
Code Sample if X; then :; else Y fi

Wondering why that should save memory?  X gets executed either way?

Posted by curaga on May 29 2008,14:36
That wasn't for saving memory, it was because ash doesn't understand the bash-y syntax if ! X..
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.