All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Zefan <lizefan@huawei.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Borislav Petkov <bp@alien8.de>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v3 2/2] tracing: Shrink the size of struct ftrace_event_field
Date: Mon, 29 Jul 2013 10:14:23 +0800	[thread overview]
Message-ID: <51F5CFFF.3090502@huawei.com> (raw)
In-Reply-To: <1374924938.6580.46.camel@gandalf.local.home>

Use bit fields, and the size of struct ftrace_event_field can be
shrunk from 48 bytes to 40 bytes on 64bit kernel.

slab_name active_obj nr_obj size obj_per_slab
---------------------------------------------
ftrace_event_field   1105   1105     48   85  (before)
ftrace_event_field   1224   1224     40  102  (after)

This saves a few Kbytes: (1224 * 40) - (1105 * 48) = 4080

v2:
- use !!is_signed, and nuke the check on this field.
- use a different way to detect overflow.
(both suggested by Steven)

v3:
- use plain WARN_ON() instead of a macro. (suggeusted by Borislav)

Signed-off-by: Li Zefan <lizefan@huawei.com>
---
 kernel/trace/trace.h        |  8 ++++----
 kernel/trace/trace_events.c | 12 ++++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 4a4f6e1..3e8c97f 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -904,10 +904,10 @@ struct ftrace_event_field {
 	struct list_head	link;
 	const char		*name;
 	const char		*type;
-	int			filter_type;
-	int			offset;
-	int			size;
-	int			is_signed;
+	unsigned int		filter_type:4;
+	unsigned int		offset:12;
+	unsigned int		size:12;
+	unsigned int		is_signed:1;
 };
 
 struct event_filter {
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 7d85429..6509afe 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -120,13 +120,17 @@ static int __trace_define_field(struct list_head *head, const char *type,
 	field->type = type;
 
 	if (filter_type == FILTER_OTHER)
-		field->filter_type = filter_assign_type(type);
-	else
-		field->filter_type = filter_type;
+		filter_type = filter_assign_type(type);
 
+	field->filter_type = filter_type;
 	field->offset = offset;
 	field->size = size;
-	field->is_signed = is_signed;
+	field->is_signed = !!is_signed;
+
+	/* detect bit-field overflow */
+	WARN_ON(filter_type > field->filter_type);
+	WARN_ON(offset > field->offset);
+	WARN_ON(size > field->size);
 
 	list_add(&field->link, head);
 
-- 
1.8.0.2


  parent reply	other threads:[~2013-07-29  2:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25  2:27 [PATCH 1/2][RESEND] tracing/syscalls: Annotate raw_init function with __init Li Zefan
2013-07-25  2:28 ` [PATCH 2/2][RESEND] tracing: Shrink the size of struct ftrace_event_field Li Zefan
2013-07-26 15:09   ` Steven Rostedt
2013-07-27  3:13     ` Li Zefan
2013-07-27  3:32     ` [PATCH v2 2/2] " Li Zefan
2013-07-27  3:47       ` Steven Rostedt
2013-07-27  8:45         ` Borislav Petkov
2013-07-27 11:35           ` Steven Rostedt
2013-07-27 16:19             ` Borislav Petkov
2013-07-29  2:14             ` Li Zefan [this message]
2013-07-29  2:10           ` Li Zefan
2013-07-26 14:23 ` [PATCH 1/2][RESEND] tracing/syscalls: Annotate raw_init function with __init Steven Rostedt

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=51F5CFFF.3090502@huawei.com \
    --to=lizefan@huawei.com \
    --cc=bp@alien8.de \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.