@@ -157,6 +157,8 @@ void CallStackTrie::addCallStack(
157
157
}
158
158
159
159
void CallStackTrie::addCallStack (MDNode *MIB) {
160
+ // Note that we are building this from existing MD_memprof metadata.
161
+ BuiltFromExistingMetadata = true ;
160
162
MDNode *StackMD = getMIBStackNode (MIB);
161
163
assert (StackMD);
162
164
std::vector<uint64_t > CallStack;
@@ -187,8 +189,9 @@ void CallStackTrie::addCallStack(MDNode *MIB) {
187
189
static MDNode *createMIBNode (LLVMContext &Ctx, ArrayRef<uint64_t > MIBCallStack,
188
190
AllocationType AllocType,
189
191
ArrayRef<ContextTotalSize> ContextSizeInfo,
190
- const uint64_t MaxColdSize, uint64_t &TotalBytes,
191
- uint64_t &ColdBytes) {
192
+ const uint64_t MaxColdSize,
193
+ bool BuiltFromExistingMetadata,
194
+ uint64_t &TotalBytes, uint64_t &ColdBytes) {
192
195
SmallVector<Metadata *> MIBPayload (
193
196
{buildCallstackMetadata (MIBCallStack, Ctx)});
194
197
MIBPayload.push_back (
@@ -197,8 +200,9 @@ static MDNode *createMIBNode(LLVMContext &Ctx, ArrayRef<uint64_t> MIBCallStack,
197
200
if (ContextSizeInfo.empty ()) {
198
201
// The profile matcher should have provided context size info if there was a
199
202
// MinCallsiteColdBytePercent < 100. Here we check >=100 to gracefully
200
- // handle a user-provided percent larger than 100.
201
- assert (MinCallsiteColdBytePercent >= 100 );
203
+ // handle a user-provided percent larger than 100. However, we may not have
204
+ // this information if we built the Trie from existing MD_memprof metadata.
205
+ assert (BuiltFromExistingMetadata || MinCallsiteColdBytePercent >= 100 );
202
206
return MDNode::get (Ctx, MIBPayload);
203
207
}
204
208
@@ -252,9 +256,19 @@ void CallStackTrie::convertHotToNotCold(CallStackTrieNode *Node) {
252
256
static void saveFilteredNewMIBNodes (std::vector<Metadata *> &NewMIBNodes,
253
257
std::vector<Metadata *> &SavedMIBNodes,
254
258
unsigned CallerContextLength,
255
- uint64_t TotalBytes, uint64_t ColdBytes) {
259
+ uint64_t TotalBytes, uint64_t ColdBytes,
260
+ bool BuiltFromExistingMetadata) {
256
261
const bool MostlyCold =
257
- MinCallsiteColdBytePercent < 100 &&
262
+ // If we have built the Trie from existing MD_memprof metadata, we may or
263
+ // may not have context size information (in which case ColdBytes and
264
+ // TotalBytes are 0, which is not also guarded against below). Even if we
265
+ // do have some context size information from the the metadata, we have
266
+ // already gone through a round of discarding of small non-cold contexts
267
+ // during matching, and it would be overly aggressive to do it again, and
268
+ // we also want to maintain the same behavior with and without reporting
269
+ // of hinted bytes enabled.
270
+ !BuiltFromExistingMetadata && MinCallsiteColdBytePercent < 100 &&
271
+ ColdBytes > 0 &&
258
272
ColdBytes * 100 >= MinCallsiteColdBytePercent * TotalBytes;
259
273
260
274
// In the simplest case, with pruning disabled, keep all the new MIB nodes.
@@ -386,9 +400,9 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
386
400
if (hasSingleAllocType (Node->AllocTypes )) {
387
401
std::vector<ContextTotalSize> ContextSizeInfo;
388
402
collectContextSizeInfo (Node, ContextSizeInfo);
389
- MIBNodes.push_back (
390
- createMIBNode ( Ctx, MIBCallStack, (AllocationType)Node->AllocTypes ,
391
- ContextSizeInfo, MaxColdSize , TotalBytes, ColdBytes));
403
+ MIBNodes.push_back (createMIBNode (
404
+ Ctx, MIBCallStack, (AllocationType)Node->AllocTypes , ContextSizeInfo ,
405
+ MaxColdSize, BuiltFromExistingMetadata , TotalBytes, ColdBytes));
392
406
return true ;
393
407
}
394
408
@@ -416,7 +430,8 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
416
430
// Pass in the stack length of the MIB nodes added for the immediate caller,
417
431
// which is the current stack length plus 1.
418
432
saveFilteredNewMIBNodes (NewMIBNodes, MIBNodes, MIBCallStack.size () + 1 ,
419
- CallerTotalBytes, CallerColdBytes);
433
+ CallerTotalBytes, CallerColdBytes,
434
+ BuiltFromExistingMetadata);
420
435
TotalBytes += CallerTotalBytes;
421
436
ColdBytes += CallerColdBytes;
422
437
@@ -441,9 +456,9 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
441
456
return false ;
442
457
std::vector<ContextTotalSize> ContextSizeInfo;
443
458
collectContextSizeInfo (Node, ContextSizeInfo);
444
- MIBNodes.push_back (createMIBNode (Ctx, MIBCallStack, AllocationType::NotCold,
445
- ContextSizeInfo, MaxColdSize, TotalBytes ,
446
- ColdBytes));
459
+ MIBNodes.push_back (createMIBNode (
460
+ Ctx, MIBCallStack, AllocationType::NotCold, ContextSizeInfo, MaxColdSize,
461
+ BuiltFromExistingMetadata, TotalBytes, ColdBytes));
447
462
return true ;
448
463
}
449
464
0 commit comments