linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoming Ni <nixiaoming@huawei.com>
To: Meng Tang <tangmeng@uniontech.com>, <mcgrof@kernel.org>,
	<keescook@chromium.org>, <yzaikin@google.com>,
	<ebiederm@xmission.com>, <willy@infradead.org>
Cc: <nizhen@uniontech.com>, <zhanglianjie@uniontech.com>,
	<sujiaxun@uniontech.com>, <linux-kernel@vger.kernel.org>,
	<linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH v4 1/2] fs/proc: optimize exactly register one ctl_table
Date: Fri, 4 Mar 2022 09:21:12 +0800	[thread overview]
Message-ID: <624f92f0-c2a1-c7d9-a4ed-6d72c48d3ab3@huawei.com> (raw)
In-Reply-To: <20220303070847.28684-1-tangmeng@uniontech.com>

On 2022/3/3 15:08, Meng Tang wrote:
> Sysctls are being moved out of kernel/sysctl.c and out to
> their own respective subsystems / users to help with easier
> maintance and avoid merge conflicts. But when we move just
> one entry and to its own new file the last entry for this
> new file must be empty, so we are essentialy bloating the
> kernel one extra empty entry per each newly moved sysctl.
> 
> To help with this, this adds support for registering just
> one ctl_table, therefore not bloating the kernel when we
> move a single ctl_table to its own file.
> 
> Since the process of registering just one single table is the
> same as that of registering an array table, so the code is
> similar to registering an array table. The difference between
> registering just one table and registering an array table is
> that we no longer traversal through pointers when registering
> a single table. These lead to that we have to add a complete
> implementation process for register just one ctl_table, so we
> have to add so much code.
> 
> Suggested-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Meng Tang <tangmeng@uniontech.com>
> ---
>   fs/proc/proc_sysctl.c  | 159 +++++++++++++++++++++++++++++------------
>   include/linux/sysctl.h |   9 ++-
>   2 files changed, 121 insertions(+), 47 deletions(-)
> 
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 6c87c99f0856..e06d2094457a 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -19,6 +19,8 @@
>   #include <linux/kmemleak.h>
>   #include "internal.h"
>   
> +#define REGISTER_SINGLE_ONE (register_single_one ? true : false)
> +
>   static const struct dentry_operations proc_sys_dentry_operations;
>   static const struct file_operations proc_sys_file_operations;
>   static const struct inode_operations proc_sys_inode_operations;
> @@ -100,8 +102,8 @@ static DEFINE_SPINLOCK(sysctl_lock);
>   static void drop_sysctl_table(struct ctl_table_header *header);
>   static int sysctl_follow_link(struct ctl_table_header **phead,
>   	struct ctl_table **pentry);
> -static int insert_links(struct ctl_table_header *head);
> -static void put_links(struct ctl_table_header *header);
> +static int insert_links(struct ctl_table_header *head, bool register_single_one);
> +static void put_links(struct ctl_table_header *header, bool register_single_one);
>   
>   static void sysctl_print_dir(struct ctl_dir *dir)
>   {
> @@ -200,7 +202,7 @@ static void erase_entry(struct ctl_table_header *head, struct ctl_table *entry)
>   
>   static void init_header(struct ctl_table_header *head,
>   	struct ctl_table_root *root, struct ctl_table_set *set,
> -	struct ctl_node *node, struct ctl_table *table)
> +	struct ctl_node *node, struct ctl_table *table, bool register_single_one)
>   {
>   	head->ctl_table = table;
>   	head->ctl_table_arg = table;
> @@ -215,19 +217,26 @@ static void init_header(struct ctl_table_header *head,
>   	INIT_HLIST_HEAD(&head->inodes);
>   	if (node) {
>   		struct ctl_table *entry;
> -		for (entry = table; entry->procname; entry++, node++)
> +		for (entry = table; entry->procname; entry++, node++) {
>   			node->header = head;
> +			if (register_single_one)
The scalability is reduced.
If you add a file interface in the future, you need to make at least two 
code changes.

Instead of having each consumer keep the current table size in mind, you 
can obtain the table size by ARRAY_SIZE() in the API interface.

For example,

+ #define register_sysctl_init(path, table) 
__register_sysctl_init(path, table, ARRAY_SIZE(table))
...
-		for (entry = table; entry->procname; entry++, node++)
+		for (entry = table; entry->procname && num > 0; entry++, node++, num--) {


Xiaoming Ni
thanks

  parent reply	other threads:[~2022-03-04  1:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03  7:08 [PATCH v4 1/2] fs/proc: optimize exactly register one ctl_table Meng Tang
2022-03-03  7:08 ` [PATCH v4 2/2] fs/proc: sysctl: optimize register single " Meng Tang
2022-03-04  1:21 ` Xiaoming Ni [this message]
2022-03-12  6:14   ` [PATCH v4 1/2] fs/proc: optimize exactly register " Davidlohr Bueso
2022-03-12  3:24 ` Al Viro

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=624f92f0-c2a1-c7d9-a4ed-6d72c48d3ab3@huawei.com \
    --to=nixiaoming@huawei.com \
    --cc=ebiederm@xmission.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=nizhen@uniontech.com \
    --cc=sujiaxun@uniontech.com \
    --cc=tangmeng@uniontech.com \
    --cc=willy@infradead.org \
    --cc=yzaikin@google.com \
    --cc=zhanglianjie@uniontech.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).