source: branches/stable/mindi-busybox/docs/keep_data_small.txt @ 1770

Last change on this file since 1770 was 1770, checked in by Bruno Cornec, 13 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod? silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian? keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René? Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
1        Keeping data small
2
3When many applets are compiled into busybox, all rw data and
4bss for each applet are concatenated. Including those from libc,
5if static busybox is built. When busybox is started, _all_ this data
6is allocated, not just that one part for selected applet.
7
8What "allocated" exactly means, depends on arch.
9On NOMMU it's probably bites the most, actually using real
10RAM for rwdata and bss. On i386, bss is lazily allocated
11by COWed zero pages. Not sure about rwdata - also COW?
12
13In order to keep busybox NOMMU and small-mem systems friendly
14we should avoid large global data in our applets, and should
15minimize usage of libc functions which implicitly use
16such structures.
17
18Small experiment to measure "parasitic" bbox memory consumption:
19here we start 1000 "busybox sleep 10" in parallel.
20busybox binary is practically allyesconfig static one,
21built against uclibc. Run on x86-64 machine with 64-bit kernel:
22
23bash-3.2# nmeter '%t %c %m %p %[pn]'
2423:17:28 .......... 168M    0  147
2523:17:29 .......... 168M    0  147
2623:17:30 U......... 168M    1  147
2723:17:31 SU........ 181M  244  391
2823:17:32 SSSSUUU... 223M  757 1147
2923:17:33 UUU....... 223M    0 1147
3023:17:34 U......... 223M    1 1147
3123:17:35 .......... 223M    0 1147
3223:17:36 .......... 223M    0 1147
3323:17:37 S......... 223M    0 1147
3423:17:38 .......... 223M    1 1147
3523:17:39 .......... 223M    0 1147
3623:17:40 .......... 223M    0 1147
3723:17:41 .......... 210M    0  906
3823:17:42 .......... 168M    1  147
3923:17:43 .......... 168M    0  147
40
41This requires 55M of memory. Thus 1 trivial busybox applet
42takes 55k of memory on 64-bit x86 kernel.
43
44On 32-bit kernel we need ~26k per applet.
45
46Script:
47
48i=1000; while test $i != 0; do
49        echo -n .
50        busybox sleep 30 &
51        i=$((i - 1))
52done
53echo
54wait
55
56(Data from NOMMU arches are sought. Provide 'size busybox' output too)
57
58
59        Example 1
60
61One example how to reduce global data usage is in
62archival/libunarchive/decompress_unzip.c:
63
64/* This is somewhat complex-looking arrangement, but it allows
65 * to place decompressor state either in bss or in
66 * malloc'ed space simply by changing #defines below.
67 * Sizes on i386:
68 * text    data     bss     dec     hex
69 * 5256       0     108    5364    14f4 - bss
70 * 4915       0       0    4915    1333 - malloc
71 */
72#define STATE_IN_BSS 0
73#define STATE_IN_MALLOC 1
74
75(see the rest of the file to get the idea)
76
77This example completely eliminates globals in that module.
78Required memory is allocated in unpack_gz_stream() [its main module]
79and then passed down to all subroutines which need to access 'globals'
80as a parameter.
81
82
83        Example 2
84
85In case you don't want to pass this additional parameter everywhere,
86take a look at archival/gzip.c. Here all global data is replaced by
87single global pointer (ptr_to_globals) to allocated storage.
88
89In order to not duplicate ptr_to_globals in every applet, you can
90reuse single common one. It is defined in libbb/messages.c
91as struct globals *const ptr_to_globals, but the struct globals is
92NOT defined in libbb.h. You first define your own struct:
93
94struct globals { int a; char buf[1000]; };
95
96and then declare that ptr_to_globals is a pointer to it:
97
98#define G (*ptr_to_globals)
99
100ptr_to_globals is declared as constant pointer.
101This helps gcc understand that it won't change, resulting in noticeably
102smaller code. In order to assign it, use PTR_TO_GLOBALS macro:
103
104    PTR_TO_GLOBALS = xzalloc(sizeof(G));
105
106Typically it is done in <applet>_main().
107
108Now you can reference "globals" by G.a, G.buf and so on, in any function.
109
110
111        bb_common_bufsiz1
112
113There is one big common buffer in bss - bb_common_bufsiz1. It is a much
114earlier mechanism to reduce bss usage. Each applet can use it for
115its needs. Library functions are prohibited from using it.
116
117'G.' trick can be done using bb_common_bufsiz1 instead of malloced buffer:
118
119#define G (*(struct globals*)&bb_common_bufsiz1)
120
121Be careful, though, and use it only if globals fit into bb_common_bufsiz1.
122Since bb_common_bufsiz1 is BUFSIZ + 1 bytes long and BUFSIZ can change
123from one libc to another, you have to add compile-time check for it:
124
125if (sizeof(struct globals) > sizeof(bb_common_bufsiz1))
126    BUG_<applet>_globals_too_big();
127
128
129        Drawbacks
130
131You have to initialize it by hand. xzalloc() can be helpful in clearing
132allocated storage to 0, but anything more must be done by hand.
133
134All global variables are prefixed by 'G.' now. If this makes code
135less readable, use #defines:
136
137#define dev_fd (G.dev_fd)
138#define sector (G.sector)
139
140
141        Word of caution
142
143If applet doesn't use much of global data, converting it to use
144one of above methods is not worth the resulting code obfuscation.
145If you have less than ~300 bytes of global data - don't bother.
146
147
148        gcc's data alignment problem
149
150The following attribute added in vi.c:
151
152static int tabstop;
153static struct termios term_orig __attribute__ ((aligned (4)));
154static struct termios term_vi __attribute__ ((aligned (4)));
155
156reduces bss size by 32 bytes, because gcc sometimes aligns structures to
157ridiculously large values. asm output diff for above example:
158
159 tabstop:
160        .zero   4
161        .section        .bss.term_orig,"aw",@nobits
162-       .align 32
163+       .align 4
164        .type   term_orig, @object
165        .size   term_orig, 60
166 term_orig:
167        .zero   60
168        .section        .bss.term_vi,"aw",@nobits
169-       .align 32
170+       .align 4
171        .type   term_vi, @object
172        .size   term_vi, 60
173
174gcc doesn't seem to have options for altering this behaviour.
175
176gcc 3.4.3 and 4.1.1 tested:
177char c = 1;
178// gcc aligns to 32 bytes if sizeof(struct) >= 32
179struct {
180    int a,b,c,d;
181    int i1,i2,i3;
182} s28 = { 1 };    // struct will be aligned to 4 bytes
183struct {
184    int a,b,c,d;
185    int i1,i2,i3,i4;
186} s32 = { 1 };    // struct will be aligned to 32 bytes
187// same for arrays
188char vc31[31] = { 1 }; // unaligned
189char vc32[32] = { 1 }; // aligned to 32 bytes
190
191-fpack-struct=1 reduces alignment of s28 to 1 (but probably
192will break layout of many libc structs) but s32 and vc32
193are still aligned to 32 bytes.
194
195I will try to cook up a patch to add a gcc option for disabling it.
196Meanwhile, this is where it can be disabled in gcc source:
197
198gcc/config/i386/i386.c
199int
200ix86_data_alignment (tree type, int align)
201{
202#if 0
203  if (AGGREGATE_TYPE_P (type)
204       && TYPE_SIZE (type)
205       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
206       && (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 256
207           || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 256)
208    return 256;
209#endif
210
211Result (non-static busybox built against glibc):
212
213# size /usr/srcdevel/bbox/fix/busybox.t0/busybox busybox
214   text    data     bss     dec     hex filename
215 634416    2736   23856  661008   a1610 busybox
216 632580    2672   22944  658196   a0b14 busybox_noalign
Note: See TracBrowser for help on using the repository browser.