From: Joel Granados <joel.granados@kernel.org>
To: Kees Cook <kees@kernel.org>, Alexey Gladkov <legion@kernel.org>,
David Laight <david.laight.linux@gmail.com>,
Wen Yang <wen.yang@linux.dev>
Cc: Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
netdev@vger.kernel.org, Joel Granados <joel.granados@kernel.org>
Subject: [PATCH RFC 0/9] sysctl: Replace ARRAY kmemdup with overlay mechanism for NS registration
Date: Thu, 26 Nov 2026 12:47:40 +0100 [thread overview]
Message-ID: <20261126-lklm-sysctl-ctx-flatarray-v1-0-d7fc9cc9b03e@kernel.org> (raw)
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>
next reply other threads:[~2026-11-26 11:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 11:47 Joel Granados [this message]
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
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=20261126-lklm-sysctl-ctx-flatarray-v1-0-d7fc9cc9b03e@kernel.org \
--to=joel.granados@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=legion@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=wen.yang@linux.dev \
/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
all inboxes | Powered by JetHome®