tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Unused functions in kernels



I'm doing a small investigation of NetBSD code bloat (see my blog post http://kristerw.blogspot.se/2016/05/20-years-of-netbsd-code-bloat.html for some background), and I noticed that the kernels have a fair amount of unused code -- for example, 7% of the sun3 GENERIC kernel consists of functions that do not have any callers.

I'm not sure how much of this is reasonable to eliminate -- many are trivial functions that do not contribute much to the size, but there are a number of larger pieces that probably should be removed (for example, all callers of ip6_forward.c are within #if 0 blocks, so ip6_forward.c could be removed from files.netinet6)

I made a script to find unused global symbols, and you can see the result for sun3 GENERIC below. Removing these eliminates 64392 bytes from the text segment.

The list does not include libkern.o, as those functions are meant to be available for loadable modules. But there are lots of unused things
there too -- changing libkern to be an "ar" archive saves 50025 bytes,
so it may make sense to eliminate this on small configurations not using loadable modules?

My script is available in https://github.com/kristerw/netbsd_utils
See the comment in the top of the file for usage and limitations.

   /Krister

PS. I'm not planning to work on eliminating the unused functions right now, but I'll be happy to work on improving the script if you find it useful!


List of unused symbols in sun3 GENERIC kernel
---------------------------------------------
[Note: There are some spurious functions in this list -- functions where all uses are inlined are incorrectly reported as unused.]

sys/arch/m68k/fpe/fpu_cordic.c
  fpu_cordit2

sys/arch/m68k/m68k/compat_16_machdep.c
  sendsig_sigcontext

sys/arch/m68k/m68k/copy.s
  fubyte
  susword
  suword
  ucas_32
  ucas_int
  ucas_ptr

sys/arch/m68k/m68k/db_interface.c
  kdb_kintr

sys/arch/sun3/dev/fb.c
  fb_pfour_get_video

sys/arch/sun3/dev/si.c
  si_debug
  si_dma_intr_timo

sys/arch/sun3/dev/si_sebuf.c
  se_debug
  se_dma_alloc
  se_dma_eop
  se_dma_free
  se_dma_intr_timo
  se_dma_poll
  se_dma_setup
  se_dma_start
  se_dma_stop
  se_intr_off
  se_intr_on

sys/arch/sun3/dev/xd.c
  xdc_e2str

sys/arch/sun3/dev/xy.c
  xyc_entoact

sys/arch/sun3/sun3/locore.s
  DCIU
  ICIA
  _Idle
  _getsr
  _spl
  _splraise
  eintrcnt
  eintrnames
  getsp
  intrnames
  masterpaddr
  start

sys/arch/sun3/sun3/machdep.c
  dumpmag

sys/arch/sun3/sun3/pmap.c
  pmap_is_modified
  pmap_procwr
  pmap_stats

sys/arch/sun68k/sun68k/bus.c
  _bus_dma_valloc_skewed

sys/arch/sun68k/sun68k/isr.c
  get_vector_entry

sys/compat/common/compat_util.c
  compat_elf_check_interp
  emul_flags_translate

sys/compat/common/kern_info_09.c
  compat_09_sys_uname

sys/compat/common/kern_sig_13.c
  native_sigaction_to_sigaction13

sys/compat/common/kern_sig_43.c
  compat_43_sigmask_to_sigset
  compat_43_sigset_to_sigmask

sys/compat/common/kern_time_50.c
  compat_50_sys___ntp_gettime30

sys/compat/common/vfs_syscalls_50.c
  compat_50_sys_lfs_segwait

sys/compat/sunos/sunos_misc.c
  native_to_sunos_sigset
  sunos_to_native_sigset

sys/conf/debugsyms.c
  _debugsym_dummyfunc

sys/conf/param.c
  fscale

sys/crypto/arc4/arc4.c
  arc4_ctxlen
  arc4_decrypt
  arc4_setkey
  arc4_stream

sys/crypto/cprng_fast/cprng_fast.c
  cprng_fast64

