From: Eric Dumazet <eric.dumazet@gmail.com>
To: "David S. Miller" <davem@davemloft.net>, Greg KH <greg@kroah.com>
Cc: Benjamin LaHaise <bcrl@lhnet.ca>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Octavian Purdila <opurdila@ixiacom.com>,
netdev@vger.kernel.org, Cosmin Ratiu <cratiu@ixiacom.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] sysctl: reduce ram usage by 40 %
Date: Tue, 03 Nov 2009 08:01:24 +0100 [thread overview]
Message-ID: <4AEFD544.6040602@gmail.com> (raw)
In-Reply-To: <4AEFCA49.4020305@gmail.com>
Eric Dumazet a écrit :
> Its curious because in my tests the biggest problems come from
> kernel/sysctl.c (__register_sysctl_paths) consuming 80% of cpu
> in following attempt to create 20.000 devices
>
> (disable hotplug before trying this, and ipv6 too !)
> modprobe dummy numdummies=20000
>
> I believe we should address __register_sysctl_paths() scalability
> problems too.
>
> I dont know what is the 'sentinel' we allocate after each struct ctl_table
> But I suspect we could reduce size requirement of the 'sentinel' to include
> only needed fields for the sentinel (and move them at start of ctl_table)
>
Here is the patch to reduce ram usage of sysctl :
[PATCH] sysctl: reduce ram usage by 40 %
We currently reserve space for a so called sentinel, a full struct ctl_table
for each ctl_table. We can cheat a bit since only needed fields of a sentinel
are ctl_name and procname. Add a new structure (struct ctl_table_sentinel)
that includes a full ctl_table and only required part of a sentinel.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
include/linux/sysctl.h | 13 ++++++++++++-
kernel/sysctl.c | 19 ++++++++++---------
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 1e4743e..6a1b1d5 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -1050,8 +1050,10 @@ extern ctl_handler sysctl_ms_jiffies;
/* A sysctl table is an array of struct ctl_table: */
struct ctl_table
{
- int ctl_name; /* Binary ID */
+ /* ctl_name and procname must be first fields (check sentinel) */
+ int ctl_name; /* Binary ID */
const char *procname; /* Text ID for /proc/sys, or zero */
+
void *data;
int maxlen;
mode_t mode;
@@ -1063,6 +1065,15 @@ struct ctl_table
void *extra2;
};
+/* ctl_table_sentinel : a ctl_table followed by a sentinel
+ * (null ctl & procname)
+ */
+struct ctl_table_sentinel {
+ struct ctl_table table;
+ int ctl_name;
+ const char *procname;
+};
+
struct ctl_table_root {
struct list_head root_list;
struct ctl_table_set default_set;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 0d949c5..5d29dd8 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2063,7 +2063,8 @@ struct ctl_table_header *__register_sysctl_paths(
const struct ctl_path *path, struct ctl_table *table)
{
struct ctl_table_header *header;
- struct ctl_table *new, **prevp;
+ struct ctl_table_sentinel *new;
+ struct ctl_table **prevp;
unsigned int n, npath;
struct ctl_table_set *set;
@@ -2080,24 +2081,24 @@ struct ctl_table_header *__register_sysctl_paths(
* worry about freeing additional memory in unregister_sysctl_table.
*/
header = kzalloc(sizeof(struct ctl_table_header) +
- (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
+ (npath * sizeof(struct ctl_table_sentinel)), GFP_KERNEL);
if (!header)
return NULL;
- new = (struct ctl_table *) (header + 1);
+ new = (struct ctl_table_sentinel *) (header + 1);
/* Now connect the dots */
prevp = &header->ctl_table;
for (n = 0; n < npath; ++n, ++path) {
/* Copy the procname */
- new->procname = path->procname;
- new->ctl_name = path->ctl_name;
- new->mode = 0555;
+ new->table.procname = path->procname;
+ new->table.ctl_name = path->ctl_name;
+ new->table.mode = 0555;
- *prevp = new;
- prevp = &new->child;
+ *prevp = &new->table;
+ prevp = &new->table.child;
- new += 2;
+ new++;
}
*prevp = table;
header->ctl_table_arg = table;
next prev parent reply other threads:[~2009-11-03 7:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-01 16:31 [PATCH 1/3] sysfs directory scaling: rbtree for dirent name lookups Benjamin LaHaise
2009-11-01 16:32 ` [PATCH 2/3] sysfs directory scaling: doubly linked list for dirents Benjamin LaHaise
2009-11-01 16:33 ` [PATCH 2/3] sysfs directory scaling: count number of children dirs Benjamin LaHaise
2009-11-03 3:50 ` [PATCH 1/3] sysfs directory scaling: rbtree for dirent name lookups Greg KH
2009-11-03 6:14 ` Eric Dumazet
2009-11-03 7:01 ` Eric Dumazet [this message]
2009-11-03 10:23 ` [PATCH] sysctl: reduce ram usage by 40 % Eric W. Biederman
2009-11-03 16:07 ` [PATCH 1/3] sysfs directory scaling: rbtree for dirent name lookups Greg KH
2009-11-03 16:38 ` Octavian Purdila
2009-11-03 16:45 ` Benjamin LaHaise
2009-11-03 17:56 ` Greg KH
2009-11-03 22:28 ` Eric W. Biederman
2009-11-03 20:01 ` Benjamin LaHaise
2009-11-03 21:32 ` Eric W. Biederman
2009-11-03 21:43 ` Eric W. Biederman
2009-11-03 21:56 ` Benjamin LaHaise
2009-11-03 22:06 ` Eric Dumazet
2009-11-03 21:52 ` Benjamin LaHaise
2009-11-03 22:18 ` Eric W. Biederman
2009-11-03 10:41 ` 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=4AEFD544.6040602@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=bcrl@lhnet.ca \
--cc=cratiu@ixiacom.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=opurdila@ixiacom.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).