[llvm] 35a003c - [MemProf][NFC] Clear each IndexedMemProfRecord after it is written (#75205)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 11:38:37 PST 2023
Author: Teresa Johnson
Date: 2023-12-15T11:38:33-08:00
New Revision: 35a003c2b21082f3c47c8b01d9d1955af5ab098e
URL: https://github.com/llvm/llvm-project/commit/35a003c2b21082f3c47c8b01d9d1955af5ab098e
DIFF: https://github.com/llvm/llvm-project/commit/35a003c2b21082f3c47c8b01d9d1955af5ab098e.diff
LOG: [MemProf][NFC] Clear each IndexedMemProfRecord after it is written (#75205)
The on-disk hash table for the memprof writer holds copies of all the
memprof records to be written. These hold a lot of memory in aggregate,
due to the lists of alloc sites (which each have a list of context
frames) and call sites. Clear each one after emitting it.
This drops the peak memory when writing a very large indexed memprof
profile by about 2.5G.
Added:
Modified:
llvm/include/llvm/ProfileData/MemProf.h
llvm/lib/ProfileData/InstrProfWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index 6557481870d8c2..37c19094bc2a63 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -538,6 +538,11 @@ class RecordWriterTrait {
offset_type /*Unused*/) {
assert(Schema != nullptr && "MemProf schema is not initialized!");
V.serialize(*Schema, Out);
+ // Clear the IndexedMemProfRecord which results in clearing/freeing its
+ // vectors of allocs and callsites. This is owned by the associated on-disk
+ // hash table, but unused after this point. See also the comment added to
+ // the client which constructs the on-disk hash table for this trait.
+ V.clear();
}
};
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 68b77a1482976a..d65f8fe50313dc 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -539,6 +539,9 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
// Release the memory of this MapVector as it is no longer needed.
MemProfRecordData.clear();
+ // The call to Emit invokes RecordWriterTrait::EmitData which destructs
+ // the memprof record copies owned by the RecordTableGenerator. This works
+ // because the RecordTableGenerator is not used after this point.
uint64_t RecordTableOffset =
RecordTableGenerator.Emit(OS.OS, *RecordWriter);
More information about the llvm-commits
mailing list