All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages()
@ 2014-06-11  8:06 Namhyung Kim
  2014-06-11  8:06 ` [PATCH 2/2] tracing: Do not copy hash if O_TRUNC is set Namhyung Kim
  2014-06-11 14:03 ` [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages() Steven Rostedt
  0 siblings, 2 replies; 5+ messages in thread
From: Namhyung Kim @ 2014-06-11  8:06 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Namhyung Kim, Namhyung Kim, Ingo Molnar

As struct ftrace_page is managed in a single linked list, it should
free from the start page.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 kernel/trace/ftrace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 5b372e3ed675..ddfda763ded7 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2398,7 +2398,8 @@ ftrace_allocate_pages(unsigned long num_to_init)
 	return start_pg;
 
  free_pages:
-	while (start_pg) {
+	pg = start_pg;
+	while (pg) {
 		order = get_count_order(pg->size / ENTRIES_PER_PAGE);
 		free_pages((unsigned long)pg->records, order);
 		start_pg = pg->next;
-- 
2.0.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] tracing: Do not copy hash if O_TRUNC is set
  2014-06-11  8:06 [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages() Namhyung Kim
@ 2014-06-11  8:06 ` Namhyung Kim
  2014-06-11 14:05   ` Steven Rostedt
  2014-06-11 14:03 ` [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages() Steven Rostedt
  1 sibling, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2014-06-11  8:06 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Namhyung Kim, Namhyung Kim, Ingo Molnar

When a filter file is open for writing and O_TRUNC is set, there's no
need to copy and free the filter entries.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 kernel/trace/ftrace.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index ddfda763ded7..13885590a184 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2759,7 +2759,13 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
 		hash = ops->filter_hash;
 
 	if (file->f_mode & FMODE_WRITE) {
-		iter->hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, hash);
+		const int size_bits = FTRACE_HASH_DEFAULT_BITS;
+
+		if (file->f_flags & O_TRUNC)
+			iter->hash = alloc_ftrace_hash(size_bits);
+		else
+			iter->hash = alloc_and_copy_ftrace_hash(size_bits, hash);
+
 		if (!iter->hash) {
 			trace_parser_put(&iter->parser);
 			kfree(iter);
@@ -2768,10 +2774,6 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
 		}
 	}
 
-	if ((file->f_mode & FMODE_WRITE) &&
-	    (file->f_flags & O_TRUNC))
-		ftrace_filter_reset(iter->hash);
-
 	if (file->f_mode & FMODE_READ) {
 		iter->pg = ftrace_pages_start;
 
-- 
2.0.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages()
  2014-06-11  8:06 [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages() Namhyung Kim
  2014-06-11  8:06 ` [PATCH 2/2] tracing: Do not copy hash if O_TRUNC is set Namhyung Kim
@ 2014-06-11 14:03 ` Steven Rostedt
  2014-06-12  1:08   ` Namhyung Kim
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2014-06-11 14:03 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: LKML, Namhyung Kim, Ingo Molnar

On Wed, 11 Jun 2014 17:06:53 +0900
Namhyung Kim <namhyung@kernel.org> wrote:

> As struct ftrace_page is managed in a single linked list, it should
> free from the start page.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  kernel/trace/ftrace.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 5b372e3ed675..ddfda763ded7 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -2398,7 +2398,8 @@ ftrace_allocate_pages(unsigned long num_to_init)
>  	return start_pg;
>  
>   free_pages:
> -	while (start_pg) {
> +	pg = start_pg;
> +	while (pg) {

It works with just the added "pg = start_page", I would keep the
while (start_pg) still.

-- Steve

>  		order = get_count_order(pg->size / ENTRIES_PER_PAGE);
>  		free_pages((unsigned long)pg->records, order);
>  		start_pg = pg->next;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] tracing: Do not copy hash if O_TRUNC is set
  2014-06-11  8:06 ` [PATCH 2/2] tracing: Do not copy hash if O_TRUNC is set Namhyung Kim
@ 2014-06-11 14:05   ` Steven Rostedt
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2014-06-11 14:05 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: LKML, Namhyung Kim, Ingo Molnar

On Wed, 11 Jun 2014 17:06:54 +0900
Namhyung Kim <namhyung@kernel.org> wrote:

> When a filter file is open for writing and O_TRUNC is set, there's no
> need to copy and free the filter entries.
> 

Nice cleanup. I'll add it for 3.17.

Thanks,

-- Steve

> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  kernel/trace/ftrace.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index ddfda763ded7..13885590a184 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -2759,7 +2759,13 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
>  		hash = ops->filter_hash;
>  
>  	if (file->f_mode & FMODE_WRITE) {
> -		iter->hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, hash);
> +		const int size_bits = FTRACE_HASH_DEFAULT_BITS;
> +
> +		if (file->f_flags & O_TRUNC)
> +			iter->hash = alloc_ftrace_hash(size_bits);
> +		else
> +			iter->hash = alloc_and_copy_ftrace_hash(size_bits, hash);
> +
>  		if (!iter->hash) {
>  			trace_parser_put(&iter->parser);
>  			kfree(iter);
> @@ -2768,10 +2774,6 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
>  		}
>  	}
>  
> -	if ((file->f_mode & FMODE_WRITE) &&
> -	    (file->f_flags & O_TRUNC))
> -		ftrace_filter_reset(iter->hash);
> -
>  	if (file->f_mode & FMODE_READ) {
>  		iter->pg = ftrace_pages_start;
>  


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages()
  2014-06-11 14:03 ` [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages() Steven Rostedt
@ 2014-06-12  1:08   ` Namhyung Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2014-06-12  1:08 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Namhyung Kim, Ingo Molnar

Hi Steve,

On Wed, 11 Jun 2014 10:03:40 -0400, Steven Rostedt wrote:
> On Wed, 11 Jun 2014 17:06:53 +0900
> Namhyung Kim <namhyung@kernel.org> wrote:
>
>> As struct ftrace_page is managed in a single linked list, it should
>> free from the start page.
>> 
>> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>> ---
>>  kernel/trace/ftrace.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
>> index 5b372e3ed675..ddfda763ded7 100644
>> --- a/kernel/trace/ftrace.c
>> +++ b/kernel/trace/ftrace.c
>> @@ -2398,7 +2398,8 @@ ftrace_allocate_pages(unsigned long num_to_init)
>>  	return start_pg;
>>  
>>   free_pages:
>> -	while (start_pg) {
>> +	pg = start_pg;
>> +	while (pg) {
>
> It works with just the added "pg = start_page", I would keep the
> while (start_pg) still.

The reason why I changed it is the code actually uses pg rather than
start_pg in the loop.  So it's more comfortable for me to check the pg
in the condition.  But it's minor, I won't insist it strongly.. :)

Thanks,
Namhyung


>>  		order = get_count_order(pg->size / ENTRIES_PER_PAGE);
>>  		free_pages((unsigned long)pg->records, order);
>>  		start_pg = pg->next;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-12  1:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-11  8:06 [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages() Namhyung Kim
2014-06-11  8:06 ` [PATCH 2/2] tracing: Do not copy hash if O_TRUNC is set Namhyung Kim
2014-06-11 14:05   ` Steven Rostedt
2014-06-11 14:03 ` [PATCH 1/2] tracing: Fix memory leak on failure path in ftrace_allocate_pages() Steven Rostedt
2014-06-12  1:08   ` Namhyung Kim

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.