Refactor kernel strings - Results

Final report for the task Refactor Kernel Strings

= Tooling =

bloat-o-meter

 * parsing a diff can be helpful to get an estimate of what can be achieved
 * for precise results, bloat-o-meter from the kernel scripts directory is way better
 * some patches for dealing with .rodata were needed
 * will be send out after v4.8-rc1 aiming for v4.9.
 * git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git strings/bloat-o-meter

ninja-measure-bloat
To calculate savings for a whole patch series, a custom script based on the following pseudo-code was created:

proper .config

 * allyesconfig difficult to use (doesn't build on ARM32; builds a lot of noise)
 * make defconfig for x86-32 with CONFIG_OLPC turned out to be a good candidate

= Centralizing filesystems =

Suggesting fs_err

 * we have good experiences with dev_err and friends for struct device
 * we could introduce something like fs_err for struct super_block
 * quick tests showed, it could save a few KB for some filesystems
 * found a questionable use case of dev_err while evaluating

side track: dev_err & __func__

 * looks pretty useless when the error message is unique
 * __func__ is pretty expensive
 * Removing all occurences removes easily &gt;60K (measured by parsing the &gt;850K diff)
 * needs to be manually reviewed, though
 * example series for the RTC subsystem (18 patches, saved 156 byte/driver average, altogether saves &gt;2.5K (5.1%))
 * will be send out after v4.8-rc1 aiming for v4.9.
 * git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git strings/rtc-no-func
 * more promising than fs_err for now

= Centralizing USB =

centralizing usb_submit_urb

 * lots of hits for this function when searching for dev_err and __func__
 * a lot of returned %d messages with little value
 * gkh says all messages can go
 * usb_submit_urb itself prints a few error messages, yet not on all exit paths
 * this should be done first
 * then, we can save ~20K from ~120 drivers
 * preparational changes in 4.9, removals in 4.10?

-ENOMEM messages for usb_alloc_urb already centralized

 * Some callers of usb_alloc_urb print -ENOMEM messages which is totally unneeded and removing those saves 4K in 53 drivers.
 * (update: with an improved coccinelle script, the savings were &gt;6KB)
 * will be send out after v4.8-rc1 aiming for v4.9.
 * git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git strings/usb_alloc_urb

fix usb-skeleton.c, too

 * template for new usb drivers
 * problems present here get copied over numerous times
 * removing aforementioned issues saves not much in byte, but scales awesomely well :)
 * will be fixed together with the series above
 * such drivers need special care

= Centralizing I2C =


 * fix another subsystem to have one fixup documented and upstream
 * will be send out after v4.8-rc1 aiming for v4.9.
 * git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git strings/i2c

preparing the i2c core

 * 7 patches to prepare i2c_add_adapter
 * added 3 error messages
 * improved 4 error messages
 * 1 refactoring (saving bytes already)
 * 1 resource leak bugfix(!)
 * all drivers have common and precise error messages for free

fixing the drivers

 * 64 removals across the tree
 * saving around 3K of variuos permutations of registering failed
 * and more considering the future (i.e. scales well)
 * ~50 bytes/driver (half .rodata, half .text)

save strings when i2c_add_adapter returns success

 * more difficult than expected
 * drivers print various additional information
 * some of them are not available to the I2C core
 * some could be, but are not currently (e.g. bus speed)
 * would need bigger refactoring, beyond the scope of this task
 * for further activities, focus on error paths
 * interesting viewpoint nonetheless

= Conclusion =

This time...

 * about 30K of strings removed
 * tools are ready and workflow is in place
 * reference examples on the way to mainline

a LOT of work still to be done

 * help is much appreciated
 * it is not strictly janitorial, though
 * focus on removing error strings first
 * reviewing patches to improve coccinelle scripts takes most time