Linux Kernel裁剪--ksize的使用

Linux Kernel裁剪–menuconfig的使用文章中我们讲了使用menuconfig来做Kernel的裁剪。
在yocto项目中提供了一个ksize.py的脚本,可以输出当前编译中所有模块的大小,通过这些大小信息,我们可以决定裁剪哪个模块。


ksize.py介绍

在yocto项目中的sources/poky/scripts/tiny/目录下有ksize.pydirsize.py两个文件。功能分别如下:

  • ksize.py:Display details of the kernel build size, broken up by built-in.o. Sort the objects by size. Run from the top level kernel build directory.
  • dirsize.py:Display details of the root filesystem size, broken up by directory.Allows for limiting by size to focus on the larger files.

ksize.py使用

使用在kernel目录下执行#python ksize.py,可以获得如下降序的输出,根据这些内容,我们可以知道当前系统编译了哪些模块。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Linux Kernel                          total |       text       data        bss
--------------------------------------------------------------------------------
vmlinux 9907245 | 7075717 2558244 273284
--------------------------------------------------------------------------------
drivers/built-in.o 3663728 | 3381077 239019 43632
net/built-in.o 1353193 | 1220555 76062 56576
fs/built-in.o 1221940 | 1185451 13489 23000
kernel/built-in.o 1007639 | 844380 85751 77508
mm/built-in.o 614522 | 540485 43449 30588
sound/built-in.o 230541 | 224237 3080 3224
block/built-in.o 216496 | 207289 6295 2912
lib/built-in.o 166456 | 163392 656 2408
crypto/built-in.o 121022 | 101636 7994 11392
security/built-in.o 70354 | 64343 5395 616
ipc/built-in.o 60459 | 58445 1990 24
init/built-in.o 44249 | 14768 29329 152
usr/built-in.o 142 | 142 0 0
--------------------------------------------------------------------------------
sum 8770741 | 8006200 512509 252032
delta 1136504 | -930483 2045735 21252


drivers total | text data bss
--------------------------------------------------------------------------------
drivers/built-in.o 3663728 | 3381077 239019 43632
--------------------------------------------------------------------------------
drivers/gpu/built-in.o 500404 | 494182 5922 300
drivers/usb/built-in.o 432817 | 397803 32054 2960
drivers/mxc/built-in.o 361344 | 268907 80141 12296
drivers/media/built-in.o 279867 | 270194 7329 2344
drivers/base/built-in.o 210668 | 201892 7864 912
drivers/scsi/built-in.o 183594 | 167352 15434 808
drivers/mmc/built-in.o 172884 | 169155 3577 152
drivers/clk/built-in.o 155525 | 141697 3316 10512
drivers/tty/built-in.o 111335 | 108328 2287 720
drivers/video/built-in.o 105953 | 92697 13112 144
drivers/mtd/built-in.o 79980 | 76361 2587 1032
drivers/staging/built-in.o 77356 | 75824 1452 80
drivers/cpufreq/built-in.o 68940 | 63435 4761 744
drivers/net/built-in.o 62838 | 60347 2426 65
drivers/i2c/built-in.o 59472 | 56958 2402 112
drivers/pinctrl/built-in.o 58007 | 56414 1521 72
drivers/regulator/built-in.o 51426 | 48498 2400 528
drivers/of/built-in.o 48692 | 47133 587 972
drivers/android/built-in.o 47364 | 44240 276 2848
drivers/gpio/built-in.o 46591 | 45139 1376 76
drivers/iommu/built-in.o 42756 | 41484 1152 120
drivers/thermal/built-in.o 40615 | 38166 2241 208
drivers/spi/built-in.o 39915 | 36670 3221 24
drivers/input/built-in.o 38894 | 37246 1584 64
drivers/irqchip/built-in.o 30444 | 25846 4270 328
drivers/dma/built-in.o 28445 | 27411 858 176
drivers/rpmsg/built-in.o 26968 | 13559 13393 16
drivers/phy/built-in.o 25168 | 24163 940 65
drivers/char/built-in.o 24712 | 22176 1736 800
drivers/soc/built-in.o 22102 | 19109 568 2425
drivers/dma-buf/built-in.o 21025 | 20909 44 72
drivers/rtc/built-in.o 19366 | 18614 624 128
drivers/block/built-in.o 15040 | 14118 818 104
drivers/cpuidle/built-in.o 13908 | 11523 2345 40
drivers/extcon/built-in.o 13586 | 12130 1440 16
drivers/power/built-in.o 13141 | 10037 2504 600
drivers/watchdog/built-in.o 12937 | 12379 477 81
drivers/virtio/built-in.o 12490 | 12049 393 48
drivers/perf/built-in.o 12364 | 10090 2218 56
drivers/pwm/built-in.o 12183 | 11103 952 128
drivers/firmware/built-in.o 10940 | 10251 601 88
drivers/clocksource/built-in.o 9421 | 8462 839 120
drivers/hwmon/built-in.o 9066 | 8498 520 48
drivers/nvmem/built-in.o 8857 | 7881 928 48
drivers/amba/built-in.o 5628 | 5124 504 0
drivers/reset/built-in.o 4647 | 3967 680 0
drivers/mailbox/built-in.o 4551 | 4295 256 0
drivers/spmi/built-in.o 4299 | 4082 168 49
drivers/misc/built-in.o 3333 | 3149 184 0
drivers/mfd/built-in.o 2122 | 1910 208 4
drivers/ras/built-in.o 608 | 584 8 16
--------------------------------------------------------------------------------
sum 3655144 | 3373641 237930 43573
delta 8584 | 7436 1089 59