sys/crypto/rijndael/rijndael-api-fst.c
  rijndael_blockDecrypt
  rijndael_blockEncrypt
  rijndael_cipherInit
  rijndael_makeKey
  rijndael_padDecrypt
  rijndael_padEncrypt

sys/crypto/rijndael/rijndael.c
  rijndael_decrypt

sys/ddb/db_command.c
  db_register_tbl
  db_unregister_tbl

sys/ddb/db_kernel.c
  db_alloc

sys/ddb/db_run.c
  db_single_step

sys/ddb/db_sym.c
  db_eqname
  db_sym_numargs
  db_symstr
  ddb_init

sys/ddb/db_variables.c
  db_set_variable

sys/dev/cons.c
  cnbell
  cnhalt

sys/dev/dev_verbose.c
  dev_findproduct
  dev_findvendor

sys/dev/dkwedge/dk.c
  dkwedge_find_by_parent
  dkwedge_get_parent_name
  dkwedge_read

sys/dev/ic/ncr5380sbc.c
  ncr5380_detach

sys/dev/ic/z8530tty.c
  zstty_get_tty_from_dev

sys/dev/scsipi/scsi_base.c
  scsi_change_def

sys/dev/scsipi/scsipi_base.c
  scsipi_channel_timed_thaw
  scsipi_print_cdb
  scsipi_sync_period_to_factor
  scsipi_thread_call_callback

sys/dev/sun/kbd.c
  kbd_bell

sys/kern/cnmagic.c
  cn_destroy_magic

sys/kern/init_main.c
  banner

sys/kern/kern_auth.c
  kauth_authorize_generic
  kauth_authorize_machdep
  kauth_cred_getdata
  kauth_cred_getrefcnt
  kauth_cred_setdata
  kauth_cred_to_uucred
  kauth_deregister_key
  kauth_deregister_scope
  kauth_register_key

sys/kern/kern_cfglock.c
  kernconfig_is_held

sys/kern/kern_condvar.c
  cv_has_waiters
  cv_is_valid
  cv_lockops

sys/kern/kern_core.c
  coredump_offset

sys/kern/kern_cpu.c
  cpu_intr_count
  cpu_setintr

sys/kern/kern_descrip.c
  fbadop_close
  fbadop_stat
  fd_putsock
  fd_putvnode

sys/kern/kern_event.c
  kfilter_register
  kfilter_unregister

sys/kern/kern_hook.c
  critpollhook_disestablish
  critpollhook_establish
  dopowerhooks
  forkhook_disestablish
  forkhook_establish
  mountroothook_disestablish
  mountroothook_establish
  powerhook_disestablish
  powerhook_establish
  shutdownhook_disestablish
  shutdownhook_establish

sys/kern/kern_ksyms.c
  ksyms_addsyms_explicit
  ksyms_get_mod
  ksyms_mod_foreach
  ksyms_modload
  ksyms_modunload

sys/kern/kern_lock.c
  _kernel_lock
  _kernel_lock_ops
  _kernel_locked_p
  _kernel_unlock
  assert_sleepable

sys/kern/kern_lwp.c
  lwp_locked
  lwp_whatis

sys/kern/kern_module.c
  module_builtin_remove
  module_compatible
  module_find_section
  module_hold
  module_prime
  module_rele

sys/kern/kern_pmf.c
  pmf_class_display_register
  pmf_class_input_register
  pmf_debug_suspend
  pmf_device_subtree_resume
  pmf_event_deregister
  pmf_event_register
  pmf_get_platform
  pmf_qual_recursive_copy
  pmf_self_suspensor_init
  pmf_set_platform
  pmf_system_bus_resume
  pmf_system_resume
  pmf_system_suspend

sys/kern/kern_proc.c
  pidtbl_dump
  proc_getspecific
  proc_setspecific
  proc_specific_key_create
  proc_specific_key_delete

sys/kern/kern_rndq.c
  _rnd_add_uint64
  rnd_add_data_sync
  rnd_seed

sys/kern/kern_rwlock.c
  rw_vector_enter
  rw_vector_exit
  rw_vector_tryenter

