From: Meng Tang <tangmeng@uniontech.com>
To: mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com
Cc: guoren@kernel.org, nickhu@andestech.com, green.hu@gmail.com,
deanbo422@gmail.com, ebiggers@kernel.org, tytso@mit.edu,
wad@chromium.org, john.johansen@canonical.com, jmorris@namei.org,
serge@hallyn.com, linux-csky@vger.kernel.org,
linux-fscrypt@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Meng Tang <tangmeng@uniontech.com>
Subject: [PATCH v3 1/2] fs/proc: Optimize arrays defined by struct ctl_path
Date: Thu, 24 Feb 2022 21:32:16 +0800 [thread overview]
Message-ID: <20220224133217.1755-1-tangmeng@uniontech.com> (raw)
Previously, arrays defined by struct ctl_path is terminated
with an empty one. When we actually only register one ctl_path,
we've gone from 8 bytes to 16 bytes.
So, I use ARRAY_SIZE() as a boundary condition to optimize it.
Since the original __register_sysctl_paths is only used in
fs/proc/proc_sysctl.c, in order to not change the usage of
register_sysctl_paths, delete __register_sysctl_paths from
include/linux/sysctl.h, change it to __register_sysctl_paths_init
in fs/proc/proc_sysctl.c, and modify it with static.
The register_sysctl_paths becomes __register_sysctl_paths,
and the macro definition is used in include/linux/sysctl.h
to expand register_sysctl_paths(path, table) to
__register_sysctl_paths(path, ARRAY_SIZE(path), table).
Signed-off-by: Meng Tang <tangmeng@uniontech.com>
---
fs/proc/proc_sysctl.c | 22 +++++++++++++---------
include/linux/sysctl.h | 9 ++++-----
2 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 9ecd5c87e8dd..721a8bec63d6 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -1589,9 +1589,10 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
}
/**
- * __register_sysctl_paths - register a sysctl table hierarchy
+ * __register_sysctl_paths_init - register a sysctl table hierarchy
* @set: Sysctl tree to register on
* @path: The path to the directory the sysctl table is in.
+ * @ctl_path_num: The numbers(ARRAY_SIZE(path)) of ctl_path
* @table: the top-level table structure
*
* Register a sysctl table hierarchy. @table should be a filled in ctl_table
@@ -1599,22 +1600,23 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
*
* See __register_sysctl_table for more details.
*/
-struct ctl_table_header *__register_sysctl_paths(
+static struct ctl_table_header *__register_sysctl_paths_init(
struct ctl_table_set *set,
- const struct ctl_path *path, struct ctl_table *table)
+ const struct ctl_path *path, int ctl_path_num, struct ctl_table *table)
{
struct ctl_table *ctl_table_arg = table;
int nr_subheaders = count_subheaders(table);
struct ctl_table_header *header = NULL, **subheaders, **subheader;
const struct ctl_path *component;
char *new_path, *pos;
+ int i;
pos = new_path = kmalloc(PATH_MAX, GFP_KERNEL);
if (!new_path)
return NULL;
pos[0] = '\0';
- for (component = path; component->procname; component++) {
+ for (component = path, i = 0; component->procname && i < ctl_path_num; component++, i++) {
pos = append_path(new_path, pos, component->procname);
if (!pos)
goto out;
@@ -1663,20 +1665,22 @@ struct ctl_table_header *__register_sysctl_paths(
/**
* register_sysctl_paths - register a sysctl table hierarchy
* @path: The path to the directory the sysctl table is in.
+ * @ctl_path_num: The numbers(ARRAY_SIZE(path)) of ctl_path
* @table: the top-level table structure
*
* Register a sysctl table hierarchy. @table should be a filled in ctl_table
* array. A completely 0 filled entry terminates the table.
*
- * See __register_sysctl_paths for more details.
+ * See __register_sysctl_paths_init for more details.
*/
-struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
+struct ctl_table_header *__register_sysctl_paths(const struct ctl_path *path,
+ int ctl_path_num,
struct ctl_table *table)
{
- return __register_sysctl_paths(&sysctl_table_root.default_set,
- path, table);
+ return __register_sysctl_paths_init(&sysctl_table_root.default_set,
+ path, ctl_path_num, table);
}
-EXPORT_SYMBOL(register_sysctl_paths);
+EXPORT_SYMBOL(__register_sysctl_paths);
/**
* register_sysctl_table - register a sysctl table hierarchy
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 889c995d8a08..37958aeecfb5 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -219,13 +219,12 @@ extern void retire_sysctl_set(struct ctl_table_set *set);
struct ctl_table_header *__register_sysctl_table(
struct ctl_table_set *set,
const char *path, struct ctl_table *table);
-struct ctl_table_header *__register_sysctl_paths(
- struct ctl_table_set *set,
- const struct ctl_path *path, struct ctl_table *table);
struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
-struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
- struct ctl_table *table);
+#define register_sysctl_paths(path, table) \
+ __register_sysctl_paths(path, ARRAY_SIZE(path), table)
+extern struct ctl_table_header *__register_sysctl_paths(const struct ctl_path *path,
+ int ctl_path_num, struct ctl_table *table);
void unregister_sysctl_table(struct ctl_table_header * table);
--
2.20.1
next reply other threads:[~2022-02-24 13:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-24 13:32 Meng Tang [this message]
2022-02-24 13:32 ` [PATCH v3 2/2] fs/proc: Optimize arrays defined by struct ctl_path Meng Tang
2022-02-26 20:13 ` Luis Chamberlain
2022-02-26 20:57 ` [PATCH v3 1/2] " Luis Chamberlain
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=20220224133217.1755-1-tangmeng@uniontech.com \
--to=tangmeng@uniontech.com \
--cc=deanbo422@gmail.com \
--cc=ebiggers@kernel.org \
--cc=green.hu@gmail.com \
--cc=guoren@kernel.org \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=keescook@chromium.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=nickhu@andestech.com \
--cc=serge@hallyn.com \
--cc=tytso@mit.edu \
--cc=wad@chromium.org \
--cc=yzaikin@google.com \
/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).