linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] perf record: fix memory leak on AIO objects deallocation
@ 2018-12-05 17:19 Alexey Budankov
  2018-12-06 17:05 ` Arnaldo Carvalho de Melo
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alexey Budankov @ 2018-12-05 17:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra
  Cc: Alexander Shishkin, Jiri Olsa, Namhyung Kim, Andi Kleen, linux-kernel


Sending a part which was missed between v12 and v13 of the patch set
introducing AIO trace streaming for perf record mode. 

The part is essential to avoid memory leakage during deallocation
of AIO related trace data buffers.

It is applied on top of acme perf/core repo.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
---
tools/perf/util/mmap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index ab30555d2afc..169d02973757 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -207,8 +207,18 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
 
 static void perf_mmap__aio_munmap(struct perf_mmap *map)
 {
+	int i;
+
+	for (i = 0; i < map->aio.nr_cblocks; ++i) {
+		if (map->aio.data[i])
+			zfree(&map->aio.data[i]);
+	}
 	if (map->aio.data)
 		zfree(&map->aio.data);
+	if (map->aio.cblocks)
+		zfree(&map->aio.cblocks);
+	if (map->aio.aiocb)
+		zfree(&map->aio.aiocb);
 }
 
 int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx,

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

* Re: [PATCH v1] perf record: fix memory leak on AIO objects deallocation
  2018-12-05 17:19 [PATCH v1] perf record: fix memory leak on AIO objects deallocation Alexey Budankov
@ 2018-12-06 17:05 ` Arnaldo Carvalho de Melo
  2018-12-06 18:10   ` Alexey Budankov
  2018-12-14 20:58 ` [tip:perf/core] perf record: Fix " tip-bot for Alexey Budankov
  2018-12-18 14:25 ` tip-bot for Alexey Budankov
  2 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-12-06 17:05 UTC (permalink / raw)
  To: Alexey Budankov
  Cc: Ingo Molnar, Peter Zijlstra, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Andi Kleen, linux-kernel

Em Wed, Dec 05, 2018 at 08:19:41PM +0300, Alexey Budankov escreveu:
> 
> Sending a part which was missed between v12 and v13 of the patch set
> introducing AIO trace streaming for perf record mode. 
> 
> The part is essential to avoid memory leakage during deallocation
> of AIO related trace data buffers.
> 
> It is applied on top of acme perf/core repo.
> 
> Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
> ---
> tools/perf/util/mmap.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index ab30555d2afc..169d02973757 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -207,8 +207,18 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
>  
>  static void perf_mmap__aio_munmap(struct perf_mmap *map)
>  {
> +	int i;
> +
> +	for (i = 0; i < map->aio.nr_cblocks; ++i) {
> +		if (map->aio.data[i])
> +			zfree(&map->aio.data[i]);
> +	}
>  	if (map->aio.data)
>  		zfree(&map->aio.data);
> +	if (map->aio.cblocks)
> +		zfree(&map->aio.cblocks);
> +	if (map->aio.aiocb)
> +		zfree(&map->aio.aiocb);

There is no need to check for NULL before calling zfree(), as it is just
a wrapper for free that sets that variable to NULL after calling it.

And free(NULL) is valid, just a noop to avoid having all those tests
before each call to free(). I'm making those plain zfree() and later
will do a sweep at removing other cases.

>  }
>  
>  int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx,

-- 

- Arnaldo

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

* Re: [PATCH v1] perf record: fix memory leak on AIO objects deallocation
  2018-12-06 17:05 ` Arnaldo Carvalho de Melo
@ 2018-12-06 18:10   ` Alexey Budankov
  0 siblings, 0 replies; 5+ messages in thread
From: Alexey Budankov @ 2018-12-06 18:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, Peter Zijlstra, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Andi Kleen, linux-kernel

On 06.12.2018 20:05, Arnaldo Carvalho de Melo wrote:
> Em Wed, Dec 05, 2018 at 08:19:41PM +0300, Alexey Budankov escreveu:
>>
>> Sending a part which was missed between v12 and v13 of the patch set
>> introducing AIO trace streaming for perf record mode. 
>>
>> The part is essential to avoid memory leakage during deallocation
>> of AIO related trace data buffers.
>>
>> It is applied on top of acme perf/core repo.
>>
>> Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
>> ---
>> tools/perf/util/mmap.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
>> index ab30555d2afc..169d02973757 100644
>> --- a/tools/perf/util/mmap.c
>> +++ b/tools/perf/util/mmap.c
>> @@ -207,8 +207,18 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
>>  
>>  static void perf_mmap__aio_munmap(struct perf_mmap *map)
>>  {
>> +	int i;
>> +
>> +	for (i = 0; i < map->aio.nr_cblocks; ++i) {
>> +		if (map->aio.data[i])
>> +			zfree(&map->aio.data[i]);
>> +	}
>>  	if (map->aio.data)
>>  		zfree(&map->aio.data);
>> +	if (map->aio.cblocks)
>> +		zfree(&map->aio.cblocks);
>> +	if (map->aio.aiocb)
>> +		zfree(&map->aio.aiocb);
> 
> There is no need to check for NULL before calling zfree(), as it is just
> a wrapper for free that sets that variable to NULL after calling it.
> 
> And free(NULL) is valid, just a noop to avoid having all those tests
> before each call to free(). I'm making those plain zfree() and later
> will do a sweep at removing other cases.

Thank you.
-Alexey

> 
>>  }
>>  
>>  int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx,
> 

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

* [tip:perf/core] perf record: Fix memory leak on AIO objects deallocation
  2018-12-05 17:19 [PATCH v1] perf record: fix memory leak on AIO objects deallocation Alexey Budankov
  2018-12-06 17:05 ` Arnaldo Carvalho de Melo
