linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] uselex.rb as a tiny tool to find dead code
@ 2013-08-07 21:43 Sergei Trofimovich
  2013-08-07 21:43 ` [PATCH 1/7] btrfs: cleanup: mark 'btrfs_lookup_fs_root' as static Sergei Trofimovich
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Sergei Trofimovich @ 2013-08-07 21:43 UTC (permalink / raw)
  To: linux-btrfs, Chris Mason, Josef Bacik; +Cc: linux-kernel, Sergei Trofimovich

From: Sergei Trofimovich <slyfox@gentoo.org>

Hi guys!

TL;DR:

the patches remove (currently or already) dead code
and localize symbol visibility used only in one module.

Thanks!

The Story:

Once upon a time I've got very simple idea to find dead code
in large C/C++ mixed project at work.

The things of my primary interest were things of too large
visibility scope, like:
 - externally visible global variables used only in module
   defining the variable
 - and functions of the same property

Once you identify those functions and mark as 'static' you
achieve two goals:

 - minor: give compiler possibility to inline code a bit better
   (especially for one-caller case)
 - more interesting: possibility to spot that the symbol is no
   longer used at all

Hence the project idea:
1. scan all intermediate object (.o) files for exported symbols
2. find such symbols that are not imported into any .o files

Meet uselex.rb: one-file script to parse 'nm' output:

    https://github.com/trofi/uselex/blob/master/uselex.rb

For linux's kernel it's use is as simple as:

    $ make $config && make
    $ uselex.rb `find -name '*.o'`

and you've got material to look at!

It outputs 3000 symbols thus I've started small:

    $ uselex.rb `find fs/btrfs -name '*.o'

To get an impression it reports such things:

    set_state_private: [R]: exported from: fs/btrfs/built-in.o fs/btrfs/btrfs.o fs/btrfs/extent_io.o
    btrfs_get_inode_ref_index: [R]: exported from: fs/btrfs/built-in.o fs/btrfs/inode-item.o fs/btrfs/btrfs.o
    btrfs_print_tree: [R]: exported from: fs/btrfs/built-in.o fs/btrfs/print-tree.o fs/btrfs/btrfs.o
    btrfs_reada_detach: [R]: exported from: fs/btrfs/built-in.o fs/btrfs/reada.o fs/btrfs/btrfs.o
    __btrfs_getxattr: [R]: exported from: fs/btrfs/built-in.o fs/btrfs/xattr.o fs/btrfs/btrfs.o
    __btrfs_setxattr: [R]: exported from: fs/btrfs/built-in.o fs/btrfs/xattr.o fs/btrfs/btrfs.o
    btrfs_read_root_item: [R]: exported from: fs/btrfs/root-tree.o fs/btrfs/built-in.o fs/btrfs/btrfs.o
    __tracepoint_btrfs_sync_fs: [R]: exported from: fs/btrfs/super.o fs/btrfs/built-in.o fs/btrfs/btrfs.o
    btrfs_start_transaction_lflush: [R]: exported from: fs/btrfs/transaction.o fs/btrfs/built-in.o fs/btrfs/btrfs.o
    btrfs_write_and_wait_marked_extents: [R]: exported from: fs/btrfs/transaction.o fs/btrfs/built-in.o fs/btrfs/btrfs.o
    ulist_fini: [R]: exported from: fs/btrfs/ulist.o fs/btrfs/built-in.o fs/btrfs/btrfs.o
    ulist_init: [R]: exported from: fs/btrfs/ulist.o fs/btrfs/built-in.o fs/btrfs/btrfs.o

You just need to make sure it does not lie too much.

For example '__btrfs_getxattr' needs to be brought under '#ifdef CONFIG_BTRFS_FS_POSIX_ACL'
and not removed entirely.

Thanks for your patience!

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-08-08 22:00 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-07 21:43 [PATCH 0/7] uselex.rb as a tiny tool to find dead code Sergei Trofimovich
2013-08-07 21:43 ` [PATCH 1/7] btrfs: cleanup: mark 'btrfs_lookup_fs_root' as static Sergei Trofimovich
2013-08-07 21:43 ` [PATCH 2/7] btrfs: cleanup: mark 'set_state_private' " Sergei Trofimovich
2013-08-07 21:43 ` [PATCH 3/7] btrfs: cleanup: mark 'btrfs_write_and_wait_marked_extents' " Sergei Trofimovich
2013-08-08 13:39   ` David Sterba
2013-08-07 21:43 ` [PATCH 4/7] btrfs: cleanup: removed unused 'btrfs_start_transaction_lflush' Sergei Trofimovich
2013-08-08 13:32   ` David Sterba
2013-08-07 21:43 ` [PATCH 5/7] btrfs: cleanup: mark 'btrfs_read_root_item' as static Sergei Trofimovich
2013-08-07 21:43 ` [PATCH 6/7] btrfs: cleanup: removed unused 'btrfs_reada_detach' Sergei Trofimovich
2013-08-08  7:33   ` Arne Jansen
2013-08-08 13:26     ` David Sterba
2013-08-08 17:46       ` Zach Brown
2013-08-08 19:11         ` Arne Jansen
2013-08-08 22:00           ` David Sterba
2013-08-07 21:43 ` [PATCH 7/7] btrfs: cleanup: removed unused 'btrfs_get_inode_ref_index' Sergei Trofimovich
2013-08-08 14:02   ` David Sterba
2013-08-07 22:02 ` [PATCH 0/7] uselex.rb as a tiny tool to find dead code Eric Sandeen
2013-08-07 22:13   ` Sergei Trofimovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).