Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp61328lqs; Mon, 4 Mar 2024 15:08:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVm6DTvpFIFGmm7847T+BySdlmmIAZX/mRExFw2WYXKKj/RENy5k+PUVvg8vKudkZz8EUxtDCvE5rQ/huTRbHOPz/5cQzM6Z9R18BtGsg== X-Google-Smtp-Source: AGHT+IEuNCZIE7scPievbHPLiRoL2ZB099aNwXZQVYlyEe4ZRs7mMZPf6OUxs76fr4/EjauBYSCp X-Received: by 2002:a17:907:76fa:b0:a43:b472:9a57 with SMTP id kg26-20020a17090776fa00b00a43b4729a57mr7429080ejc.62.1709593724869; Mon, 04 Mar 2024 15:08:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709593724; cv=pass; d=google.com; s=arc-20160816; b=tyWsEbPbKgpeFEXK35hs3qkW+PmiUFvUY+wZO3nPUfPKoz3PcB6hFJSyFed0ZCqiO7 Mb3o7p4QHqF2CLDcyr0S2Of9LmQo1kLSq4zLhRoMMs5N61xGiSRp8/Si5UT7PqMIEf6k 692jtQ20rNz7FcXEuJgH2rszZOqGJN0nDf9DFX9kLaB0eD+36QCObmrpZY1LRSFaTF8V RZ2jrAy00zmV6M9WssP7ydWWN31jhmWf8VCud2eaEYzF1w6CUMAZuT2yOee3gVEM9RyN jQNe4lQdQVzq/IoFLXTmp50FvzpPvcJei9K7Anua3ShkUCSVqU43otGIp0MFpF9U6m/G W3/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=b1r1e64Qfq1Nb/DkcZkKTpPhtuzkcXOgG4S4buJsiQE=; fh=s1fZEdGGHFKlkrF3njJuxobE+Xf6SbIV8h7pc+69Jsg=; b=VpzCrWJRZQ1Y1oTsaM0t95sjBQKB0YLG5VKj7LopFpo5QG3vNmpCr/ULU+r5NO2jeQ AK1jFDUYk9qP+/2rimwwiSohNpYD2/51pJyFTM9ZoDTZOQAv6AW15Ff9gZNP9B0JZQdz Y08LFnTfqydGtzC/XU/VSzSv4sMB0wi54YEqyxGZ3j8N2I/zhsWiNdIG5ULzzsBROg0g u5vDoWO8iMNwp+LjoYYGx3pJSlLi7lMOpfzOMxrkppAdjUKxIUgUKtd4GZnA61N5GdoL bgI/yf0uvaq/Bs6YcBjc46ouS4BEK01bP3VO361fuBh1OiW83shgf3CW6FHdshhVRBJF NWjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X37Ff001; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-91395-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91395-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g12-20020a170906348c00b00a43fb65eca0si4269151ejb.220.2024.03.04.15.08.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 15:08:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91395-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=@kernel.org header.s=k20201202 header.b=X37Ff001; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-91395-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91395-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 978311F22F5A for ; Mon, 4 Mar 2024 23:08:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 515C27D098; Mon, 4 Mar 2024 23:08:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X37Ff001" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77C337CF03; Mon, 4 Mar 2024 23:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709593697; cv=none; b=onGYz15zMNOKPVvUgpDpzQUUO1l/Xz42oMlemk9MArxWqeGW3TsTs79bf6IBuUnaD3CQDmUrE9aaj8+3rHgadQQANaG1y1xvFplBfyKhUTsALo3QxKsE1stfDjFB/cKRnaahuMdjpBm5UyAdAgCu674PmDq/PozDhDQzFgSR8dY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709593697; c=relaxed/simple; bh=/5bbCzf48je/36eQ9gunlgLxqUEMLvbbEKof6Y9DYOY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mH447jcvcWALg583QN1s5WMF5Yw+nSzSGXG1w4j8+TwV3AjaIlOoPoaSci3KXQjl8hGto5QCa7GW+lwHtGIfr+Eu4SOqIDTZpHe/uhIWT4gsHWBXujp6Z1Ik0Z+UNtmQ5plGkNmkieK+HwkOrkz7IiXzO+l6Nb04g/3kXJGHcCg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X37Ff001; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7A2EC433C7; Mon, 4 Mar 2024 23:08:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709593697; bh=/5bbCzf48je/36eQ9gunlgLxqUEMLvbbEKof6Y9DYOY=; h=From:To:Cc:Subject:Date:From; b=X37Ff001BXrUyw8X1CoYnojBl6XK3FBnPqCXu3fw7lfSNCqmvKZqfZfNPcJ8lVqpA BuD5MvHA4BZmR32+JO4N7HOrr6UIHUBBKCPtn///0mD/SRG+wutw5SW4asxIybmO+6 Zs7nTS4PHfP6+62cxyIgyxKrBErRTv35x4B0zaxLSjXeEax5LeO1trZt8YOXjUqK6c jN/fY/19YfI3aavGXwVm22RYMbZ+dcnjrAErxojDj/GZ9T6c0rAjlq7vAFGD4WNCC9 wE02J59mDhd1PuDxYzOcXxOabY9dAVqhVhDeyDumh6rJC0VkJROcy0Jfg7KBG3N9oJ sM5mpjjbMQuQA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Andi Kleen Subject: [PATCH v2 0/4] perf annotate: Improve memory usage for symbol histogram Date: Mon, 4 Mar 2024 15:08:11 -0800 Message-ID: <20240304230815.1440583-1-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hello, This is another series of memory optimization in perf annotate. v2 changes: * fix a bug when offset is bigger than 16 bits When perf annotate (or perf report/top with TUI) processes samples, it needs to save the sample period (overhead) at instruction level. For now, it allocates an array to do that for the whole symbol when it hits any new symbol. This comes with a lot of waste since samples can be very few and instructions span to multiple bytes. For example, when a sample hits symbol 'foo' that has size of 100 and that's the only sample falls into the symbol. Then it needs to allocate a symbol histogram (sym_hist) and the its size would be 16 (header) + 16 (sym_hist_entry) * 100 (symbol_size) = 1616 But actually it just needs 32 (header + sym_hist_entry) bytes. Things get worse if the symbol size is bigger (and it doesn't have many samples in different places). Also note that it needs a separate histogram for each event. Let's split the sym_hist_entry and have it in a hash table so that it can allocate only necessary entries. No functional change intended. Thanks, Namhyung Namhyung Kim (4): perf annotate: Add a hashmap for symbol histogram perf annotate: Calculate instruction overhead using hashmap perf annotate: Remove sym_hist.addr[] array perf annotate: Add comments in the data structures tools/perf/ui/gtk/annotate.c | 14 ++++- tools/perf/util/annotate.c | 116 ++++++++++++++++++++++------------- tools/perf/util/annotate.h | 86 +++++++++++++++++++++++--- 3 files changed, 159 insertions(+), 57 deletions(-) -- 2.44.0.rc1.240.g4c46232300-goog