xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Joel Granados via B4 Relay <devnull+j.granados.samsung.com@kernel.org>
To: Luis Chamberlain <mcgrof@kernel.org>,
	willy@infradead.org,  josh@joshtriplett.org,
	Kees Cook <keescook@chromium.org>,
	 Phillip Potter <phil@philpotter.co.uk>,
	 Clemens Ladisch <clemens@ladisch.de>,
	Arnd Bergmann <arnd@arndb.de>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Juergen Gross <jgross@suse.com>,
	 Stefano Stabellini <sstabellini@kernel.org>,
	 Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	 Jiri Slaby <jirislaby@kernel.org>,
	 "James E.J. Bottomley" <jejb@linux.ibm.com>,
	 "Martin K. Petersen" <martin.petersen@oracle.com>,
	 Doug Gilbert <dgilbert@interlog.com>,
	 Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	 Jason Gunthorpe <jgg@ziepe.ca>,
	Leon Romanovsky <leon@kernel.org>,
	 Corey Minyard <minyard@acm.org>, Theodore Ts'o <tytso@mit.edu>,
	 "Jason A. Donenfeld" <Jason@zx2c4.com>,
	David Ahern <dsahern@kernel.org>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	 Robin Holt <robinmholt@gmail.com>,
	Steve Wahl <steve.wahl@hpe.com>,
	 Russ Weight <russell.h.weight@intel.com>,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	Song Liu <song@kernel.org>,
	 "K. Y. Srinivasan" <kys@microsoft.com>,
	 Haiyang Zhang <haiyangz@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>,  Dexuan Cui <decui@microsoft.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	 Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	 Rodrigo Vivi <rodrigo.vivi@intel.com>,
	 Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	 David Airlie <airlied@gmail.com>,
	Daniel Vetter <daniel@ffwll.ch>
Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org,
	 linux-serial@vger.kernel.org, linux-scsi@vger.kernel.org,
	 linuxppc-dev@lists.ozlabs.org, linux-rdma@vger.kernel.org,
	 openipmi-developer@lists.sourceforge.net,
	netdev@vger.kernel.org,  linux-raid@vger.kernel.org,
	linux-hyperv@vger.kernel.org,  intel-gfx@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org,
	 Joel Granados <j.granados@samsung.com>
Subject: [PATCH 00/15] sysctl: Remove sentinel elements from drivers
Date: Thu, 28 Sep 2023 15:21:25 +0200	[thread overview]
Message-ID: <20230928-jag-sysctl_remove_empty_elem_drivers-v1-0-e59120fca9f9@samsung.com> (raw)

From: Joel Granados <j.granados@samsung.com>

