Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2276860rbb; Tue, 27 Feb 2024 17:27:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzhfPsWZfY8NcKXbp1t5pntzxkUkBbhiKrANR1oNibsH8B9a3Drd27fykWgcwEwNxqTLH1Ze/eSxtGbJ9e+XBufVoc6hwprNdOTZe69g== X-Google-Smtp-Source: AGHT+IGew3TN6pu00xP26VRVNDE0EgqCkjmdcjuipPkgwrLUYFWKckMVjA/edvY+XRhKUvajzWVE X-Received: by 2002:a17:902:d891:b0:1dc:6fec:15d8 with SMTP id b17-20020a170902d89100b001dc6fec15d8mr11185100plz.47.1709083656992; Tue, 27 Feb 2024 17:27:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709083656; cv=pass; d=google.com; s=arc-20160816; b=rtrm/aAOmH8UkLmJEYjiD4Dcv07HtGDB6UqCv4bYMhLtSxH5xSQwfRdqio6lJRsAPg CV2uvVwZJ8hG5uW6S9PO9F98gYU4g5nTjDhDzgs7HjZKRQpkpvmFgGpDPdq4RJCtGpA6 zzVkkbR8QWDG7IRwC2AJmYoFXmMRNm5nN8rxcmT7LHFJtBa1QSHzOk0v4pWAxEYy5Umn 6tkh5KA+NtV9iA0vxSThc7Z6h9GtiIclqvv30+3p65DAOMRoQDn8zGiU3HxSH6jptnb0 If5LRu/IRujA9U06UlB5KKaNc3lIJl7PKZIRDbwHVH8IhkzcGJJIvBqwUP0JqK4tWofj Hd1A== 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=sZfrapsxCnNC0YXN2XtGVaZ4SFpMv9Di9D++fGSBe0k=; fh=s1fZEdGGHFKlkrF3njJuxobE+Xf6SbIV8h7pc+69Jsg=; b=IdkHAz7MNIdYSuB/jpfMshVt9vxe3Hh7yNWBbvD5b/Q0o7RsTEqSMtMZxq5VMe61W+ hTfvKF+HKQdwAvuZ1tNPey2/bevJ5OB+M9UdnO0XeVEtgxpbpdALA+sOyx7JkeCkBsN7 5lmuRKrIyifIIUXPuKQiwq66T7WRmL2oLF0Cce0ccHLbR+sQblEcaSHpI8Ss9NC3XBL7 Wb3Ji5N/woTnHWqHN3EPU8n99sxxjQbtom3IZYOHRdfoABqn8Io53MJS40NPuHXLA0RY MXaOCCseH8is6TqBleg0TFlE2cyLnRHyd1sqvda4XoDT8MpxSYsHO0khH+bnmt/h4ikH xABg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pBZYTBSY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-84286-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84286-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e11-20020a170903240b00b001dc742a30bdsi2358671plo.386.2024.02.27.17.27.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 17:27:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84286-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pBZYTBSY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-84286-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84286-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1DB5BB27281 for ; Wed, 28 Feb 2024 00:52:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 627C21FDA; Wed, 28 Feb 2024 00:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pBZYTBSY" 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 68C85A34; Wed, 28 Feb 2024 00:52:32 +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=1709081552; cv=none; b=NfrSkkOdctOY7yKxlWnpIbtXhKsptS7xinRSBNF5J4eJe9vibF31kxW+B0QgH8VALSf0NREX3eSTznOVRvMRu706SePT3Mc0VxP4bZLqGxJ2UNhZEJICdghYoXxDAwPMqdZn8b4QCqEarzk6IYeM5mDWC6Sc1vzvfnqJ1f4yqOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709081552; c=relaxed/simple; bh=Pf04X6SV6XUlQWu1+HzF9j9trt7MUo1jU/RSKN5kwes=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lkrTKNnsBt71HmEJBIpZec9hhmvwroAYNJvvLJ43MmQoGNkqPcZiQ97L8ttbEer0mPCd+hCS3nUslFKYH/O3/m4LaGRT3ox0HiYg/qqX6xox2yu0beWKb2pThS+1jrqPh6+AOBmXanTjkaPaXS9+JqrEFlxMsmFTFmiVnOYzMpw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pBZYTBSY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90394C433F1; Wed, 28 Feb 2024 00:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709081551; bh=Pf04X6SV6XUlQWu1+HzF9j9trt7MUo1jU/RSKN5kwes=; h=From:To:Cc:Subject:Date:From; b=pBZYTBSYsSsFTPfDvsBGpMOVpCgniu+PwtBRwJqD+aP+ESBTeZAdxvn2h0QG0+0k5 aoQhKj+hq+wVVkHajIRys6Zc/luHWr73ZMoY2cPCBMkSvRSiNeHB71Z6McWYm0FN5g g7E3THuYdsKu5Hcpb1jSmbdq/81kvzPRIwGlLW05kuqr1tM0Z/c6SDp5Z3KTCZCVHr e/b0E9Hs1IT25EF1Jo1oi33g+VLvSE4HmxrdGnW4mxS+yR8NE/8Qizt4WC5whonSay xjPnHZZaW4m0/AogNqq7P6QUOj3JNMDPmM+E/an2EBWdh0sDN+GJDf2mp5/JJPMhjX ffT5ZjRd1rGbQ== 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 0/4] perf annotate: Improve memory usage for symbol histogram Date: Tue, 27 Feb 2024 16:52:26 -0800 Message-ID: <20240228005230.287113-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. 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 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 | 114 ++++++++++++++++++++++------------- tools/perf/util/annotate.h | 86 +++++++++++++++++++++++--- 3 files changed, 158 insertions(+), 56 deletions(-) -- 2.44.0.rc1.240.g4c46232300-goog