net total | text data bss
--------------------------------------------------------------------------------
net/built-in.o 1353193 | 1220555 76062 56576
--------------------------------------------------------------------------------
net/ipv4/built-in.o 469015 | 417817 26198 25000
net/ipv6/built-in.o 316158 | 279174 15700 21284
net/core/built-in.o 304912 | 284889 16287 3736
net/llc/built-in.o 63390 | 50366 12000 1024
net/xfrm/built-in.o 53804 | 52100 880 824
net/*.o 38792 | 37932 756 104
net/netlink/built-in.o 31723 | 30596 827 300
net/packet/built-in.o 29162 | 28633 529 0
net/unix/built-in.o 27576 | 22811 640 4125
net/sched/built-in.o 9863 | 8326 1537 0
net/dns_resolver/built-in.o 3734 | 3574 144 16
net/ethernet/built-in.o 2806 | 2726 80 0
net/802/built-in.o 1484 | 1384 88 12
--------------------------------------------------------------------------------
sum 1352419 | 1220328 75666 56425
delta 774 | 227 396 151


fs total | text data bss
--------------------------------------------------------------------------------
fs/built-in.o 1221940 | 1185451 13489 23000
--------------------------------------------------------------------------------
fs/*.o 458917 | 436661 5680 16576
fs/ext4/built-in.o 333360 | 330151 2089 1120
fs/proc/built-in.o 100347 | 99489 698 160
fs/fat/built-in.o 56932 | 56692 184 56
fs/jbd2/built-in.o 55802 | 55581 101 120
fs/ext2/built-in.o 46214 | 46126 80 8
fs/quota/built-in.o 32170 | 30297 1489 384
fs/kernfs/built-in.o 24769 | 20450 191 4128
fs/notify/built-in.o 24246 | 23522 516 208
fs/debugfs/built-in.o 22506 | 22186 304 16
fs/configfs/built-in.o 21240 | 20759 449 32
fs/nls/built-in.o 14765 | 14529 232 4
fs/hugetlbfs/built-in.o 10352 | 10243 65 44
fs/sysfs/built-in.o 9026 | 8943 59 24
fs/devpts/built-in.o 4126 | 3489 629 8
fs/ramfs/built-in.o 2648 | 2576 64 8
fs/exportfs/built-in.o 2576 | 2575 1 0
--------------------------------------------------------------------------------
sum 1219996 | 1184269 12831 22896
delta 1944 | 1182 658 104


kernel total | text data bss
--------------------------------------------------------------------------------
kernel/built-in.o 1007639 | 844380 85751 77508
--------------------------------------------------------------------------------
kernel/*.o 478489 | 403442 40281 34766
kernel/sched/built-in.o 142040 | 123170 16198 2672
kernel/time/built-in.o 112568 | 90159 15113 7296
kernel/events/built-in.o 76317 | 72106 3615 596
kernel/irq/built-in.o 56272 | 52350 1782 2140
kernel/printk/built-in.o 49827 | 20187 416 29224
kernel/rcu/built-in.o 40706 | 34826 5834 46
kernel/locking/built-in.o 21259 | 21226 29 4
kernel/power/built-in.o 17474 | 15685 1573 216
kernel/bpf/built-in.o 11262 | 10786 108 368
--------------------------------------------------------------------------------
sum 1006214 | 843937 84949 77328
delta 1425 | 443 802 180


sound total | text data bss
--------------------------------------------------------------------------------
sound/built-in.o 230541 | 224237 3080 3224
--------------------------------------------------------------------------------
sound/core/built-in.o 132362 | 127598 1788 2976
sound/soc/built-in.o 97681 | 96177 1264 240
sound/*.o 774 | 718 40 16
--------------------------------------------------------------------------------
sum 230817 | 224493 3092 3232
delta -276 | -256 -12 -8


block total | text data bss
--------------------------------------------------------------------------------
block/built-in.o 216496 | 207289 6295 2912
--------------------------------------------------------------------------------
block/*.o 208934 | 199767 6263 2904
block/partitions/built-in.o 7370 | 7338 28 4
--------------------------------------------------------------------------------
sum 216304 | 207105 6291 2908
delta 192 | 184 4 4


lib total | text data bss
--------------------------------------------------------------------------------
lib/built-in.o 166456 | 163392 656 2408
--------------------------------------------------------------------------------
lib/*.o 217281 | 215730 1397 154
lib/zlib_deflate/built-in.o 17683 | 15299 96 2288
lib/zlib_inflate/built-in.o 12196 | 12196 0 0
lib/lzo/built-in.o 3259 | 3259 0 0
--------------------------------------------------------------------------------
sum 250419 | 246484 1493 2442
delta -83963 | -83092 -837 -34


security total | text data bss
--------------------------------------------------------------------------------
security/built-in.o 70354 | 64343 5395 616
--------------------------------------------------------------------------------
security/keys/built-in.o 36035 | 33971 1480 584
security/*.o 33076 | 29165 3899 12
security/integrity/built-in.o 1207 | 1175 16 16
--------------------------------------------------------------------------------
sum 70318 | 64311 5395 612
delta 36 | 32 0 4

Title:Linux Kernel裁剪--ksize的使用

Author:Victor Huang

Time:2019-04-14 / 16:04

Link:http://wowothink.com/42532517/

License: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)