Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1418275lqd; Thu, 25 Apr 2024 15:18:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSMrBmNCE1aq/wqTuUp6B8QL3QCF3vqzSuKbOn5SGLVxTTMb5TucpmRrf4TElUxiYc5W/hCleGCiL51XSWAZTUUscaInO06NlMJJk/MA== X-Google-Smtp-Source: AGHT+IHOtyk1nHakBkFCzLqSf2wMq1I8YaKi+38BcLmv4J4+NDmIgu8Tor9sth4IxHUgY4xaITh2 X-Received: by 2002:a50:f68f:0:b0:571:be31:500b with SMTP id d15-20020a50f68f000000b00571be31500bmr618965edn.25.1714083527784; Thu, 25 Apr 2024 15:18:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714083527; cv=pass; d=google.com; s=arc-20160816; b=DVfrA4JUEVnguEV59kTajWKEcrEW0CYSkvV+ykiEMn4s26lr/2gEfmryzFOLPgoHJa ds8BLBtVCiy08DtuoUyn5+3lON2XRcSmjufAuYbwwC1tZ3Kw5VdGrOpCxeWISlnSbal7 I8UveeQ7hp0D/8buVfuPETeCqpSTgyh0MTwED6U3xqmVXMvDWeHv17NjZsv+gmG8AT+a jqLJ2m9TAP1pwd0zGQt3vjNBTxFchwDlsojDPDSndmLp/C7w2VMiiE4zvd4iucHeBGLc DYvlus3EPuhFnyFNaETBdIB5w0MNYTPKEiIdRyxLhSN+A/iR9ty2obzy6MFWBHeKjnhb kemA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=qcaXVQm7LCKx33Z9bMfhR6q1MTnTq6iFanOK7BRu6Ak=; fh=oj1K2Wgi9ad1if+A7G0R2BYQbeFSe7hawDzidmOCD8c=; b=t1F7n7S30pOqySRK2hTo1/ETR7T9puHr3fvJlWHGEXde8HTGCPFup3Do22yAAr8Ha3 Bnj7wiUn8E0zOaVkDElMo0hZi+v0F52hUTPJqOD9LvkabHHPLDWELYKkcBKIAmuPlCV7 lWLZYcRJFdrzfDpFsAF1l+GZ0Ig9oxXE5RXnJ1YrmpIFi6JLlcbMz83s7hXMEX9ezETU GnMBCmbYM5frXkQppuk6LTdeUCgUnVXvjuJuJfEGzDS8bHFDXJeb+esruNZB3Pv21SII ZJtCSvJLzOIbD4j7rmuM8P0TGxcQU5VNXwS/+N1BLutUB9hX8WCBF402ZC7t7fCGDadS fz/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dwC3JTSG; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-159297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l4-20020a056402028400b0057083e9f46dsi10267866edv.354.2024.04.25.15.18.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dwC3JTSG; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-159297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2F95F1F2A14A for ; Thu, 25 Apr 2024 22:11:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 878BD176FD2; Thu, 25 Apr 2024 22:05:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dwC3JTSG" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6144D175562 for ; Thu, 25 Apr 2024 22:05:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082715; cv=none; b=mT2R/To3Kevys51Ge3IE0jQvyL4ZqlVZa4dh4n+JmifXj1SwvcnEhiMMMfbkiivfBeHkMGHh96A70Fr8Y/Pa5clapF+gTOQMyj1bEMSI+SaKBUhwtkA3LjzIbFhCCdkSYOih/z1M3O2kS1QdZWHAGxx9bGY6eh5ACcMrhDrwywI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082715; c=relaxed/simple; bh=W25+yILfHx9cXQCv3wX2OvycXnIRZUSZb4Hv7dyII64=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=L/jY/Roh0MN/xMfQ3kuHoZPDmr+zWUD92igJDOk6oMQT5MkCkBwSs6rJH5Z9B9nQlS1SaEWf+6KGfZL97/u0QzaFZwJbBXkWSMJJ0Q2idTInPIMhAKW70F674GU/WcB8LVgU5l4B8IeolaI2wqLHLmowUjwrgxpw94qTrd6Kg8A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dwC3JTSG; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6156b93c768so27156507b3.1 for ; Thu, 25 Apr 2024 15:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714082713; x=1714687513; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=qcaXVQm7LCKx33Z9bMfhR6q1MTnTq6iFanOK7BRu6Ak=; b=dwC3JTSGZS33OxIsD8n4H/zVXWx2LJ9Q9PH/AuUD2eyQY7I0zmqi+dh+BPVFhRZZcq 0Tsx5R8SwrPmmEqNEKe4n7MIa7THwnrlsFFnOFCriL7wwqnCbvSnYX+Hs1bKBOCl+Hs9 K+Ii5x1JLXrv8Vb6ZFLCCxfXuhI2a4VOEG4N+WaGIDc4Vv74aI75YkwTwYgQ+Q6JEKab UMs7XhNeHft5OBp0EZvGJywYMN5ZT7EXIuOlE+tUpk2kXYR3qZjvSpTSLzTNR/6VUukc 0ZHozhBqEyDI/ZCA37lEjvwXfx8YD3e2c+0rnF646chQSpAP4cCqQPLeePQThvtugdw4 J8tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714082713; x=1714687513; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qcaXVQm7LCKx33Z9bMfhR6q1MTnTq6iFanOK7BRu6Ak=; b=gkS3GEmor6x6ritvwATgfDVF5QijOvzYFOaozeOJgT4qQmJ+ahdtRGnTC4oXdhaVyp HQE6OwFk7zLmLn7FslahxoTznHBgWNP24GA7fVr1jlr+0Q5pjIfaevOGVEig2F55Auc2 HDQ5afzuQqRv3TAI5Q/gx43IYGkIsdOEzpVHN1botjtASo92FjsS86GKQUyixtFB7qaQ zFWSll8huzLvJSQRKBpY1yXlsNw97VWxTaisR2ZEBoHfAy/i2ZtRaiNk84rxFMET98oq bIUlIko0i2RKsoZzWa0Xht0ZCe0axtA53PAy/p9Y2EER5yXII1uF4hrs/DITAb+NMiDC oOgw== X-Forwarded-Encrypted: i=1; AJvYcCWQlWs2tYmP0RhDT8wV3TkcnR2Avobs4doz8eRsG0Qahu841zuE0CxRy1zuozT1M1lxKlZQaXoUQsUnKJHs1HP3+XaORMWwiiJ84OcF X-Gm-Message-State: AOJu0YwRVXY8HUPQjXj4bFWh4sGtCkniVJd8T6gFUBz0tSUO6j1IgdFu XRkcyuZJvJecMyyEiOymEyohvZD4ZJEmTHQYmvn75oXMGNgap/eAg+iclWcyRxu5XT5j3aWXynn 1 X-Received: from yabinc-desktop.mtv.corp.google.com ([2620:15c:211:202:b177:fe3c:94d3:f359]) (user=yabinc job=sendgmr) by 2002:a05:6902:1549:b0:de5:1f88:ae4e with SMTP id r9-20020a056902154900b00de51f88ae4emr270433ybu.2.1714082713376; Thu, 25 Apr 2024 15:05:13 -0700 (PDT) Date: Thu, 25 Apr 2024 15:05:09 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240425220509.1751260-1-yabinc@google.com> Subject: [PATCH] perf/core: Trim dyn_size if raw data is absent From: Yabin Cui To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yabin Cui Content-Type: text/plain; charset="UTF-8" Currently, perf_tp_event() always allocates space for raw sample data, even when the PERF_SAMPLE_RAW flag is not set. This leads to unused spaces within generated sample records. This patch reduces dyn_size when PERF_SAMPLE_RAW is not present, ensuring sample records use only the necessary amount of space. Fixes: 0a9081cf0a11 ("perf/core: Add perf_sample_save_raw_data() helper") Signed-off-by: Yabin Cui --- kernel/events/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 724e6d7e128f..d68ecdc264d3 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7688,6 +7688,10 @@ void perf_prepare_sample(struct perf_sample_data *data, data->raw = NULL; data->dyn_size += sizeof(u64); data->sample_flags |= PERF_SAMPLE_RAW; + } else if ((data->sample_flags & ~sample_type) & PERF_SAMPLE_RAW) { + data->dyn_size -= data->raw->size + sizeof(u32); + data->raw = NULL; + data->sample_flags &= ~PERF_SAMPLE_RAW; } if (filtered_sample_type & PERF_SAMPLE_BRANCH_STACK) { -- 2.44.0.769.g3c40516874-goog