[BusyBox] choice for reserving buffers

Larry Doolittle ldoolitt at recycle.lbl.gov
Fri Apr 20 17:14:23 UTC 2001


I trust most of you remember the long, drawn out haggling
over placement of buffers on BSS, stack, or heap.  Newcomers
can check the archives, most (all?) of the discussion took
place in two threads:

"#define -> static const int", starting with Mark Whitley's
post of 5 Jan 2001

"choice for reserving buffers", starting with my (Larry Doolittle's)
post of 24 Jan 2001

The current behavior of BusyBox is selected with the
BB_FEATURE_BUFFERS_GO_ON_STACK definition in Config.h,
which in turn controls the definition of RESERVE_BB_BUFFER
and RESERVE_BB_UBUFFER.  These preprocessor macros are used
nine times total, in the cp_mv, rpmunpack, syslogd, tftp,
and tr applets.

This situation is OK, but really does not address Vladimir's
reasonable opinion that these items belong in BSS, at least
for computers with MMU's that can efficiently instantiate BSS
dynamically at runtime (like normal Linux, but not uCLinux).

At one point (25 Jan) in that discussion, I said 
> It would be nice to add BSS as an option to my list of
> compile-time choices, but it can't happen cleanly,
> due to the structure of c.

Nobody called me on this statement, which was simply a case of
my not thinking through the problem clearly enough.  A quick
experiment this morning shows me that:
    char buffer[len];           /* goes on stack */
    static char buffer[len];    /* goes in BSS */
    char *buffer=xmalloc(len);  /* allocates from heap */

The attached patch adds a BB_FEATURE_BUFFERS_GO_IN_BSS
configuration option, which I'm sure Vladimir will want
to turn on for his builds.   ;-)

Results of running size on i386 BusyBox using gcc-2.7.2.3,
current CVS copy, starting with the base configuration but
with rpmunpack, tftp, and tr turned on.
   text    data     bss     dec     hex filename
 128391   11320   15376  155087   25dcf busybox-heap
 128419   11320   15376  155115   25deb busybox-stack
 128343   11320   50456  190119   2e6a7 busybox-bss

Enjoy!

       - Larry

diff -urN cvs/busybox/Config.h busybox-trial/Config.h
--- cvs/busybox/Config.h	Thu Apr 19 12:05:23 2001
+++ busybox-trial/Config.h	Fri Apr 20 09:57:36 2001
@@ -144,6 +144,11 @@
 // them put on the stack.  For some very small machines with limited stack
 // space, this can be deadly.  For most folks, this works just fine...
 //#define BB_FEATURE_BUFFERS_GO_ON_STACK
+// The third alternative for buffer allocation is to use BSS.  This works
+// beautifully for computers with a real MMU (and OS support), but wastes
+// runtime RAM for uCLinux.  This behavior was the only one available for
+// BusyBox versions 0.48 and earlier.
+//#define BB_FEATURE_BUFFERS_GO_IN_BSS
 //
 // Turn this on to use Erik's very cool devps, and devmtab kernel drivers,
 // thereby eliminating the need for the /proc filesystem and thereby saving
diff -urN cvs/busybox/busybox.h busybox-trial/busybox.h
--- cvs/busybox/busybox.h	Thu Apr 12 13:32:22 2001
+++ busybox-trial/busybox.h	Fri Apr 20 09:53:13 2001
@@ -72,8 +72,13 @@
 #define RESERVE_BB_BUFFER(buffer,len)           char buffer[len]
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
 #else
+#ifdef BB_FEATURE_BUFFERS_GO_IN_BSS
+#define RESERVE_BB_BUFFER(buffer,len)  static          char buffer[len]
+#define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len]
+#else
 #define RESERVE_BB_BUFFER(buffer,len)           char *buffer=xmalloc(len)
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
+#endif
 #endif
 






More information about the busybox mailing list