티스토리 뷰

조사

Measuring the kernel

덕쑤 2013. 6. 21. 11:45

Measuring the kernel

커널 사이즈를 판단을 위한 3가지 관점

1. 커널이미지는 플레쉬에 저장이된다.

2. RAM 의 커널이미지는 정적인 크기이다. (보통 압축되지 않은 이미지이다)

- 커널이 로딩될때 text, data, BSS segment가 포함된다. text와 BSS segment는 커널 실행시간에도 일정한 크기를 유지하지만 data와 stack segment는 시스테의 요구에 따라 늘어날수 있다. 

3. 커널은 일정량의 dynamic REM을 사용한다.

- 사용량은 시스템이 동작하는동안 변경이 될수있다. 그러나 시스템이 셋업될때 메모리의 베이스라인량만큼 할당이된다. 특정 어플리케이션의 요구되는 최소한의 메모리보다 더 많이 할당이 될수도 있다.


XIP DRIP 조사해서 추가하기


Measuring the kernel image size

The compressed kernel image is what is stored in the flash or ROM of the target device. The size of this image can be obtained by examining the size of the image file in the host filesystem with the 'ls -l' command:

  • for example: 'ls -l vmlinuz' or 'ls -l bzImage' (or whatever the compressed image name is for your platform.) 


Measuring the kernel text, data and bss segments

Use the size command to determine the size of the text, data, and BSS segments of a kernel image.

Note BSS segment는 커널이미지에 포함되어있지않다. 왜나면 메모리가 제로인 상환에서 통합될수가 없기때문이다. 또 한 이미지 안에는 부팅과정에서 텍스트 영역과 데이터 영역을 초기화 하기 위한 코드가 있다. 이러한 요인들 때문에  size 명령은 정적 커널 RAM 크기에 정확하게 올바른 값을 제공하지 않는다. 

하지만 it can be used as a reasonable estimate.

To use the size command, run it with the filename of the uncompressed kernel image (which is usually vmlinux).

  • for example: 'size vmlinux'

Example output:

   text    data     bss     dec     hex filename
2921377  369712  132996 3424085  343f55 vmlinux

Measuring and comparing sub-parts of the kernel

커널영역을 줄일수 있는 영역을 찾기 위해서는 sub-system과 symbol의정적인 크기를 줄이는 것이 종종 유용하다. 3가지 방법을 설할것이다. 

1. 어떻게 각각의 sub-system의 크기를 볼것인가?

2. 어떻게 개별적인 symbal의 크기를 볼것인가?

3. 어떻게 두개의 커널간의 심벌의 크기를 비교할것인가?

이것은 매우 유용하다. 커널을 설정한후 커널의 어느 부분에 영향을 주었는지를 알수있고 이정보를 통해서나의 결정이 어떠한 영향을 줄지예상할수 있다.

Measuring major kernel subsystems

The major sub-systems of the kernel are put into library object files named built-in.o in the corresponding sub-directory for that sub-system within the kernel build directory. The major sub-directories, at the time of this writing (for kernel 2.6.17) are: init, user, kernel, mm, fs, ipc, security, crypto, block, ltt, drivers, sound, net, lib

To see the size of the major kernel sections (code, data, and BSS), use the size command, with a wildcard for the first level of sub-directory:

  • size */built-in.o

You can pipe this output through sort to sort by the largest libraries:

  • size */built-in.o | sort -n -r -k 4

Example output:

 731596   53144   33588  818328   c7c98 drivers/built-in.o
 687960   24972    2648  715580   aeb3c fs/built-in.o
 547844   19508   28052  595404   915cc net/built-in.o
 184072    6256   32440  222768   36630 kernel/built-in.o
 141956    3300    2852  148108   2428c mm/built-in.o
  68048    1804    1096   70948   11524 block/built-in.o
  26216     768       0   26984    6968 crypto/built-in.o
  17744    2412    2124   22280    5708 init/built-in.o
  20780     292     124   21196    52cc ipc/built-in.o
  18768      68       0   18836    4994 lib/built-in.o
   2116       0       0    2116     844 security/built-in.o
    134       0       0     134      86 usr/built-in.o
   text    data     bss     dec     hex filename