sys/kern/kern_rwlock_obj.c
  rw_obj_hold

sys/kern/kern_stub.c
  default_bus_space_handle_is_equal
  default_bus_space_is_equal
  dosa_register
  enoioctl
  nullret
  sa_stacks1
  sys_sa_enable
  sys_sa_preempt
  sys_sa_register
  sys_sa_setconcurrency
  sys_sa_stacks
  sys_sa_unblockyield
  sys_sa_yield
  voidop

sys/kern/kern_synch.c
  kpreempt_disabled

sys/kern/kern_sysctl.c
  sysctl_destroyv
  sysctl_free
  sysctl_log_print
  sysctl_needfunc
  sysctl_null

sys/kern/kern_tc.c
  getbintime
  tc_detach
  tc_gonebad

sys/kern/kern_uuid.c
  uuid_dec_be
  uuid_dec_le
  uuid_enc_be
  uuid_enc_le
  uuid_printf
  uuidgen

sys/kern/subr_autoconf.c
  cfdata_ifattr
  config_deactivate
  config_defer
  config_detach_all
  config_detach_children
  config_finalize_register
  config_fini_component
  config_found_ia
  config_init_component
  config_interrupts
  config_mountroot
  device_active
  device_getlock
  device_pmf_bus_private
  device_pmf_bus_register
  device_pmf_driver_set_child_register
  ifattr_match
  null_childdetached

sys/kern/subr_blist.c
  blist_resize

sys/kern/subr_bufq.c
  bufq_cancel

sys/kern/subr_callback.c
  callback_head_destroy
  callback_head_init
  callback_register
  callback_run_roundrobin
  callback_unregister

sys/kern/subr_copy.c
  copyout_proc
  ioctl_copyin
  ioctl_copyout

sys/kern/subr_cpufreq.c
  cpufreq_get
  cpufreq_get_backend
  cpufreq_get_state
  cpufreq_get_state_index
  cpufreq_register
  cpufreq_resume
  cpufreq_set
  cpufreq_set_all
  cpufreq_suspend

sys/kern/subr_device.c
  device_activation
  device_cfattach
  device_has_power

sys/kern/subr_devsw.c
  bdev_dump
  devsw_detach

sys/kern/subr_disk.c
  convertdisklabel
  disk_isbusy
  diskerr

sys/kern/subr_evcnt.c
  evcnt_attach_dynamic_nozero

sys/kern/subr_extent.c
  extent_alloc1
  extent_alloc_region
  extent_alloc_subregion
  extent_destroy

sys/kern/subr_iostat.c
  iostat_seek

sys/kern/subr_ipi.c
  ipi_multicast
  ipi_trigger_multi
  ipi_unicast

sys/kern/subr_kcpuset.c
  kcpuset_atomic_clear
  kcpuset_atomicly_intersect
  kcpuset_atomicly_merge
  kcpuset_atomicly_remove
  kcpuset_clone
  kcpuset_export_u32
  kcpuset_ffs_intersecting
  kcpuset_fill
  kcpuset_intersect
  kcpuset_intersecting_p
  kcpuset_isotherset
  kcpuset_merge
  kcpuset_remove

sys/kern/subr_kmem.c
  kmem_asprintf

sys/kern/subr_kobj.c
  kobj_setname

sys/kern/subr_lwp_specificdata.c
  _lwp_getspecific_by_lwp
  lwp_specific_key_delete

sys/kern/subr_optstr.c
  optstr_get

sys/kern/subr_pcq.c
  pcq_maxitems

sys/kern/subr_percpu.c
  percpu_getptr_remote

sys/kern/subr_pool.c
  phtree_SPLAY_MINMAX
  pool_cache_destruct_object
  pool_cache_reclaim
  pool_cache_sethiwat
  pool_chk
  pool_set_drain_hook

sys/kern/subr_prf.c
  aprint_debug_ifnet
  aprint_error_ifnet
  aprint_naive_dev
  aprint_naive_ifnet
  aprint_verbose_dev
  aprint_verbose_ifnet
  db_vprintf
  device_printf
  logpri
  printf_tolog
  tprintf_open
  ttyprintf
  vlog

