[BusyBox] Re: busybox init memory problems

Erik Andersen andersen at lineo.com
Sun Jun 4 07:49:09 UTC 2000


On Fri Jun 02, 2000 at 10:54:16AM -0600, Erik Andersen wrote:
> > 
> > The sysinfo struct has changed going to 2.[34], whats the best way to
> > fix this ?
> > 

FYI, I just spent some time looking into this problem, and I just sent the
attached email to the linux-kernel mailing list.  The problem here is not
struct sysinfo.  The problem is that the various memory values contained in
struct sysinfo used to return containing memory values in bytes, and now they
return using units of PAGE_SIZE.  I just whipped up a patch to reinstate the
traditional behavior (see attached)...

While checking out 2.4.0-test, I also noticed that /proc/mounts seems to act
strangely:

    [andersen at dillweed busybox]$ cat /proc/mounts
    none / shm rw 0 0
    none pipe: pipefs rw 0 0
    none / proc rw 0 0
    /dev/root / reiserfs rw 0 0
    proc /proc proc rw 0 0
    devpts /dev/pts devpts rw 0 0
    /dev/hda1 /boot reiserfs rw 0 0

I didn't have any of the "none" filesystems mounted -- something is messed with
the nodev filesystems it looks like.  This makes BusyBox df behave badly.
Also, looks like nfsmount.c is in need of some work for 2.4.x...

 -Erik

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


From: Erik Andersen <andersen at xmission.com>
To: linux-kernel <linux-kernel at vger.rutgers.edu>
Subject: [PATCH] fix for sysinfo(2) in 2.4.0-test1
Date: Sun, 4 Jun 2000 01:35:51 -0600
User-Agent: Mutt/1.0.1i
X-Operating-System: Linux 2.4.0-test1-ac7, Intel PII-Celeron, 487.509756 MHz
X-No-Junk-Mail: I do not want to get *any* junk mail.

I have a version of free I wrote for BusyBox that uses sysinfo (rather then
/proc) to get its information.  Under 2.2.x it reports normal stuff, i.e.
    [andersen at dillweed busybox]$ ./free
		  total         used         free       shared      buffers
      Mem:       127800       124268         3532        16956         7544
     Swap:       128516        13584       114932
    Total:       256316       137852       118464

while under 2.2.0-test1-ac7 it reports wierd numbers (~ #/4096)
    [andersen at dillweed busybox]$ ./free
		  total         used         free       shared      buffers
      Mem:           30           11           19            0            1
     Swap:           31            0           31
    Total:           61           11           50

After investigating the problem, it turns out that somewhere during 2.3.x the
values for memory stored in struct sysinfo changed from being stored as bytes
to being units of PAGE_SIZE, but kernel/info.c was never updated to reflect
this change in definition.  

Breaking free isn't that big of a deal, but I also use sysinfo in init to check
that the box has enough ram from within the init process (and no, mounting
/proc from within init and reading /proc/meminfo is not a good solution.
BusyBox is often used in embedded systems where /proc is not compiled in).

The following patch reinstates the traditional sysinfo(2) interface by
returning bytes (not units of PAGE_SIZE) for memory values.  

An additional patch suggestion (not included here) would be to eliminate the
supurfluous "mem_unit" variable from struct_sysinfo in include/linux/kernel.h
and arch/*/mm/init.c.

 -Erik

--
Erik B. Andersen   Web:    http://www.xmission.com/~andersen/ 
                   email:  andersee at debian.org
--This message was written using 73% post-consumer electrons--



--- linux/kernel/info.c.orig	Mon Aug 23 12:15:53 1999
+++ linux/kernel/info.c	Sun Jun  4 01:13:11 2000
@@ -2,6 +2,8 @@
  * linux/kernel/info.c
  *
  * Copyright (C) 1992 Darren Senn
+ * Fixed to once again return bytes instead of page counts,
+ * June 2000, by Erik Andersen <andersee at debian.org>
  */
 
 /* This implements the sysinfo() system call */
@@ -10,7 +12,6 @@
 #include <linux/unistd.h>
 #include <linux/swap.h>
 #include <linux/smp_lock.h>
-
 #include <asm/uaccess.h>
 
 asmlinkage long sys_sysinfo(struct sysinfo *info)
@@ -31,6 +32,17 @@
 
 	si_meminfo(&val);
 	si_swapinfo(&val);
+	
+	/* These are in units of PAGE_SIZE, but this interface
+	 * has always returned bytes.  Make it return bytes */
+	val.totalram*=PAGE_SIZE;
+	val.freeram*=PAGE_SIZE;
+	val.sharedram*=PAGE_SIZE;
+	val.bufferram*=PAGE_SIZE;
+	val.totalswap*=PAGE_SIZE;
+	val.freeswap*=PAGE_SIZE;
+	val.totalhigh*=PAGE_SIZE;
+	val.freehigh*=PAGE_SIZE;
 
 	if (copy_to_user(info, &val, sizeof(struct sysinfo)))
 		return -EFAULT;






More information about the busybox mailing list