@ 2018-12-14 20:58 ` tip-bot for Alexey Budankov
  2018-12-18 14:25 ` tip-bot for Alexey Budankov
  2 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Alexey Budankov @ 2018-12-14 20:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ak, jolsa, alexander.shishkin, peterz, acme, hpa, tglx,
	linux-kernel, namhyung, mingo, alexey.budankov

Commit-ID:  c713acc7090b32ca1c157f6528d607a087e807a8
Gitweb:     https://git.kernel.org/tip/c713acc7090b32ca1c157f6528d607a087e807a8
Author:     Alexey Budankov <alexey.budankov@linux.intel.com>
AuthorDate: Wed, 5 Dec 2018 20:19:41 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 6 Dec 2018 16:43:27 -0300

perf record: Fix memory leak on AIO objects deallocation

Sending a part which was missed between v12 and v13 of the patch set
introducing AIO trace streaming for perf record mode.

The part is essential to avoid memory leakage during deallocation of AIO
related trace data buffers.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/e5d3154e-1583-83bb-9527-28ddbc6dbf9d@linux.intel.com
[ No need to test for NULL before calling zfree() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/mmap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index ab30555d2afc..8fc39311a30d 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -207,8 +207,14 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
 
 static void perf_mmap__aio_munmap(struct perf_mmap *map)
 {
+	int i;
+
+	for (i = 0; i < map->aio.nr_cblocks; ++i)
+		zfree(&map->aio.data[i]);
 	if (map->aio.data)
 		zfree(&map->aio.data);
+	zfree(&map->aio.cblocks);
+	zfree(&map->aio.aiocb);
 }
 
 int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx,

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

* [tip:perf/core] perf record: Fix memory leak on AIO objects deallocation
  2018-12-05 17:19 [PATCH v1] perf record: fix memory leak on AIO objects deallocation Alexey Budankov
  2018-12-06 17:05 ` Arnaldo Carvalho de Melo
  2018-12-14 20:58 ` [tip:perf/core] perf record: Fix " tip-bot for Alexey Budankov
@ 2018-12-18 14:25 ` tip-bot for Alexey Budankov
  2 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Alexey Budankov @ 2018-12-18 14:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, tglx, namhyung, linux-kernel, ak, alexey.budankov, jolsa,
	peterz, mingo, acme, alexander.shishkin

Commit-ID:  c8dd6ee51a4d0a119c8b4121d83008215e3209ed
Gitweb:     https://git.kernel.org/tip/c8dd6ee51a4d0a119c8b4121d83008215e3209ed
Author:     Alexey Budankov <alexey.budankov@linux.intel.com>
AuthorDate: Wed, 5 Dec 2018 20:19:41 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 17 Dec 2018 14:59:34 -0300

perf record: Fix memory leak on AIO objects deallocation

Sending a part which was missed between v12 and v13 of the patch set
introducing AIO trace streaming for perf record mode.

The part is essential to avoid memory leakage during deallocation of AIO
related trace data buffers.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/e5d3154e-1583-83bb-9527-28ddbc6dbf9d@linux.intel.com
[ No need to test for NULL before calling zfree() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/mmap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index ab30555d2afc..8fc39311a30d 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -207,8 +207,14 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
 
 static void perf_mmap__aio_munmap(struct perf_mmap *map)
 {
+	int i;
+
+	for (i = 0; i < map->aio.nr_cblocks; ++i)
+		zfree(&map->aio.data[i]);
 	if (map->aio.data)
 		zfree(&map->aio.data);
+	zfree(&map->aio.cblocks);
+	zfree(&map->aio.aiocb);
 }
 
 int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx,

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

end of thread, other threads:[~2018-12-18 14:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05 17:19 [PATCH v1] perf record: fix memory leak on AIO objects deallocation Alexey Budankov
2018-12-06 17:05 ` Arnaldo Carvalho de Melo
2018-12-06 18:10   ` Alexey Budankov
2018-12-14 20:58 ` [tip:perf/core] perf record: Fix " tip-bot for Alexey Budankov
2018-12-18 14:25 ` tip-bot for Alexey Budankov

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).