debugfs: add small file operations for most files
authorJohannes Berg <johannes.berg@intel.com>
Tue, 22 Oct 2024 13:18:34 +0000 (15:18 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 23 Oct 2024 14:47:01 +0000 (16:47 +0200)
commit8dc6d81c6b2acc434b00c4585f0594739031c4e4
treefefeebc094a02eabd16bd9cfacb375a1f60710b2
parentb457d8713872a9aad89c8a57dd8fe471c7db158d
debugfs: add small file operations for most files

As struct file_operations is really big, but (most) debugfs
files only use simple_open, read, write and perhaps seek, and
don't need anything else, this wastes a lot of space for NULL
pointers.

Add a struct debugfs_short_fops and some bookkeeping code in
debugfs so that users can use that with debugfs_create_file()
using _Generic to figure out which function to use.

Converting mac80211 to use it where possible saves quite a
bit of space:

1010127  205064    1220 1216411  128f9b net/mac80211/mac80211.ko (before)
 981199  205064    1220 1187483  121e9b net/mac80211/mac80211.ko (after)
-------
 -28928 = ~28KiB

With a marginal space cost in debugfs:

   8701     550      16    9267    2433 fs/debugfs/inode.o (before)
  25233     325      32   25590    63f6 fs/debugfs/file.o  (before)
   8914     558      16    9488    2510 fs/debugfs/inode.o (after)
  25380     325      32   25737    6489 fs/debugfs/file.o  (after)
---------------
   +360      +8

(All on x86-64)

A simple spatch suggests there are more than 300 instances,
not even counting the ones hidden in macros like in mac80211,
that could be trivially converted, for additional savings of
about 240 bytes for each.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/20241022151838.26f9925fb959.Ia80b55e934bbfc45ce0df42a3233d34b35508046@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
fs/debugfs/file.c
fs/debugfs/inode.c
fs/debugfs/internal.h
include/linux/debugfs.h