mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC 0/9] sysctl: Replace ARRAY kmemdup with overlay mechanism for NS registration
@ 2026-11-26 11:47 Joel Granados
  2026-11-26 11:47 ` [PATCH RFC 1/9] sysctl: Add struct ctl_table_tmpl as a distinct template type Joel Granados
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Joel Granados @ 2026-11-26 11:47 UTC (permalink / raw)
  To: Kees Cook, Alexey Gladkov, David Laight, Wen Yang
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Linus Torvalds, linux-kernel, linux-fsdevel, netdev,
	Joel Granados

This is meant to replace the sysctl array duplication mechanism used by
callers that register sysctls for individual namespaces.

Instead of duplicating a sysctl array and keeping it in memory for the
life of a namespace, use it (the array) as a template and keep only the
necessary delta in a sysctl_context struct inside ctl_table_header. The
sysctl_context can then be used to overlay the ctl_table just before
calling its proc_handler.

The last 5 commits are just examples of how the conversions at the call
sites would look. The idea is to upstream the core first and then merge
each individual calling site through its own subsystem tree.

Motivation
==========

* Reducing memory footprint for namespace registrations
  On a 64 bit ARCH, memory consumption is reduced by at least 53% (this
  is a back-of-envelope approximation): from (56 * ARRAY_SIZE *
  count(namespaces)) bytes to (26 * ARRAY_SIZE * count(namespaces))
  bytes [2]; we save more, if a subset of the context is used.

* ctl_table const qualification
  Namespace ctl_table arrays that are currently modified during
  registration can be const qualified (moved to .rodata) as they no
  longer require pre-registration changes.

What was done
=============

* struct sysctl_context:
  Embedded in struct ctl_table_header, holds flat arrays indexed by
  entry position: void **data, **extra1, **extra2; umode_t
  *mode. They point to what should be overlaid.

* overlay flags:
  struct ctl_table gets a u8 flags member in an existing hole (no size
  change) with SYSCTL_OVERLAY_{DATA,EXTRA1,EXTRA2,MODE}. They control
  what gets overlaid

* sysctl template overlay:
  Add a template registration function to initialize the sysctl
  context. Overlay data from context before calling any proc_handler.
  Template registration can only be done with a ctl_table_tmpl type.

Comment on void*
================
The sysctl_context uses 3 void** because it reflects struct ctl_table.
Yes, we should get rid of these untyped pointers. No, this is not the
series that will remove them. Yes, there are already proposals out there
that are working towards this [1]. Yes, the plan is for sysctl_context's
void pointers to change once struct ctl_table's do. I thought that
resolving the pointers had to go first, but I think these two efforts
can coexist if handled separately.

Recent approaches
=================
* Alexey Gladkov's "sysctl_field" descriptors:
  cover.1787770053.git.legion@kernel.org, cover.1790439358.git.legion@kernel.org
  Which build a temp ctl_table from typed accessors before calling the
  proc_handler

* My own header-context RFC:
  20260924-lklm-sysctl-headerctx-template-v1-0-b25e51c66ba7@kernel.org
  computed .data as base + delta in the core.

This series takes the idea of building a temp ctl_table entry before
calling proc_handler, which is a commonality in these two, and drops
everything else: no network types in sysctl core, no namespace specific
enum in sysctl core, no delta arithmetic.

To and Cc
=========
I always find it challenging to know who wants to receive these e-mails.
I added you here because you have recently commented on the issue or
are in the maintainer path. Let me know if you don't want to be included
in the future.

Any comments are greatly appreciated

Best

Based on v7.4-rc2

[1] https://lore.kernel.org/all/cover.1794844686.git.wen.yang@linux.dev
    https://lore.kernel.org/all/cover.1793204511.git.wen.yang@linux.dev
[2] sizeof(struct ctl_table) -> 56 bytes
    3*sizeof(void*) + sizeof(umode_t) -> 26 bytes

Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
Joel Granados (9):
      sysctl: Add struct ctl_table_tmpl as a distinct template type
      sysctl: Add flags to struct ctl_table
      sysctl: Add overlay mechanism for flagged ctl_table members
      sysctl: Add sysctl template registration
      net: sysctl: Add sysctl registration to networking
      ipv4: Register ipv4_net_table as a template
      ipc: Register ipc_sysctls as a template
      ipc: Register mq_sysctls as a template
      ucount: Register user_table as a template

 fs/proc/proc_sysctl.c       | 362 ++++++++++++++++++++++++++++++++++++++------
 include/linux/sysctl.h      |  66 ++++++++
 include/net/net_namespace.h |  14 ++
 ipc/ipc_sysctl.c            |  24 ++-
 ipc/mq_sysctl.c             |  20 +--
 kernel/ucount.c             |  14 +-
 net/ipv4/sysctl_net_ipv4.c  | 163 +++++++++++++++++---
 net/sysctl_net.c            |  25 +++
 8 files changed, 594 insertions(+), 94 deletions(-)
---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261123-lklm-sysctl-ctx-flatarray-c4b4ea101d93

Best regards,
-- 
Joel Granados <joel.granados@kernel.org>



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

end of thread, other threads:[~2026-11-26 11:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 11:47 [PATCH RFC 0/9] sysctl: Replace ARRAY kmemdup with overlay mechanism for NS registration Joel Granados
2026-11-26 11:47 ` [PATCH RFC 1/9] sysctl: Add struct ctl_table_tmpl as a distinct template type Joel Granados
2026-11-26 11:47 ` [PATCH RFC 2/9] sysctl: Add flags to struct ctl_table Joel Granados
2026-11-26 11:47 ` [PATCH RFC 3/9] sysctl: Add overlay mechanism for flagged ctl_table members Joel Granados
2026-11-26 11:47 ` [PATCH RFC 4/9] sysctl: Add sysctl template registration Joel Granados
2026-11-26 11:47 ` [PATCH RFC 5/9] net: sysctl: Add sysctl registration to networking Joel Granados
2026-11-26 11:47 ` [PATCH RFC 6/9] ipv4: Register ipv4_net_table as a template Joel Granados
2026-11-26 11:47 ` [PATCH RFC 7/9] ipc: Register ipc_sysctls " Joel Granados
2026-11-26 11:47 ` [PATCH RFC 8/9] ipc: Register mq_sysctls " Joel Granados
2026-11-26 11:47 ` [PATCH RFC 9/9] ucount: Register user_table " Joel Granados

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®