[llvm] [MemProf][NFC] Free large data structures after last use (PR #75120)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 16:30:53 PST 2023
https://github.com/teresajohnson created https://github.com/llvm/llvm-project/pull/75120
The MemProf InstrProfWriter uses a couple of MapVector for building the
lists of records it needs to write. Once its entries are all added to
the associated OnDiskChainedHashTableGenerator, it is no longer used.
Clearing these MapVectors, which grow quite large for large profiles,
saved 4G for a large memory profile.
>From 0d1bfb5a6c014ff48da92a533edc4e55fc7f603b Mon Sep 17 00:00:00 2001
From: Teresa Johnson <tejohnson at google.com>
Date: Mon, 11 Dec 2023 14:42:28 -0800
Subject: [PATCH] [MemProf][NFC] Free large data structures after last use
The MemProf InstrProfWriter uses a couple of MapVector for building the
lists of records it needs to write. Once its entries are all added to
the associated OnDiskChainedHashTableGenerator, it is no longer used.
Clearing these MapVectors, which grow quite large for large profiles,
saved 4G for a large memory profile.
---
llvm/lib/ProfileData/InstrProfWriter.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 595c9aa1adc105..68b77a1482976a 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -536,6 +536,8 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
// Insert the key (func hash) and value (memprof record).
RecordTableGenerator.insert(I.first, I.second);
}
+ // Release the memory of this MapVector as it is no longer needed.
+ MemProfRecordData.clear();
uint64_t RecordTableOffset =
RecordTableGenerator.Emit(OS.OS, *RecordWriter);
@@ -549,6 +551,8 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
// Insert the key (frame id) and value (frame contents).
FrameTableGenerator.insert(I.first, I.second);
}
+ // Release the memory of this MapVector as it is no longer needed.
+ MemProfFrameData.clear();
uint64_t FrameTableOffset = FrameTableGenerator.Emit(OS.OS, *FrameWriter);
More information about the llvm-commits
mailing list