summaryrefslogtreecommitdiff
path: root/docs/keep_data_small.txt
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-20 11:08:39 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-20 11:08:39 +0000
commite84aeb5bcb1a8398fce53aad9c0072ad73a8b5c9 (patch)
tree7681cc079c04adbd75e40183f3b65059413634a9 /docs/keep_data_small.txt
parent88a2aa98e06cf6b0aa00a3cf88376a1d3497fb2c (diff)
downloadbusybox-w32-e84aeb5bcb1a8398fce53aad9c0072ad73a8b5c9.tar.gz
busybox-w32-e84aeb5bcb1a8398fce53aad9c0072ad73a8b5c9.tar.bz2
busybox-w32-e84aeb5bcb1a8398fce53aad9c0072ad73a8b5c9.zip
update docs
Diffstat (limited to 'docs/keep_data_small.txt')
-rw-r--r--docs/keep_data_small.txt82
1 files changed, 51 insertions, 31 deletions
diff --git a/docs/keep_data_small.txt b/docs/keep_data_small.txt
index fcd8df4a9..72de2d1ef 100644
--- a/docs/keep_data_small.txt
+++ b/docs/keep_data_small.txt
@@ -2,44 +2,48 @@
2 2
3When many applets are compiled into busybox, all rw data and 3When many applets are compiled into busybox, all rw data and
4bss for each applet are concatenated. Including those from libc, 4bss for each applet are concatenated. Including those from libc,
5if static bbox is built. When bbox is started, _all_ this data 5if static busybox is built. When busybox is started, _all_ this data
6is allocated, not just that one part for selected applet. 6is allocated, not just that one part for selected applet.
7 7
8What "allocated" exactly means, depends on arch. 8What "allocated" exactly means, depends on arch.
9On nommu it's probably bites the most, actually using real 9On NOMMU it's probably bites the most, actually using real
10RAM for rwdata and bss. On i386, bss is lazily allocated 10RAM for rwdata and bss. On i386, bss is lazily allocated
11by COWed zero pages. Not sure about rwdata - also COW? 11by COWed zero pages. Not sure about rwdata - also COW?
12 12
13In order to keep bbox NOMMU and small-mem systems friendly 13In order to keep busybox NOMMU and small-mem systems friendly
14we should avoid large global data in our applets, and should 14we should avoid large global data in our applets, and should
15minimize usage of libc functions which implicitly use 15minimize usage of libc functions which implicitly use
16such structures in libc. 16such structures.
17 17
18Small experiment measures "parasitic" bbox memory consumption. 18Small experiment to measure "parasitic" bbox memory consumption:
19Here we start 1000 "busybox sleep 10" in parallel. 19here we start 1000 "busybox sleep 10" in parallel.
20bbox binary is practically allyesconfig static one, 20busybox binary is practically allyesconfig static one,
21built against uclibc: 21built against uclibc. Run on x86-64 machine with 64-bit kernel:
22 22
23bash-3.2# nmeter '%t %c %b %m %p %[pn]' 23bash-3.2# nmeter '%t %c %m %p %[pn]'
2423:17:28 .......... 0 0 168M 0 147 2423:17:28 .......... 168M 0 147
2523:17:29 .......... 0 0 168M 0 147 2523:17:29 .......... 168M 0 147
2623:17:30 U......... 0 0 168M 1 147 2623:17:30 U......... 168M 1 147
2723:17:31 SU........ 0 188k 181M 244 391 2723:17:31 SU........ 181M 244 391
2823:17:32 SSSSUUU... 0 0 223M 757 1147 2823:17:32 SSSSUUU... 223M 757 1147
2923:17:33 UUU....... 0 0 223M 0 1147 2923:17:33 UUU....... 223M 0 1147
3023:17:34 U......... 0 0 223M 1 1147 3023:17:34 U......... 223M 1 1147
3123:17:35 .......... 0 0 223M 0 1147 3123:17:35 .......... 223M 0 1147
3223:17:36 .......... 0 0 223M 0 1147 3223:17:36 .......... 223M 0 1147
3323:17:37 S......... 0 0 223M 0 1147 3323:17:37 S......... 223M 0 1147
3423:17:38 .......... 0 0 223M 1 1147 3423:17:38 .......... 223M 1 1147
3523:17:39 .......... 0 0 223M 0 1147 3523:17:39 .......... 223M 0 1147
3623:17:40 .......... 0 0 223M 0 1147 3623:17:40 .......... 223M 0 1147
3723:17:41 .......... 0 0 210M 0 906 3723:17:41 .......... 210M 0 906
3823:17:42 .......... 0 0 168M 1 147 3823:17:42 .......... 168M 1 147
3923:17:43 .......... 0 0 168M 0 147 3923:17:43 .......... 168M 0 147
40 40
41This requires 55M of memory. Thus 1 trivial busybox applet 41This requires 55M of memory. Thus 1 trivial busybox applet
42takes 55k of memory. 42takes 55k of memory on 64-bit x86 kernel.
43
44On 32-bit kernel we need ~26k per applet.
45
46(Data from NOMMU arches are sought. Provide 'size busybox' output too)
43 47
44 48
45 Example 1 49 Example 1
@@ -104,8 +108,12 @@ its needs. Library functions are prohibited from using it.
104 108
105#define G (*(struct globals*)&bb_common_bufsiz1) 109#define G (*(struct globals*)&bb_common_bufsiz1)
106 110
107Be careful, though, and use it only if 111Be careful, though, and use it only if globals fit into bb_common_bufsiz1.
108sizeof(struct globals) <= sizeof(bb_common_bufsiz1). 112Since bb_common_bufsiz1 is BUFSIZ + 1 bytes long and BUFSIZ can change
113from one libc to another, you have to add compile-time check for it:
114
115if(sizeof(struct globals) > sizeof(bb_common_bufsiz1))
116 BUG_<applet>_globals_too_big();
109 117
110 118
111 Drawbacks 119 Drawbacks
@@ -135,7 +143,7 @@ static int tabstop;
135static struct termios term_orig __attribute__ ((aligned (4))); 143static struct termios term_orig __attribute__ ((aligned (4)));
136static struct termios term_vi __attribute__ ((aligned (4))); 144static struct termios term_vi __attribute__ ((aligned (4)));
137 145
138reduced bss size by 32 bytes, because gcc sometimes aligns structures to 146reduces bss size by 32 bytes, because gcc sometimes aligns structures to
139ridiculously large values. asm output diff for above example: 147ridiculously large values. asm output diff for above example:
140 148
141 tabstop: 149 tabstop:
@@ -154,3 +162,15 @@ ridiculously large values. asm output diff for above example:
154 .size term_vi, 60 162 .size term_vi, 60
155 163
156gcc doesn't seem to have options for altering this behaviour. 164gcc doesn't seem to have options for altering this behaviour.
165
166gcc 3.4.3:
167// gcc aligns to 32 bytes if sizeof(struct) >= 32
168struct st {
169 int c_iflag,c_oflag,c_cflag,c_lflag;
170 int i1,i2,i3; // struct will be aligned to 4 bytes
171// int i1,i2,i3,i4; // struct will be aligned to 32 bytes
172};
173struct st t = { 1 };
174// same for arrays
175char vc31[31] = { 1 }; // unaligned
176char vc32[32] = { 1 }; // aligned to 32 bytes