User Tools

Site Tools


mywiki:linux:linuxstack

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
mywiki:linux:linuxstack [2014/10/21 10:37] shaoguohmywiki:linux:linuxstack [2022/04/02 17:29] (current) – external edit 127.0.0.1
Line 3: Line 3:
  
 ====== kernel Stack ====== ====== kernel Stack ======
 +The default stack size for a process running in kernel space is 8K (as of 2011). 
 +
 exception/hard IRQ/soft IRQ stack exception/hard IRQ/soft IRQ stack
  
Line 15: Line 17:
  
 ===== checkstack.pl ====== ===== checkstack.pl ======
-checkstack.pl creates a listing of the size of the stack frame used by every function in the kernel (i.e. the total amount of local scratch space used by each function for local variables and whatnot).+checkstack.pl creates a listing of **the size of the stack frame used by every function in the kernel** (i.e. the total amount of local scratch space used by each function for local variables and whatnot).
  
 The way it does this is by going through the disassembly of the kernel and looking for 2 things: function names and instructions which adjust the stack. It looks for function names by looking for lines that match $funcre (qr/^$x* <(.*)>:$/), and it looks for stack adjustment instructions that match $re or $dre; the latter two depend highly on what architecture the kernel was compiled for, which is what the first big block if if/else statements is checking for. $re searches for functions which adjust the stack by a fixed amount (the vast majority of functions), and $dre searches for functions which adjust the stack by a variable amount (rare). The way it does this is by going through the disassembly of the kernel and looking for 2 things: function names and instructions which adjust the stack. It looks for function names by looking for lines that match $funcre (qr/^$x* <(.*)>:$/), and it looks for stack adjustment instructions that match $re or $dre; the latter two depend highly on what architecture the kernel was compiled for, which is what the first big block if if/else statements is checking for. $re searches for functions which adjust the stack by a fixed amount (the vast majority of functions), and $dre searches for functions which adjust the stack by a variable amount (rare).
Line 23: Line 25:
 Example: Example:
  
-  * mips-openwrt-linux-objdump -d vmlinux > vmlinux.S +  * mips-openwrt-linux-objdump -d vmlinux | scripts/checkstack.pl mips
-  * cat vmlinux.S | scripts/checkstack.pl mips+
  
 Its output like below: Its output like below:
Line 38: Line 39:
 0x802ed918 GSW_MulticastRouterPortRemove [vmlinux]: 664 0x802ed918 GSW_MulticastRouterPortRemove [vmlinux]: 664
 0x802edd68 GSW_MulticastSnoopCfgSet [vmlinux]: 664 0x802edd68 GSW_MulticastSnoopCfgSet [vmlinux]: 664
-0x802f1cb4 GSW_PortRedirectSet [vmlinux]: 664 +...
-0x802ed610 GSW_MulticastRouterPortAdd [vmlinux]: 656 +
-0x802f3908 GSW_8021X_EAPOL_RuleSet [vmlinux]: 632 +
-0x802e6b30 GSW_STP_BPDU_RuleSet [vmlinux]: 624 +
-0x8023a820 test_pcomp [vmlinux]: 600 +
-0x8022a7d8 semctl_main [vmlinux]: 584+
 0x8023ade4 test_comp [vmlinux]: 584 0x8023ade4 test_comp [vmlinux]: 584
 0x8022b4e0 SyS_semtimedop [vmlinux]: 520 0x8022b4e0 SyS_semtimedop [vmlinux]: 520
Line 50: Line 46:
 0x8023b690 __test_skcipher [vmlinux]: 496 0x8023b690 __test_skcipher [vmlinux]: 496
 0x80163cd0 elf_kcore_store_hdr [vmlinux]: 464 0x80163cd0 elf_kcore_store_hdr [vmlinux]: 464
-0x801a5110 nlmsvc_mark_resources [vmlinux]: 432 +...
-0x802e2120 proc_write_directpath [vmlinux]: 432 +
-0x80412190 copy_to_user_tmpl.part.33 [vmlinux]: 432 +
-0x802a80bc loop_get_status_old [vmlinux]: 408 +
-0x80197de0 nfs_dns_parse [vmlinux]: 400 +
-0x802a7d58 loop_set_status_old [vmlinux]: 400 +
-0x800d50b4 shmem_file_splice_read [vmlinux]: 368 +
-0x80129268 __generic_file_splice_read [vmlinux]: 368+
 0x80129c08 vmsplice_to_pipe [vmlinux]: 368 0x80129c08 vmsplice_to_pipe [vmlinux]: 368
 0x801aabc8 autofs4_notify_daemon [vmlinux]: 368 0x801aabc8 autofs4_notify_daemon [vmlinux]: 368
Line 70: Line 59:
 0x80122c88 setxattr [vmlinux]: 320 0x80122c88 setxattr [vmlinux]: 320
 0x80147660 elf_core_dump [vmlinux]: 320 0x80147660 elf_core_dump [vmlinux]: 320
-0x8023d1c0 test_hash [vmlinux]: 320 +...
-0x803d8df0 __udp4_lib_mcast_deliver.isra.55 [vmlinux]: 320 +
-0x800895e4 sched_domain_debug_one.constprop.66 [vmlinux]:312 +
-0x8015f668 show_stat [vmlinux]: 312 +
-0x801ac09c autofs4_expire_run [vmlinux]: 312 +
-0x8027d7f4 store_mode [vmlinux]: 312 +
-0x802b9aa4 mtdchar_ioctl [vmlinux]: 312 +
-0x80122880 getxattr [vmlinux]: 304 +
-0x8015f304 meminfo_proc_show [vmlinux]: 304 +
-0x8019e460 exportfs_decode_fh [vmlinux]: 304 +
-0x803696b8 rtnl_newlink [vmlinux]: 304+
 0x80396de0 conntrack_pptp_help [vmlinux]: 304 0x80396de0 conntrack_pptp_help [vmlinux]: 304
 </file> </file>
 +
 +===== CONFIG_FRAME_WARN ===== 
 +This kernel configuration option passes an option to the compiler to cause it to emit a warning when a static stack size for a routine is detected that is larger than the specified threshold. It requires gcc version 4.4 or later in order to work.
 + 
 +The gcc option used is "-Wframe-larger-than=xxx"
 +
 +By default, CONFIG_FRAME_WARN has the value of **1024**, but you can set it to any value from 0 to 8192.
 + 
 +Here is a sample of build output with this option configured to 256: 
 +    ...
 +    CC      ipc/msg.o
 +    CC      ipc/sem.o
 +    .../linux-3.0.y/ipc/sem.c: In function 'semctl_main.clone.7':
 +    .../linux-3.0.y/ipc/sem.c:1021:1: warning: the frame size of 520 bytes is larger than 256 bytes
 +    .../linux-3.0.y/ipc/sem.c: In function 'sys_semtimedop':
 +    .../linux-3.0.y/ipc/sem.c:1514:1: warning: the frame size of 472 bytes is larger than 256 bytes
 +    CC      ipc/shm.o
 +    CC      ipc/ipcns_notifier.o
 +    ...
 +
  
 ===== stack_size =====  ===== stack_size ===== 
Line 111: Line 110:
  
  
-==== CONFIG_DEBUG_STACK_USAGE / CONFIG_DEBUG_STACKOVERFLOW ====+===== CONFIG_DEBUG_STACK_USAGE / CONFIG_DEBUG_STACKOVERFLOW ===== 
 # dmesg | grep greatest        # dmesg | grep greatest       
 <file>                                                 <file>                                                
mywiki/linux/linuxstack.1413859027.txt.gz · Last modified: (external edit)