sys/kern/subr_pserialize.c
  pserialize_destroy

sys/kern/subr_psref.c
  psref_class_destroy
  psref_copy
  psref_held

sys/kern/subr_specificdata.c
  specificdata_domain_delete

sys/kern/subr_time.c
  tvhzto

sys/kern/subr_vmem.c
  vmem_roundup_size

sys/kern/tty.c
  tty_detach

sys/kern/tty_conf.c
  ttyldisc_detach

sys/kern/uipc_domain.c
  sockaddr_addr
  sockaddr_anyaddr
  sockaddr_format

sys/kern/uipc_mbuf.c
  m_align
  m_append
  m_apply
  m_defrag
  m_devget
  m_getclr
  m_getptr
  mbstat

sys/kern/uipc_mbuf2.c
  m_tag_first
  m_tag_free
  m_tag_init
  m_tag_next

sys/kern/uipc_socket.c
  getsombuf

sys/kern/uipc_socket2.c
  sbappendaddrchain
  sbinsertoob
  solocked
  solocked2

sys/kern/vfs_bio.c
  buf_setvalimit

sys/kern/vfs_dirhash.c
  dirhash_dir_isempty
  dirhash_enter
  dirhash_get
  dirhash_lookup
  dirhash_lookup_freed
  dirhash_purge
  dirhash_put
  dirhash_remove

sys/kern/vfs_mount.c
  mount_finispecific
  mount_getspecific
  mount_setspecific
  mount_specific_key_create
  mount_specific_key_delete
  vfs_unmount_forceone

sys/kern/vfs_subr.c
  VFS_SNAPSHOT
  kinfo_vdebug
  kinfo_vgetfailed
  lockdelay
  printlockedvnodes
  vaccess

sys/kern/vfs_syscalls.c
  do_sys_mkdir
  do_sys_rename
  do_sys_symlink
  do_sys_unlink
  vfs_composefh_free
  vfs_copyinfh_free

sys/kern/vfs_trans.c
  fstrans_dump
  fstrans_is_owner
  vfs_resume
  vfs_suspend

sys/kern/vfs_vnode.c
  vrele_async

sys/kern/vfs_vnops.c
  vn_extattr_get
  vn_extattr_rm
  vn_extattr_set

sys/kern/vfs_wapbl.c
  wapbl_dump
  wapbl_jlock_assert

sys/kern/vfs_xattr.c
  extattr_check_cred

sys/kern/vnode_if.c
  VOP_CLOSEEXTATTR
  VOP_OPENEXTATTR

sys/miscfs/genfs/genfs_io.c
  genfs_compat_getpages
  genfs_compat_gop_write
  genfs_gop_write_rwmap

sys/miscfs/genfs/genfs_vnops.c
  genfs_node_wrlocked

sys/miscfs/kernfs/kernfs_vnops.c
  kernfs_addentry
  kernfs_alloctype
  kfsfileoptree_SPLAY_MINMAX
  kfsfileoptree_SPLAY_REMOVE

sys/miscfs/specfs/spec_vnops.c
  spec_node_lookup_by_mount

sys/net/bpf_filter.c
  bpf_create
  bpf_destroy
  bpf_filter
  bpf_set_cop
  bpf_set_extmem

sys/net/if.c
  if_clone_detach
  if_deactivate
  if_get_byindex
  if_link_state_change
  ifa_ifwithaf

sys/net/if_ethersubr.c
  ether_aton_r
  ether_crc32_be
  ether_set_ifflags_cb

sys/net/if_llatbl.c
  llentry_alloc
  lltable_fill_sa_entry
  lltable_get_af
  lltable_get_ifp

sys/net/if_media.c
  ifmedia_baudrate
  ifmedia_delete_instance
  ifmedia_list_add
  ifmedia_removeall

sys/net/if_ppp.c
  ppp_register_compressor
  ppp_unregister_compressor

sys/net/link_proto.c
  sockaddr_dl_alloc

