[KLUG Programming] Shared libraries & memory usage.

Robert G. Brown programming@kalamazoolinux.org
Tue, 15 Jul 2003 00:24:24 -0400


On 14 Jul 2003 22:24:49 -0400, Bruce Smith <bruce@armintl.com> wrote:

>> I think the spirit of bruces question was along the lines of something more 
>> formal than demand paging.
>
>Let me explain the reason behind my question, or what I'm really trying
>to determine.
I wouldn't dream of stopping you! :)

>The Devil Linux developers are debating what we should run direct from
>CD.  Right now we have the option of loading binaries and libraries into
>a RAM disk.  Or run them, direct from the CD.
OK, even I'm starting to understand where this is going, and I haven't 
read ahead... honest! 

>Command line binaries (vi, ls, ...) are a no-brainer.  They are not used
>often, so running them from CD saves a lot of memory usage (RAM disk)
>with almost no downside.
Sure. The only thing you might be worried about is that one of these will
force other stuff out (onto swap, or in a demand paging environment, some
stuff you might want would be trashed, and might have to be demand paged
back in). But OK, the exposure is probably real small.

>It's the daemons we are worried about.  We don't want the CD to cycle up
>during the normal day of being a firewall.  For example, if I'm running
>a NTP (or snort, or sshd, or dhcpd, or cipe, or syslog-ng, or ..... )
>daemon on my firewall, I don't want the CDROM to cycle up as part of the
>normal UNATTENDED operation.  That would slow things down and create a
>potential point of failure.
If memory were no object, compiling them all static is an idea. Maybe
for some of the smaller ones (ntpd may be a good candidate) that may 
be the solution. Someone might want to see what the impact of this is;
if it ups your memory requirements a lot, then it's not a complete 
solution.

The other problem is that it throws away economy of scale, since when 
things are compiled static, the libraries are no longer re-entrant.

>So we are wondering about the binary itself, and the shared libraries
>the daemon uses.  Will those be loaded into memory, and STAY IN MEMORY,
>when the daemon is initially started?  Or will it need to go back to CD?
I can't think of anything that will GUARANTEE that they will stay in 
memory. Things can always get swapped out if something needs real memory, 
and the swpper is pretty lazy about bringing stuff back in. I do suggest
that careful study of swapping, the ld command, and the dynamic loader
be conducted. There may be a facility or flag that makes the loader 
VERY aggressive about keeping things in physical memory. Looking at ld
carefully will give you a little more control over where and how symbols
get resolved (address computed, not read!!) and where some symbol table 
info resides. Then there's the swapper and memory manager, which someone
needs to examine (kernal source) to see how/when it throws stuff out, and
if it tries to keep re-entrant stuff in memory (especially stuff with 
high refcounts, which is how I would write it, but what do I know?).

The goal may be not so much to eliminate CDROM reads, but make them as
infrequent as possible. If that ain't good enough, maybe put only selected
libs in the ramdisk?

Have I generated enough ideas (and work) for one message? :)

						Regards,
						---> RGB <---