From: Vaibhav Nagarnaik <vnagarnaik@google.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, Michael Rubin <mrubin@google.com>,
David Sharp <dhsharp@google.com>
Subject: Re: [PATCH] trace: Add a free on close control mechanism for buffer_size_kb
Date: Fri, 29 Apr 2011 12:45:28 -0700 [thread overview]
Message-ID: <BANLkTimY9weoBhiQv+dfS4UzYPGBFDdPQQ@mail.gmail.com> (raw)
In-Reply-To: <1304033561.18763.212.camel@gandalf.stny.rr.com>
On Thu, Apr 28, 2011 at 4:32 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
> Sorry, my mind has been elsewhere and I forgot about your patches.
>
> On Fri, 2011-04-22 at 15:46 -0700, Vaibhav Nagarnaik wrote:
>> The proc file entry buffer_size_kb is used to set the size of tracing
>> buffer. The memory to expand the buffer size is kernel memory. Consider
>> a use case where tracing is handled by a user space utility, which acts
>> as a gate keeper for tracing requests. In an OOM condition, tracing is
>> considered a low priority task and if the utility gets killed the ring
>> buffer memory cannot be released back to the kernel.
>>
>> This patch adds an IOCTL on the buffer_size_kb file to set a boolean.
>> When this boolean is enabled, closing buffer_size_kb file will cause
>> tracing to stop and free up the ring buffer memory.
>>
>> The user space process can then open the buffer_size_kb file to set the
>> new buffer size for tracing, enable the boolean through IOCTL and keep
>> the file open. Under OOM condition, if the process gets killed, the
>> kernel closes the file descriptor for buffer_size_kb. The release
>> handler stops the tracing and releases the kernel memory automatically.
>>
>> Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
>> ---
>> include/linux/ftrace.h | 3 +
>> kernel/trace/trace.c | 135 ++++++++++++++++++++++++++++++++++++------------
>> 2 files changed, 105 insertions(+), 33 deletions(-)
>>
>> diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
>> index ca29e03..30c8a23 100644
>> --- a/include/linux/ftrace.h
>> +++ b/include/linux/ftrace.h
>> @@ -114,6 +114,9 @@ struct ftrace_func_command {
>> char *params, int enable);
>> };
>>
>> +/* enable/disable auto free ring buffer on file close */
>> +#define TRACE_RINGBUF_FREE_ON_CLOSE _IOW('t', 0x01, int)
>> +
>> #ifdef CONFIG_DYNAMIC_FTRACE
>>
>> int ftrace_arch_code_modify_prepare(void);
>> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
>> index d38c16a..c676f17 100644
>> --- a/kernel/trace/trace.c
>> +++ b/kernel/trace/trace.c
>> @@ -2817,6 +2817,42 @@ static int tracing_resize_ring_buffer(unsigned long size)
>> return ret;
>> }
>>
>> +static ssize_t tracing_buffer_resize_atomic(unsigned long size)
>
> Why call it "atomic"? Because you do the mutex? Anyway I hate the name.
> It sounds like it can do it without preemption, which it clearly can't
> do.
I just wanted to note that it was a locked operation. I have changed the name
to tracing_buffer_resize_locked.
If you think it can be named better, I will change it.
>
> The rest looks fine to me.
>
Thanks for reviewing. I will send the updated patch.
> -- Steve
>
>> +{
>> + int cpu, ret = 0;
>> +
>> + mutex_lock(&trace_types_lock);
>> +
>> + tracing_stop();
>> +
>> + /* disable all cpu buffers */
>> + for_each_tracing_cpu(cpu) {
>> + if (global_trace.data[cpu])
>> + atomic_inc(&global_trace.data[cpu]->disabled);
>> + if (max_tr.data[cpu])
>> + atomic_inc(&max_tr.data[cpu]->disabled);
>> + }
>> +
>> + if (size != global_trace.entries)
>> + ret = tracing_resize_ring_buffer(size);
>> +
>> + /* If check pages failed, return ENOMEM */
>> + if (tracing_disabled)
>> + ret = -ENOMEM;
>> +
>> + for_each_tracing_cpu(cpu) {
>> + if (global_trace.data[cpu])
>> + atomic_dec(&global_trace.data[cpu]->disabled);
>> + if (max_tr.data[cpu])
>> + atomic_dec(&max_tr.data[cpu]->disabled);
>> + }
>> +
>> + tracing_start();
>> + mutex_unlock(&trace_types_lock);
>> +
>> + return ret;
>> +}
>> +
>>
>
>
>
Vaibhav Nagarnaik
next prev parent reply other threads:[~2011-04-29 19:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-22 22:46 Vaibhav Nagarnaik
2011-04-28 23:14 ` Vaibhav Nagarnaik
2011-04-28 23:32 ` Steven Rostedt
2011-04-29 19:45 ` Vaibhav Nagarnaik [this message]
2011-04-29 20:01 ` Steven Rostedt
2011-04-29 23:15 ` Vaibhav Nagarnaik
2011-04-29 19:45 ` Vaibhav Nagarnaik
2011-04-29 23:16 ` Vaibhav Nagarnaik
2011-05-24 18:37 ` Vaibhav Nagarnaik
2011-05-24 18:48 ` Steven Rostedt
2011-05-26 3:29 ` Steven Rostedt
2011-05-26 18:00 ` Vaibhav Nagarnaik
2011-05-26 18:23 ` Steven Rostedt
2011-05-26 18:33 ` Vaibhav Nagarnaik
2011-05-26 18:16 ` [PATCH v2] " Vaibhav Nagarnaik
2011-05-26 18:34 ` Vaibhav Nagarnaik
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=BANLkTimY9weoBhiQv+dfS4UzYPGBFDdPQQ@mail.gmail.com \
--to=vnagarnaik@google.com \
--cc=dhsharp@google.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mrubin@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®