[BusyBox] Re: busybox init memory problems

Erik Andersen andersen at lineo.com
Fri Jun 2 16:54:16 UTC 2000


On Fri Jun 02, 2000 at 10:54:24PM +1000, bug1 wrote:
> > 
> > I comment out the memmory check part and it continues ok.
> > 
> > busybox free shows only 7 free, /proc/meminfo shows the correct ammount.
> > 
> > I could be doing something wrong, ill download the cvs version of
> > busybox and have a go with a clean copy.
> > 
> > Glenn
> > 
> 
> The sysinfo struct has changed going to 2.[34], whats the best way to
> fix this ?
> 
> from 2.4.0-test1-ac7 /include/linux/kernel.h 
> struct sysinfo {
>         long uptime;                    /* Seconds since boot */
>         unsigned long loads[3];         /* 1, 5, and 15 minute load
> averages */
>         unsigned long totalram;         /* Total usable main memory size
> */
>         unsigned long freeram;          /* Available memory size */
>         unsigned long sharedram;        /* Amount of shared memory */
>         unsigned long bufferram;        /* Memory used by buffers */
>         unsigned long totalswap;        /* Total swap space size */
>         unsigned long freeswap;         /* swap space still available */
>         unsigned short procs;           /* Number of current processes
> */
>         unsigned long totalhigh;        /* Total high memory size */
>         unsigned long freehigh;         /* Available high memory size */
>         unsigned int mem_unit;          /* Memory unit size in bytes */
>         char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses
> this.. */};
> 
> from same file in 2.2.16-pre7
> struct sysinfo {
>         long uptime;                    /* Seconds since boot */
>         unsigned long loads[3];         /* 1, 5, and 15 minute load
> averages */
>         unsigned long totalram;         /* Total usable main memory size
> */
>         unsigned long freeram;          /* Available memory size */
>         unsigned long sharedram;        /* Amount of shared memory */
>         unsigned long bufferram;        /* Memory used by buffers */
>         unsigned long totalswap;        /* Total swap space size */
>         unsigned long freeswap;         /* swap space still available */
>         unsigned short procs;           /* Number of current processes
> */
>         char _f[22];                    /* Pads structure to 64 bytes */
> };

Ahh.  This explains it.  Thanks for tracking this down.  Hmm.  Looks like you
must have compiled it under 2.2.x and then run it under 2.4.x then, correct?
Could you track down the exact kernel rev where it changed?

In busybox init.c I have some code where I do

    #ifndef KERNEL_VERSION
    #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
    #endif

    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
    foo
    #endif

but that approach is probably the wrong thing to do (i.e. setting it at compile
time instead of at runtime), since it is clear that folks compile under some
kernels and run with others and busybox should cope.  It would be best here to
use get_kernel_revision() from utility.c

    int kernelVersion = 0;
    kernelVersion = get_kernel_revision();
    if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,4,0)) {
	foo();
    }

And then it looks like we need to compile in our own versions of sysinfo
structs so we can accomodate both kernels at runtime.  sigh.  All this
pain is to avoid using /proc from init.

 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--





More information about the busybox mailing list