From: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
netdev@vger.kernel.org,
Damien Millescamps <damien.millescamps@6wind.com>
Subject: Re: [PATCH 24/29] sysctl: Replace root_list with links between sysctl_table_sets.
Date: Mon, 30 Jan 2012 02:01:48 +0200 [thread overview]
Message-ID: <CAPLs8y8YV0MiNhR0SnviBHPQb-oMj+_DLvRpJN89Yrbyjsf2xg@mail.gmail.com> (raw)
In-Reply-To: <1327639925-12920-24-git-send-email-ebiederm@xmission.com>
Very nice way to handle netns specific files with links between sets!
You did a much better job than I did at dealing with them.
It took me a while to understand how the code works. I'll try to write
something for Documentation/ because the inner workings are a bit
intertwined.
A few comments bellow.
On Fri, Jan 27, 2012 at 6:52 AM, Eric W. Biederman
<ebiederm@xmission.com> wrote:
> Piecing together directories by looking first in one directory
> tree, than in another directory tree and finally in a third
than -> then
> directory tree makes it hard to verify that some directory
> entries are not multiply defined and makes it hard to create
> efficient implementations the sysctl filesystem.
>
> Replace the sysctl wide list of roots with autogenerated
> links from the core sysctl directory tree to the other
> sysctl directory trees.
>
> This simplifies sysctl directory reading and lookups as now
> only entries in a single sysctl directory tree need to be
> considered.
>
> Benchmark before:
> make-dummies 0 999 -> 0.44s
> rmmod dummy -> 0.065s
> make-dummies 0 9999 -> 1m36s
> rmmod dummy -> 0.4s
>
> Benchmark after:
> make-dummies 0 999 -> 0.63s
> rmmod dummy -> 0.12s
> make-dummies 0 9999 -> 2m35s
> rmmod dummy -> 18s
>
> The slowdown is caused by the lookups used in insert_headers
insert_headers -> insert_header
> and put_links to see if we need to add links or remove links.
> void register_sysctl_root(struct ctl_table_root *root)
> {
> - spin_lock(&sysctl_lock);
> - list_add_tail(&root->root_list, &sysctl_table_root.root_list);
> - spin_unlock(&sysctl_lock);
> }
This function is empty. Can be deleted (there are two callers in
net/sysctl_net.c.
> @@ -400,6 +373,7 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
> struct inode *inode;
> struct dentry *err = ERR_PTR(-ENOENT);
> struct ctl_dir *ctl_dir;
> + int ret;
>
> if (IS_ERR(head))
> return ERR_CAST(head);
> @@ -410,6 +384,11 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
> if (!p)
> goto out;
>
"sysctl_follow_link" implies that it will follow the link. I would
pull out the check whether the header is a link or not. This wouldn't
save much (a function call), but it would make the code easier to
read:
/* Get out quickly if not a link */
if (S_ISLNK(p->mode)) {
ret = sysctl_follow_link(&h, &p, current->nsproxy);
err = ERR_PTR(ret);
if (ret)
goto out;
}
> + ret = sysctl_follow_link(&h, &p, current->nsproxy);
> + err = ERR_PTR(ret);
> + if (ret)
> + goto out;
> +
> err = ERR_PTR(-ENOMEM);
> inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
> if (h)
> @@ -547,6 +526,25 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
> return !!filldir(dirent, qname.name, qname.len, filp->f_pos, ino, type);
> }
>
> +static int proc_sys_link_fill_cache(struct file *filp, void *dirent,
> + filldir_t filldir,
> + struct ctl_table_header *head,
> + struct ctl_table *table)
> +{
> + int err, ret = 0;
> + head = sysctl_head_grab(head);
> +
> + /* It is not an error if we can not follow the link ignore it */
> + err = sysctl_follow_link(&head, &table, current->nsproxy);
similar
> + if (err)
> + goto out;
> +
> + ret = proc_sys_fill_cache(filp, dirent, filldir, head, table);
> +out:
> + sysctl_head_finish(head);
> + return ret;
> +}
> +
> -static struct ctl_dir *get_subdir(struct ctl_table_set *set,
> - struct ctl_dir *dir, const char *name, int namelen)
> +static struct ctl_dir *get_subdir(struct ctl_dir *dir,
> + const char *name, int namelen)
> {
> + struct ctl_table_set *set = dir->header.set;
> struct ctl_dir *subdir, *new = NULL;
>
> spin_lock(&sysctl_lock);
> - subdir = find_subdir(dir->header.set, dir, name, namelen);
> - if (!IS_ERR(subdir))
> - goto found;
> - if ((PTR_ERR(subdir) == -ENOENT) && set != dir->header.set)
> - subdir = find_subdir(set, dir, name, namelen);
> + subdir = find_subdir(dir, name, namelen);
> if (!IS_ERR(subdir))
> goto found;
> if (PTR_ERR(subdir) != -ENOENT)
> @@ -817,13 +815,14 @@ static struct ctl_dir *get_subdir(struct ctl_table_set *set,
> if (!new)
> goto failed;
>
> - subdir = find_subdir(set, dir, name, namelen);
> + subdir = find_subdir(dir, name, namelen);
> if (!IS_ERR(subdir))
> goto found;
> if (PTR_ERR(subdir) != -ENOENT)
> goto failed;
I think you're returning the wrong error here. If we got to this point
then subdir == ERR_PTR(-ENOENT).
We want to create a new dir here even if one doesn't exist.
So if we have an error in insert_header() we don't return that error,
but ENOENT.
>
> - insert_header(dir, &new->header);
> + if (insert_header(dir, &new->header))
> + goto failed;
> subdir = new;
Something like this would fix it:
if (subdir = insert_header(dir, &new->header))
> found:
> subdir->header.nreg++;
> @@ -841,6 +840,57 @@ failed:
> return subdir;
> }
>
--
.
..: Lucian
next prev parent reply other threads:[~2012-01-30 0:02 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-27 4:45 [Review][PATCH][0/29] sysctl rewrite for speed and clarity Eric W. Biederman
2012-01-27 4:49 ` [PATCH 01/29] sysctl: remove impossible condition check Eric W. Biederman
2012-01-27 4:49 ` [PATCH 02/29] sysctl: Consolidate !CONFIG_SYSCTL handling Eric W. Biederman
2012-01-27 4:49 ` [PATCH 03/29] sysctl: Register the base sysctl table like any other sysctl table Eric W. Biederman
2012-01-27 4:49 ` [PATCH 04/29] sysctl: Move the implementation into fs/proc/proc_sysctl.c Eric W. Biederman
2012-01-27 4:49 ` [PATCH 05/29] sysctl: Make the directories have nlink == 1 Eric W. Biederman
2012-01-27 4:49 ` [PATCH 06/29] sysctl: Implement retire_sysctl_set Eric W. Biederman
2012-01-27 4:49 ` [PATCH 07/29] sysctl: Remove the unnecessary sysctl_set parent concept Eric W. Biederman
2012-01-27 4:49 ` [PATCH 08/29] sysctl: Create local copies of directory names used in paths Eric W. Biederman
2012-01-27 4:49 ` [PATCH 09/29] sysctl: Add support for register sysctl tables with a normal cstring path Eric W. Biederman
2012-01-27 4:49 ` [PATCH 10/29] sysctl: Add ctl_table chains into cstring paths Eric W. Biederman
2012-01-27 4:49 ` [PATCH 11/29] sysctl: register only tables of sysctl files Eric W. Biederman
2012-01-27 4:49 ` [PATCH 12/29] sysctl: Improve the sysctl sanity checks Eric W. Biederman
2012-01-27 4:49 ` [PATCH 13/29] sysctl: Remove the now unused ctl_table parent field Eric W. Biederman
2012-01-27 4:49 ` [PATCH 14/29] sysctl: A more obvious version of grab_header Eric W. Biederman
2012-01-27 4:49 ` [PATCH 15/29] sysctl: Initial support for auto-unregistering sysctl tables Eric W. Biederman
2012-01-27 4:49 ` [PATCH 16/29] sysctl: Factor out init_header from __register_sysctl_paths Eric W. Biederman
2012-01-27 4:49 ` [PATCH 17/29] sysctl: Factor out insert_header and erase_header Eric W. Biederman
2012-01-27 4:49 ` [PATCH 18/29] sysctl: Normalize the root_table data structure Eric W. Biederman
2012-01-27 4:50 ` [PATCH 19/29] sysctl: Rewrite proc_sys_lookup introducing find_entry and lookup_entry Eric W. Biederman
2012-01-27 4:50 ` [PATCH 20/29] sysctl: Rewrite proc_sys_readdir in terms of first_entry and next_entry Eric W. Biederman
2012-01-27 4:50 ` [PATCH 21/29] sysctl: Add a root pointer to ctl_table_set Eric W. Biederman
2012-01-27 4:50 ` [PATCH 22/29] sysctl: Stop requiring explicit management of sysctl directories Eric W. Biederman
2012-01-27 4:50 ` [PATCH 23/29] sysctl: Add sysctl_print_dir and use it in get_subdir Eric W. Biederman
2012-01-27 4:50 ` [PATCH 24/29] sysctl: Replace root_list with links between sysctl_table_sets Eric W. Biederman
2012-01-27 4:50 ` [PATCH 25/29] sysctl: Modify __register_sysctl_paths to take a set instead of a root and an nsproxy Eric W. Biederman
2012-01-27 4:50 ` [PATCH 26/29] sysctl: Move sysctl_check_dups into insert_header Eric W. Biederman
2012-01-27 4:50 ` [PATCH 27/29] sysctl: Make the header lists per directory Eric W. Biederman
2012-01-27 4:50 ` [PATCH 28/29] sysctl: Index sysctl directories with rbtrees Eric W. Biederman
2012-01-27 4:50 ` [PATCH 29/29] sysctl: Add register_sysctl for normal sysctl users Eric W. Biederman
2012-01-27 4:51 ` [PATCH 01/29] sysctl: remove impossible condition check Eric W. Biederman
2012-01-27 4:51 ` [PATCH 02/29] sysctl: Consolidate !CONFIG_SYSCTL handling Eric W. Biederman
2012-01-27 4:51 ` [PATCH 03/29] sysctl: Register the base sysctl table like any other sysctl table Eric W. Biederman
2012-01-27 4:51 ` [PATCH 04/29] sysctl: Move the implementation into fs/proc/proc_sysctl.c Eric W. Biederman
2012-01-27 4:51 ` [PATCH 05/29] sysctl: Make the directories have nlink == 1 Eric W. Biederman
2012-01-27 4:51 ` [PATCH 06/29] sysctl: Implement retire_sysctl_set Eric W. Biederman
2012-01-27 4:51 ` [PATCH 07/29] sysctl: Remove the unnecessary sysctl_set parent concept Eric W. Biederman
2012-01-27 4:51 ` [PATCH 08/29] sysctl: Create local copies of directory names used in paths Eric W. Biederman
2012-01-27 4:51 ` [PATCH 09/29] sysctl: Add support for register sysctl tables with a normal cstring path Eric W. Biederman
2012-01-27 4:51 ` [PATCH 10/29] sysctl: Add ctl_table chains into cstring paths Eric W. Biederman
2012-01-27 4:51 ` [PATCH 11/29] sysctl: register only tables of sysctl files Eric W. Biederman
2012-01-27 4:51 ` [PATCH 12/29] sysctl: Improve the sysctl sanity checks Eric W. Biederman
2012-01-27 4:51 ` [PATCH 13/29] sysctl: Remove the now unused ctl_table parent field Eric W. Biederman
2012-01-27 4:51 ` [PATCH 14/29] sysctl: A more obvious version of grab_header Eric W. Biederman
2012-01-27 4:51 ` [PATCH 15/29] sysctl: Initial support for auto-unregistering sysctl tables Eric W. Biederman
2012-01-27 4:51 ` [PATCH 16/29] sysctl: Factor out init_header from __register_sysctl_paths Eric W. Biederman
2012-01-27 4:51 ` [PATCH 17/29] sysctl: Factor out insert_header and erase_header Eric W. Biederman
2012-01-27 4:51 ` [PATCH 18/29] sysctl: Normalize the root_table data structure Eric W. Biederman
2012-01-29 17:36 ` Lucian Adrian Grijincu
2012-01-30 0:22 ` Eric W. Biederman
2012-01-27 4:51 ` [PATCH 19/29] sysctl: Rewrite proc_sys_lookup introducing find_entry and lookup_entry Eric W. Biederman
2012-01-29 15:49 ` Lucian Adrian Grijincu
2012-01-27 4:51 ` [PATCH 20/29] sysctl: Rewrite proc_sys_readdir in terms of first_entry and next_entry Eric W. Biederman
2012-01-27 4:51 ` [PATCH 21/29] sysctl: Add a root pointer to ctl_table_set Eric W. Biederman
2012-01-29 17:19 ` Lucian Adrian Grijincu
2012-01-27 4:51 ` [PATCH 22/29] sysctl: Stop requiring explicit management of sysctl directories Eric W. Biederman
2012-01-29 19:31 ` Lucian Adrian Grijincu
2012-01-31 4:45 ` Eric W. Biederman
2012-01-27 4:51 ` [PATCH 23/29] sysctl: Add sysctl_print_dir and use it in get_subdir Eric W. Biederman
2012-01-27 4:52 ` [PATCH 24/29] sysctl: Replace root_list with links between sysctl_table_sets Eric W. Biederman
2012-01-30 0:01 ` Lucian Adrian Grijincu [this message]
2012-01-31 3:10 ` Eric W. Biederman
2012-01-30 17:51 ` Dave Jones
2012-01-31 2:11 ` Eric W. Biederman
2012-01-31 2:13 ` Joe Perches
2012-01-27 4:52 ` [PATCH 25/29] sysctl: Modify __register_sysctl_paths to take a set instead of a root and an nsproxy Eric W. Biederman
2012-01-27 4:52 ` [PATCH 26/29] sysctl: Move sysctl_check_dups into insert_header Eric W. Biederman
2012-01-27 4:52 ` [PATCH 27/29] sysctl: Make the header lists per directory Eric W. Biederman
2012-01-27 4:52 ` [PATCH 28/29] sysctl: Index sysctl directories with rbtrees Eric W. Biederman
2012-01-27 4:52 ` [PATCH 29/29] sysctl: Add register_sysctl for normal sysctl users Eric W. Biederman
2012-02-02 3:27 ` [Review][PATCH][0/4] sysctl bitty fixes Eric W. Biederman
2012-02-02 3:28 ` [PATCH 1/4] sysctl: An easier to read version of find_subdir Eric W. Biederman
2012-02-02 3:29 ` [PATCH 2/4] sysctl: Correct error return from get_subdir Eric W. Biederman
2012-02-02 3:29 ` [PATCH 3/4] sysctl: Comments to make the code clearer Eric W. Biederman
2012-02-02 16:28 ` Ben Hutchings
2012-02-02 3:30 ` [PATCH 4/4] sysctl: Don't call sysctl_follow_link unless we are a link Eric W. Biederman
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=CAPLs8y8YV0MiNhR0SnviBHPQb-oMj+_DLvRpJN89Yrbyjsf2xg@mail.gmail.com \
--to=lucian.grijincu@gmail.com \
--cc=damien.millescamps@6wind.com \
--cc=ebiederm@xmission.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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).