sys/net/pfil.c
  pfil_add_hook

sys/net/pktqueue.c
  pktq_destroy
  pktq_flush

sys/net/raw_usrreq.c
  raw_usrreq

sys/net/route.c
  rtcache_init_noclone

sys/net/rtsock.c
  rt_ieee80211msg

sys/netinet/if_arp.c
  arpioctl

sys/netinet/in.c
  in_ifscrub
  in_multi_lock_held

sys/netinet/in_proto.c
  sockaddr_in_cmp

sys/netinet/ip_encap.c
  encap_attach
  encap_attach_func
  encap_detach
  encap_getarg

sys/netinet/ip_icmp.c
  icmp_statinc
  icmpmask
  ip_next_mtu

sys/netinet/ip_id.c
  ip_id_fini

sys/netinet/ip_input.c
  ip_drain
  ip_statinc

sys/netinet/tcp_congctl.c
  tcp_congctl_bystruct
  tcp_congctl_unregister

sys/netinet/tcp_sack.c
  sack_dump

sys/netinet/tcp_subr.c
  tcp_statadd
  tcp_statinc

sys/netinet/udp_usrreq.c
  udp_input_checksum
  udp_statinc

sys/netinet6/frag6.c
  ip6_reass_packet

sys/netinet6/icmp6.c
  icmp6_statinc

sys/netinet6/in6.c
  in6_is_addr_deprecated
  in6_sin_2_v4mapsin6_in_sock
  in6ifa_ifwithaddr

sys/netinet6/ip6_flow.c
  ip6flow_create
  ip6flow_fastforward
  ip6flow_invalidate_all
  ip6flow_poolinit
  ip6flow_slowtimo

sys/netinet6/ip6_input.c
  ip6_forward_srcrt
  ip6_sourcecheck
  ip6_sourcecheck_interval
  ip6_statinc

sys/netinet6/ip6_mroute.c
  ip6_mrtproto

sys/netinet6/ip6_output.c
  ip6_copypktopts
  ip6_freepcbopts

sys/netinet6/nd6.c
  nd6_rem_ifa_lle

sys/netinet6/scope6.c
  scope6_get
  scope6_get_default
  scope6_set

sys/netinet6/udp6_usrreq.c
  udp6_statinc

sys/nfs/nfs_srvsubs.c
  nfsrv_copyfh

sys/nfs/nfs_vnops.c
  nfs_null

sys/secmodel/bsd44/secmodel_bsd44.c
  secmodel_bsd44_init
  secmodel_bsd44_start
  secmodel_bsd44_stop

sys/secmodel/secmodel.c
  secmodel_setinfo

sys/secmodel/securelevel/secmodel_securelevel.c
  secmodel_securelevel_init

sys/secmodel/suser/secmodel_suser.c
  secmodel_suser_init

sys/ufs/ffs/ffs_alloc.c
  ffs_blkalloc
  ffs_blkfree_snap
  ffs_checkfreefile
  ffs_freefile_snap

sys/ufs/mfs/mfs_miniroot.c
  mfs_initminiroot

sys/ufs/mfs/mfs_vfsops.c
  mfs_mountroot

sys/uvm/uvm_amap.c
  amap_share_protect

sys/uvm/uvm_aobj.c
  uao_set_pgfl

sys/uvm/uvm_emap.c
  uvm_emap_alloc
  uvm_emap_enter
  uvm_emap_free
  uvm_emap_remove

sys/uvm/uvm_map.c
  _uvm_map_sanity
  _uvm_tree_sanity
  vm_map_busy
  vm_map_locked_p
  vm_map_starved_p

sys/uvm/uvm_meter.c
  uvm_pctparam_set

sys/uvm/uvm_mmap.c
  uvm_mmap_dev

sys/uvm/uvm_page.c
  uvm_page_locked_p
  uvm_page_recolor
  uvm_pageismanaged
  uvm_pagerealloc

sys/uvm/uvm_swap.c
  swapsys_lock
  swapsys_unlock
  uvm_swap_shutdown


Home | Main Index | Thread Index | Old Index