To see even greater detail, you can examine the size of built-in.o files even deeper in the kernel build hierarchy, using the find command:

  • find . -name "built-in.o" | xargs size | sort -n -r -k 4

Example output:

 731596   53144   33588  818328   c7c98 ./drivers/built-in.o
 687960   24972    2648  715580   aeb3c ./fs/built-in.o
 547844   19508   28052  595404   915cc ./net/built-in.o
 260019    9824    4944  274787   43163 ./net/ipv4/built-in.o
 184072    6256   32440  222768   36630 ./kernel/built-in.o
...

Alert.gif Note: Please be careful interpreting the results from the size of the built-in.o files in sub-directories. In general, the object files are aggregated into the libraries of parent directories, meaning that many object files will have their size counted twice. You cannot simply add the columns for an indication of the total kernel size
Measuring individual kernel symbols

You can measure the size of individual kernel symbols using the 'nm' command. Using the nm --size -r vmlinux

[tbird@crest ebony]$ nm --size -r vmlinux | head -10
00008000 b read_buffers
00004000 b __log_buf
00003100 B ide_hwifs
000024f8 T jffs2_garbage_collect_pass
00002418 T journal_commit_transaction
00002400 b futex_queues
000021a8 t jedec_probe_chip
00002000 b write_buf
00002000 D init_thread_union
00001e6c t tcp_ack

Legend: The columns of this output are:

  1. size in bytes (in hexadecimal)
  2. symbol type
  3. symbol name.

The symbol type is usually one of:

  • 'b' or 'B' for a symbol in the BSS segment (uninitialized data),
  • 't' or 'T' for a symbol in the text segment (code), or
  • 'd' or 'D' for a symbol in the data segment.

Use 'man nm' for additional information on the 'nm' command.

Comparing kernel symbols between two kernel images

Use the bloat-o-meter command, found in the kernel source scripts directory, to compare the symbol sizes between two kernel images.

  • <kernel-src>/scripts/bloat-o-meter vmlinux.default vmlinux.altconfig

If you get an error: 'chmod a+x <kernel-src>/scripts/bloat-o-meter'

Example output, comparing a baseline kernel to one configured with CONFIG_PRINTK=n:

[] $ ../../linux/scripts/bloat-o-meter vmlinux.baseline vmlinux.no-printk
add/remove: 5/23 grow/shrink: 8/1541 up/down: 1141/-199824 (-198683)
function                                     old     new   delta
proc_ioctl_default                             -     610    +610
proc_reapurb                                   -     296    +296
proc_disconnectsignal                          -      88     +88
proc_releaseinterface                          -      72     +72
proc_claiminterface                            -      36     +36
xprt_adjust_cwnd                             169     182     +13
do_timer                                    1052    1063     +11
i8042_controller_reset                        78      84      +6
serio_init                                   167     172      +5
usb_exit                                      80      81      +1
early_uart_console_init                       45      46      +1
console_unblank                              103     104      +1
console_conditional_schedule                  21      22      +1
parse_early_param                            102     101      -1
machine_emergency_restart                    249     248      -1
console_callback                             239     238      -1
arch_align_stack                              45      44      -1
quirk_p64h2_1k_io                            183     181      -2
printk_time                                    4       -      -4
printk_cpu                                     4       -      -4
oops_timestamp.7                               4       -      -4
neigh_resolve_output                         733     729      -4
msg_level.4                                    4       -      -4
...
de_dump_status                             1586     313    -1273
decode_getfattr                             3156    1748   -1408
ext3_fill_super                             5980    4545   -1435
usbdev_ioctl                                6476    4846   -1630
usb_get_configuration                       4001    1878   -2123
proc_submiturb                              2294       -   -2294
__log_buf                                 131072       - -131072


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
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
글 보관함