From: Li Zefan <lizf@cn.fujitsu.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Jens Axboe <jens.axboe@oracle.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v3 4/7] blktrace: fix memory leak when freeing struct blk_io_trace
Date: Fri, 27 Mar 2009 16:13:14 +0800 [thread overview]
Message-ID: <49CC8A9A.6050101@cn.fujitsu.com> (raw)
In-Reply-To: <49CC66EA.4000703@cn.fujitsu.com>
> static void blk_tracer_start(struct trace_array *tr)
> {
> + blk_tracer_enabled = true;
> trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
> }
...
> static void blk_tracer_reset(struct trace_array *tr)
> {
> - blk_tracer_enabled = false;
> blk_tracer_stop(tr);
> }
Those changes should have been in [PATCH 3/7]..
==========
[PATCH] blktrace: fix memory leak when freeing struct blk_io_trace
When mixing the use of ioctl-based blktrace and ftrace-based blktrace,
we can leak memory in this way:
# btrace /dev/sda > /dev/null &
# echo 0 > /sys/block/sda/sda1/trace/enable
now we leak bt->dropped_file, bt->msg_file, bt->rchan...
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/trace/blktrace.c | 25 ++++++++++---------------
1 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index acf8454..2f21d77 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -247,7 +247,7 @@ record_it:
static struct dentry *blk_tree_root;
static DEFINE_MUTEX(blk_tree_mutex);
-static void blk_trace_cleanup(struct blk_trace *bt)
+static void blk_trace_free(struct blk_trace *bt)
{
debugfs_remove(bt->msg_file);
debugfs_remove(bt->dropped_file);
@@ -255,6 +255,11 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
+}
+
+static void blk_trace_cleanup(struct blk_trace *bt)
+{
+ blk_trace_free(bt);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
}
@@ -410,11 +415,11 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (buts->name[i] == '/')
buts->name[i] = '_';
- ret = -ENOMEM;
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
- goto err;
+ return -ENOMEM;
+ ret = -ENOMEM;
bt->sequence = alloc_percpu(unsigned long);
if (!bt->sequence)
goto err;
@@ -483,17 +488,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
return 0;
err:
- if (bt) {
- if (bt->msg_file)
- debugfs_remove(bt->msg_file);
- if (bt->dropped_file)
- debugfs_remove(bt->dropped_file);
- free_percpu(bt->sequence);
- free_percpu(bt->msg_data);
- if (bt->rchan)
- relay_close(bt->rchan);
- kfree(bt);
- }
+ blk_trace_free(bt);
return ret;
}
@@ -1250,7 +1245,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- kfree(bt);
+ blk_trace_free(bt);
return 0;
}
--
1.5.4.rc3
next prev parent reply other threads:[~2009-03-27 8:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-27 5:39 [PATCH v2 0/7] blktrace: last round of fixes Li Zefan
2009-03-27 5:39 ` [PATCH v2 1/7] trace: make 'mem' argument of trace_seq_putmem() const Li Zefan
2009-03-27 5:40 ` [PATCH v2 2/7] blktrace: make classic output more classic Li Zefan
2009-03-27 5:40 ` [PATCH v2 3/7] blktrace: fix blk_probes_ref chaos Li Zefan
2009-03-27 8:13 ` [PATCH v3 " Li Zefan
2009-03-27 5:40 ` [PATCH v2 4/7] blktrace: fix memory leak when freeing struct blk_io_trace Li Zefan
2009-03-27 8:13 ` Li Zefan [this message]
2009-03-27 5:41 ` [PATCH v2 5/7] blktrace: extract duplidate code Li Zefan
2009-03-27 5:41 ` [PATCH v2 6/7] blktrace: print out BLK_TN_MESSAGE properly Li Zefan
2009-03-27 5:42 ` [PATCH v2 7/7] blktrace: support filtering of BLK_TN_MESSAGE Li Zefan
2009-03-27 9:42 ` [PATCH v2 0/7] blktrace: last round of fixes Ingo Molnar
2009-03-28 22:46 ` Ingo Molnar
2009-03-29 18:02 ` Jens Axboe
2009-03-30 1:17 ` Ingo Molnar
2009-03-30 0:40 ` Li Zefan
2009-03-30 1:23 ` Ingo Molnar
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=49CC8A9A.6050101@cn.fujitsu.com \
--to=lizf@cn.fujitsu.com \
--cc=acme@redhat.com \
--cc=fweisbec@gmail.com \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--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.