[v1] perf record: Reduce memory for recording lost samples event

Message ID 20231207021627.1322884-1-irogers@google.com
State New
Headers
Series [v1] perf record: Reduce memory for recording lost samples event |

Commit Message

Ian Rogers Dec. 7, 2023, 2:16 a.m. UTC
  Reduce from PERF_SAMPLE_MAX_SIZE to "sizeof(*lost) +
session->machines.host.id_hdr_size".

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
---
Suggested in:
https://lore.kernel.org/lkml/CAM9d7cjpYHN_Q63sW70vTCisdW=-SzjsrryUUJjgtZ3+9jdxfA@mail.gmail.com/
---
 tools/perf/builtin-record.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Ian Rogers Jan. 3, 2024, 2:59 a.m. UTC | #1
On Wed, Dec 6, 2023 at 6:16 PM Ian Rogers <irogers@google.com> wrote:
>
> Reduce from PERF_SAMPLE_MAX_SIZE to "sizeof(*lost) +
> session->machines.host.id_hdr_size".
>
> Suggested-by: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Ian Rogers <irogers@google.com>

Ping.

Thanks,
Ian

> ---
> Suggested in:
> https://lore.kernel.org/lkml/CAM9d7cjpYHN_Q63sW70vTCisdW=-SzjsrryUUJjgtZ3+9jdxfA@mail.gmail.com/
> ---
>  tools/perf/builtin-record.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index eb5a398ddb1d..206110fc2799 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -1954,7 +1954,8 @@ static void record__read_lost_samples(struct record *rec)
>
>                                 if (count.lost) {
>                                         if (!lost) {
> -                                               lost = zalloc(PERF_SAMPLE_MAX_SIZE);
> +                                               lost = zalloc(sizeof(*lost) +
> +                                                             session->machines.host.id_hdr_size);
>                                                 if (!lost) {
>                                                         pr_debug("Memory allocation failed\n");
>                                                         return;
> @@ -1970,7 +1971,8 @@ static void record__read_lost_samples(struct record *rec)
>                 lost_count = perf_bpf_filter__lost_count(evsel);
>                 if (lost_count) {
>                         if (!lost) {
> -                               lost = zalloc(PERF_SAMPLE_MAX_SIZE);
> +                               lost = zalloc(sizeof(*lost) +
> +                                             session->machines.host.id_hdr_size);
>                                 if (!lost) {
>                                         pr_debug("Memory allocation failed\n");
>                                         return;
> --
> 2.43.0.rc2.451.g8631bc7472-goog
>
  
Arnaldo Carvalho de Melo Jan. 3, 2024, 4:45 p.m. UTC | #2
Em Wed, Dec 06, 2023 at 06:16:27PM -0800, Ian Rogers escreveu:
> Reduce from PERF_SAMPLE_MAX_SIZE to "sizeof(*lost) +
> session->machines.host.id_hdr_size".
> 
> Suggested-by: Namhyung Kim <namhyung@kernel.org>


Thanks, applied to perf-tools-next.

- Arnaldo


> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> Suggested in:
> https://lore.kernel.org/lkml/CAM9d7cjpYHN_Q63sW70vTCisdW=-SzjsrryUUJjgtZ3+9jdxfA@mail.gmail.com/
> ---
>  tools/perf/builtin-record.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index eb5a398ddb1d..206110fc2799 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -1954,7 +1954,8 @@ static void record__read_lost_samples(struct record *rec)
>  
>  				if (count.lost) {
>  					if (!lost) {
> -						lost = zalloc(PERF_SAMPLE_MAX_SIZE);
> +						lost = zalloc(sizeof(*lost) +
> +							      session->machines.host.id_hdr_size);
>  						if (!lost) {
>  							pr_debug("Memory allocation failed\n");
>  							return;
> @@ -1970,7 +1971,8 @@ static void record__read_lost_samples(struct record *rec)
>  		lost_count = perf_bpf_filter__lost_count(evsel);
>  		if (lost_count) {
>  			if (!lost) {
> -				lost = zalloc(PERF_SAMPLE_MAX_SIZE);
> +				lost = zalloc(sizeof(*lost) +
> +					      session->machines.host.id_hdr_size);
>  				if (!lost) {
>  					pr_debug("Memory allocation failed\n");
>  					return;
> -- 
> 2.43.0.rc2.451.g8631bc7472-goog
>
  

Patch

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index eb5a398ddb1d..206110fc2799 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1954,7 +1954,8 @@  static void record__read_lost_samples(struct record *rec)
 
 				if (count.lost) {
 					if (!lost) {
-						lost = zalloc(PERF_SAMPLE_MAX_SIZE);
+						lost = zalloc(sizeof(*lost) +
+							      session->machines.host.id_hdr_size);
 						if (!lost) {
 							pr_debug("Memory allocation failed\n");
 							return;
@@ -1970,7 +1971,8 @@  static void record__read_lost_samples(struct record *rec)
 		lost_count = perf_bpf_filter__lost_count(evsel);
 		if (lost_count) {
 			if (!lost) {
-				lost = zalloc(PERF_SAMPLE_MAX_SIZE);
+				lost = zalloc(sizeof(*lost) +
+					      session->machines.host.id_hdr_size);
 				if (!lost) {
 					pr_debug("Memory allocation failed\n");
 					return;