From: Mateusz Guzik <mjguzik@gmail.com>
To: brauner@kernel.org
Cc: viro@zeniv.linux.org.uk, jack@suse.cz,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
adobriyan@gmail.com
Subject: [PATCH v3 1/3] proc: allow to mark /proc files permanent outside of fs/proc/
Date: Sun, 26 Apr 2026 00:08:42 +0200 [thread overview]
Message-ID: <20260425220844.1763933-2-mjguzik@gmail.com> (raw)
In-Reply-To: <20260425220844.1763933-1-mjguzik@gmail.com>
From: Alexey Dobriyan <adobriyan@gmail.com>
Add proc_make_permanent() function to mark PDE as permanent to speed up
open/read/close (one alloc/free and lock/unlock less).
Enable it for built-in code and for compiled-in modules.
This function becomes nop magically in modular code.
Note, note, note!
If built-in code creates and deletes PDEs dynamically (not in init
hook), then proc_make_permanent() must not be used.
It is intended for simple code:
static int __init xxx_module_init(void)
{
g_pde = proc_create_single();
proc_make_permanent(g_pde);
return 0;
}
static void __exit xxx_module_exit(void)
{
remove_proc_entry(g_pde);
}
If module is built-in then exit hook never executed and PDE is
permanent so it is OK to mark it as such.
If module is module then rmmod will yank PDE, but proc_make_permanent()
is nop and core /proc code will do everything right.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
fs/proc/generic.c | 12 ++++++++++++
fs/proc/internal.h | 3 +++
include/linux/proc_fs.h | 10 ++++++++++
3 files changed, 25 insertions(+)
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 3063080f3bb2..497561ee3848 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -845,3 +845,15 @@ ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size,
kfree(buf);
return ret == 0 ? size : ret;
}
+
+/*
+ * Not exported to modules:
+ * modules' /proc files aren't permanent because modules aren't permanent.
+ */
+void impl_proc_make_permanent(struct proc_dir_entry *pde);
+void impl_proc_make_permanent(struct proc_dir_entry *pde)
+{
+ if (pde) {
+ pde_make_permanent(pde);
+ }
+}
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 64dc44832808..1edbabbdbc5d 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -79,8 +79,11 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde)
return pde->flags & PROC_ENTRY_PERMANENT;
}
+/* This is for builtin code, not even for modules which are compiled in. */
static inline void pde_make_permanent(struct proc_dir_entry *pde)
{
+ /* Ensure magic flag does something. */
+ static_assert(PROC_ENTRY_PERMANENT != 0);
pde->flags |= PROC_ENTRY_PERMANENT;
}
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 19d1c5e5f335..dceccd27a234 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -248,4 +248,14 @@ static inline struct pid_namespace *proc_pid_ns(struct super_block *sb)
bool proc_ns_file(const struct file *file);
+static inline void proc_make_permanent(struct proc_dir_entry *pde)
+{
+ /* Don't give matches to modules. */
+#if defined CONFIG_PROC_FS && !defined MODULE
+ /* This mess is created by defining "struct proc_dir_entry" elsewhere. */
+ void impl_proc_make_permanent(struct proc_dir_entry *pde);
+ impl_proc_make_permanent(pde);
+#endif
+}
+
#endif /* _LINUX_PROC_FS_H */
--
2.48.1
next prev parent reply other threads:[~2026-04-25 22:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-25 22:08 [PATCH v3 0/3] revamp fs/filesystems.c Mateusz Guzik
2026-04-25 22:08 ` Mateusz Guzik [this message]
2026-04-25 22:08 ` [PATCH v3 2/3] fs: RCU-ify filesystems list Mateusz Guzik
2026-04-25 22:08 ` [PATCH v3 3/3] fs: cache the string generated by reading /proc/filesystems Mateusz Guzik
2026-04-27 14:53 ` [PATCH v3 0/3] revamp fs/filesystems.c Christian Brauner
2026-04-28 6:36 ` Why does GNU sed abuse /proc/filesystems? " Cedric Blancher
2026-04-28 8:31 ` Mateusz Guzik
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=20260425220844.1763933-2-mjguzik@gmail.com \
--to=mjguzik@gmail.com \
--cc=adobriyan@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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