What?
These commits remove the sentinel element (last empty element) from the
sysctl arrays of all the files under the "drivers/" directory that use a
sysctl array for registration. The merging of the preparation patches
(in https://lore.kernel.org/all/ZO5Yx5JFogGi%2FcBo@bombadil.infradead.org/)
to mainline allows us to just remove sentinel elements without changing
behavior (more info here [1]).

These commits are part of a bigger set (here
https://github.com/Joelgranados/linux/tree/tag/sysctl_remove_empty_elem_V4)
that remove the ctl_table sentinel. Make the review process easier by
chunking the commits into manageable pieces. Each chunk can be reviewed
separately without noise from parallel sets.

Now that the architecture chunk has been mostly reviewed [6], we send
the "drivers/" directory. Once this one is done, it will be follwed by
"fs/*", "kernel/*", "net/*" and miscellaneous. The final set will remove
the unneeded check for ->procname == NULL.

Why?
By removing the sysctl sentinel elements we avoid kernel bloat as
ctl_table arrays get moved out of kernel/sysctl.c into their own
respective subsystems. This move was started long ago to avoid merge
conflicts; the sentinel removal bit came after Mathew Wilcox suggested
it to avoid bloating the kernel by one element as arrays moved out. This
patchset will reduce the overall build time size of the kernel and run
time memory bloat by about ~64 bytes per declared ctl_table array. I
have consolidated some links that shed light on the history of this
effort [2].

Testing:
* Ran sysctl selftests (./tools/testing/selftests/sysctl/sysctl.sh)
* Ran this through 0-day with no errors or warnings

Size saving after removing all sentinels:
  These are the bytes that we save after removing all the sentinels
  (this plus all the other chunks). I included them to get an idea of
  how much memory we are talking about.
    * bloat-o-meter:
        - The "yesall" configuration results save 9158 bytes
          https://lore.kernel.org/all/20230621091000.424843-1-j.granados@samsung.com/
        - The "tiny" config + CONFIG_SYSCTL save 1215 bytes
          https://lore.kernel.org/all/20230809105006.1198165-1-j.granados@samsung.com/
    * memory usage:
        In memory savings are measured to be 7296 bytes. (here is how to
        measure [3])

Size saving after this patchset:
    * bloat-o-meter
        - The "yesall" config saves 2432 bytes [4]
        - The "tiny" config saves 64 bytes [5]
    * memory usage:
        In this case there were no bytes saved because I do not have any
        of the drivers in the patch. To measure it comment the printk in
        `new_dir` and uncomment the if conditional in `new_links` [3].

Comments/feedback greatly appreciated

Best
Joel

[1]
We are able to remove a sentinel table without behavioral change by
introducing a table_size argument in the same place where procname is
checked for NULL. The idea is for it to keep stopping when it hits
->procname == NULL, while the sentinel is still present. And when the
sentinel is removed, it will stop on the table_size. You can go to 
(https://lore.kernel.org/all/20230809105006.1198165-1-j.granados@samsung.com/)
for more information.

[2]
Links Related to the ctl_table sentinel removal:
* Good summary from Luis sent with the "pull request" for the
  preparation patches.
  https://lore.kernel.org/all/ZO5Yx5JFogGi%2FcBo@bombadil.infradead.org/
* Another very good summary from Luis.
  https://lore.kernel.org/all/ZMFizKFkVxUFtSqa@bombadil.infradead.org/
* This is a patch set that replaces register_sysctl_table with register_sysctl
  https://lore.kernel.org/all/20230302204612.782387-1-mcgrof@kernel.org/
* Patch set to deprecate register_sysctl_paths()
  https://lore.kernel.org/all/20230302202826.776286-1-mcgrof@kernel.org/
* Here there is an explicit expectation for the removal of the sentinel element.
  https://lore.kernel.org/all/20230321130908.6972-1-frank.li@vivo.com
* The "ARRAY_SIZE" approach was mentioned (proposed?) in this thread
  https://lore.kernel.org/all/20220220060626.15885-1-tangmeng@uniontech.com

[3]
To measure the in memory savings apply this on top of this patchset.

"
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index c88854df0b62..e0073a627bac 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -976,6 +976,8 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
        table[0].procname = new_name;
        table[0].mode = S_IFDIR|S_IRUGO|S_IXUGO;
        init_header(&new->header, set->dir.header.root, set, node, table, 1);
+       // Counts additional sentinel used for each new dir.
+       printk("%ld sysctl saved mem kzalloc \n", sizeof(struct ctl_table));

        return new;
 }
@@ -1199,6 +1201,9 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_
                link_name += len;
                link++;
        }
+       // Counts additional sentinel used for each new registration
+       //if ((head->ctl_table + head->ctl_table_size)->procname)
+               printk("%ld sysctl saved mem kzalloc \n", sizeof(struct ctl_table));
        init_header(links, dir->header.root, dir->header.set, node, link_table,
                    head->ctl_table_size);
        links->nreg = nr_entries;
"
and then run the following bash script in the kernel:

accum=0
for n in $(dmesg | grep kzalloc | awk '{print $3}') ; do
    echo $n
    accum=$(calc "$accum + $n")
done
echo $accum

[4]
add/remove: 0/0 grow/shrink: 0/21 up/down: 0/-2432 (-2432)
Function                                     old     new   delta
xpc_sys_xpc_hb                               192     128     -64
xpc_sys_xpc                                  128      64     -64
vrf_table                                    128      64     -64
ucma_ctl_table                               128      64     -64
tty_table                                    192     128     -64
sg_sysctls                                   128      64     -64
scsi_table                                   128      64     -64
random_table                                 448     384     -64
raid_table                                   192     128     -64
oa_table                                     192     128     -64
mac_hid_files                                256     192     -64
iwcm_ctl_table                               128      64     -64
ipmi_table                                   128      64     -64
hv_ctl_table                                 128      64     -64
hpet_table                                   128      64     -64
firmware_config_table                        192     128     -64
cdrom_table                                  448     384     -64
balloon_table                                128      64     -64
parport_sysctl_template                      912     720    -192
parport_default_sysctl_table                 584     136    -448
parport_device_sysctl_template               776     136    -640
Total: Before=429940038, After=429937606, chg -0.00%

[5]
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-64 (-64)
Function                                     old     new   delta
random_table                                 448     384     -64
Total: Before=1885527, After=1885463, chg -0.00%

[6] https://lore.kernel.org/all/20230913-jag-sysctl_remove_empty_elem_arch-v2-0-d1bd13a29bae@samsung.com/

Signed-off-by: Joel Granados <j.granados@samsung.com>

---

---
Joel Granados (15):
      cdrom: Remove now superfluous sentinel element from ctl_table array
      hpet: Remove now superfluous sentinel element from ctl_table array
      xen: Remove now superfluous sentinel element from ctl_table array
      tty: Remove now superfluous sentinel element from ctl_table array
      scsi: Remove now superfluous sentinel element from ctl_table array
      parport: Remove the now superfluous sentinel element from ctl_table array
      macintosh: Remove the now superfluous sentinel element from ctl_table array
      infiniband: Remove the now superfluous sentinel element from ctl_table array
      char-misc: Remove the now superfluous sentinel element from ctl_table array
      vrf: Remove the now superfluous sentinel element from ctl_table array
      sgi-xp: Remove the now superfluous sentinel element from ctl_table array
      fw loader: Remove the now superfluous sentinel element from ctl_table array
      raid: Remove now superfluous sentinel element from ctl_table array
      hyper-v/azure: Remove now superfluous sentinel element from ctl_table array
      intel drm: Remove now superfluous sentinel element from ctl_table array

 drivers/base/firmware_loader/fallback_table.c |  3 +-
 drivers/cdrom/cdrom.c                         |  3 +-
 drivers/char/hpet.c                           |  3 +-
 drivers/char/ipmi/ipmi_poweroff.c             |  3 +-
 drivers/char/random.c                         |  3 +-
 drivers/gpu/drm/i915/i915_perf.c              |  3 +-
 drivers/hv/hv_common.c                        |  3 +-
 drivers/infiniband/core/iwcm.c                |  3 +-
 drivers/infiniband/core/ucma.c                |  3 +-
 drivers/macintosh/mac_hid.c                   |  3 +-
 drivers/md/md.c                               |  3 +-
 drivers/misc/sgi-xp/xpc_main.c                |  6 ++--
 drivers/net/vrf.c                             |  3 +-
 drivers/parport/procfs.c                      | 42 ++++++++++++---------------
 drivers/scsi/scsi_sysctl.c                    |  3 +-
 drivers/scsi/sg.c                             |  3 +-
 drivers/tty/tty_io.c                          |  3 +-
 drivers/xen/balloon.c                         |  3 +-
 18 files changed, 36 insertions(+), 60 deletions(-)
---
base-commit: 0e945134b680040b8613e962f586d91b6d40292d
change-id: 20230927-jag-sysctl_remove_empty_elem_drivers-f034962a0d8c

Best regards,
-- 
Joel Granados <j.granados@samsung.com>



             reply	other threads:[~2023-09-28 13:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28 13:21 Joel Granados via B4 Relay [this message]
     [not found] ` <20230928-jag-sysctl_remove_empty_elem_drive>
2023-09-28 13:21 ` [PATCH 01/15] cdrom: Remove now superfluous sentinel element from ctl_table array Joel Granados via B4 Relay
2023-09-28 13:36   ` Greg Kroah-Hartman
2023-09-29 12:17     ` Joel Granados
2023-09-30 16:52       ` Phillip Potter
2023-10-02  7:39         ` Joel Granados
2023-09-28 13:21 ` [PATCH 02/15] hpet: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 03/15] xen: " Joel Granados via B4 Relay
2023-09-28 13:33   ` Juergen Gross
2023-09-28 13:21 ` [PATCH 04/15] tty: " Joel Granados via B4 Relay
2023-10-02  8:17   ` Jiri Slaby
2023-10-02  8:47     ` Christophe Leroy
2023-10-02  9:02       ` Greg Kroah-Hartman
2023-09-28 13:21 ` [PATCH 05/15] scsi: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 06/15] parport: Remove the " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 07/15] macintosh: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 08/15] infiniband: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 09/15] char-misc: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 10/15] vrf: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 11/15] sgi-xp: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 12/15] fw loader: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 13/15] raid: Remove " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 14/15] hyper-v/azure: " Joel Granados via B4 Relay
2023-09-28 13:21 ` [PATCH 15/15] intel drm: " Joel Granados via B4 Relay
     [not found] ` <65157da7.5d0a0220.13b5e.9e95SMTPIN_ADDED_BROKEN@mx.google.com>
2023-09-28 15:20   ` [PATCH 13/15] raid: " Song Liu
     [not found] ` <65157da8.050a0220.fb263.fdb1SMTPIN_ADDED_BROKEN@mx.google.com>
2023-09-28 15:26   ` [PATCH 14/15] hyper-v/azure: " Wei Liu
2023-09-29 12:15     ` Joel Granados
2023-09-29 14:03     ` Joel Granados
2023-09-28 16:31 ` [PATCH 00/15] sysctl: Remove sentinel elements from drivers Christophe Leroy
2023-10-02  8:47   ` Joel Granados
2023-10-02  9:02     ` Christophe Leroy
     [not found] ` <=?utf-8?q?=3C20230928-jag-sysctl=5Fremove=5Fempty=5Felem=5Fdrive?=>
2023-09-28 17:51   ` [PATCH 11/15] sgi-xp: Remove the now superfluous sentinel element from ctl_table array Steve Wahl
2023-09-29 12:14     ` Joel Granados

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230928-jag-sysctl_remove_empty_elem_drivers-v1-0-e59120fca9f9@samsung.com \
    --to=devnull+j.granados.samsung.com@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=airlied@gmail.com \
    --cc=arnd@arndb.de \
    --cc=clemens@ladisch.de \
    --cc=daniel@ffwll.ch \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=dgilbert@interlog.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=j.granados@samsung.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=jejb@linux.ibm.com \
    --cc=jgg@ziepe.ca \
    --cc=jgross@suse.com \
    --cc=jirislaby@kernel.org \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=josh@joshtriplett.org \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=kys@microsoft.com \
    --cc=leon@kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=martin.petersen@oracle.com \
    --cc=mcgrof@kernel.org \
    --cc=minyard@acm.org \
    --cc=netdev@vger.kernel.org \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=openipmi-developer@lists.sourceforge.net \
    --cc=pabeni@redhat.com \
    --cc=phil@philpotter.co.uk \
    --cc=rafael@kernel.org \
    --cc=robinmholt@gmail.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=russell.h.weight@intel.com \
    --cc=song@kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=steve.wahl@hpe.com \
    --cc=sudipm.mukherjee@gmail.com \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=tytso@mit.edu \
    --cc=wei.liu@kernel.org \
    --cc=willy@infradead.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).