Skip to content

Commit 8fc3f6d

Browse files
authored
[BOLT] Add option instrumentation-max-size for bump allocator (#174716)
While the current max memory size is sufficient for most binaries, a few binaries may encouter insufficient allocated memory space. Allow specify the max memory size of the instrumentation bump allocator.
1 parent fdc393f commit 8fc3f6d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ cl::opt<bool> ConservativeInstrumentation(
5151
"accuracy (for debugging, default: false)"),
5252
cl::init(false), cl::Optional, cl::cat(BoltInstrCategory));
5353

54+
cl::opt<uint32_t> InstrumentationMaxSize(
55+
"instrumentation-max-size",
56+
cl::desc("Set max memory size of the instrumentation bump allocator "
57+
"default: 0x6400000)"),
58+
cl::init(0x6400000), cl::Optional, cl::cat(BoltInstrCategory));
59+
5460
cl::opt<uint32_t> InstrumentationSleepTime(
5561
"instrumentation-sleep-time",
5662
cl::desc("interval between profile writes (default: 0 = write only at "

bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern cl::opt<bool> InstrumentationFileAppendPID;
3333
extern cl::opt<bool> ConservativeInstrumentation;
3434
extern cl::opt<std::string> InstrumentationFilename;
3535
extern cl::opt<std::string> InstrumentationBinpath;
36+
extern cl::opt<uint32_t> InstrumentationMaxSize;
3637
extern cl::opt<uint32_t> InstrumentationSleepTime;
3738
extern cl::opt<bool> InstrumentationNoCountersClear;
3839
extern cl::opt<bool> InstrumentationWaitForks;
@@ -167,6 +168,7 @@ void InstrumentationRuntimeLibrary::emitBinary(BinaryContext &BC,
167168
emitFill(sizeof(uint64_t), Label);
168169

169170
emitPadding(BC.RegularPageSize);
171+
emitIntValue("__bolt_instr_max_size", opts::InstrumentationMaxSize);
170172
emitIntValue("__bolt_instr_sleep_time", opts::InstrumentationSleepTime);
171173
emitIntValue("__bolt_instr_no_counters_clear",
172174
!!opts::InstrumentationNoCountersClear, 1);

bolt/runtime/instr.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ extern uint32_t __bolt_instr_num_ind_targets;
8585
extern uint32_t __bolt_instr_num_funcs;
8686
// Time to sleep across dumps (when we write the fdata profile to disk)
8787
extern uint32_t __bolt_instr_sleep_time;
88+
// Max size of bump allocator
89+
extern uint32_t __bolt_instr_max_size;
8890
// Do not clear counters across dumps, rewrite file with the updated values
8991
extern bool __bolt_instr_no_counters_clear;
9092
// Wait until all forks of instrumented process will finish
@@ -1551,14 +1553,14 @@ __bolt_instr_data_dump(int FD, const char *LibPath = nullptr,
15511553
ret = __ftruncate(FD, 0);
15521554
assert(ret == 0, "Failed to ftruncate!");
15531555
BumpPtrAllocator HashAlloc;
1554-
HashAlloc.setMaxSize(0x6400000);
1556+
HashAlloc.setMaxSize(__bolt_instr_max_size);
15551557
ProfileWriterContext Ctx = readDescriptions(LibContents, LibSize);
15561558
Ctx.CallFlowTable = new (HashAlloc, 0) CallFlowHashTable(HashAlloc);
15571559

15581560
DEBUG(printStats(Ctx));
15591561

15601562
BumpPtrAllocator Alloc;
1561-
Alloc.setMaxSize(0x6400000);
1563+
Alloc.setMaxSize(__bolt_instr_max_size);
15621564
const uint8_t *FuncDesc = Ctx.FuncDescriptions;
15631565
for (int I = 0, E = __bolt_instr_num_funcs; I < E; ++I) {
15641566
FuncDesc = writeFunctionProfile(FD, Ctx, FuncDesc, Alloc);
@@ -1662,8 +1664,9 @@ extern "C" void __attribute((force_align_arg_pointer)) __bolt_instr_setup() {
16621664
"__bolt_instr_setup: failed to mmap page for metadata!");
16631665

16641666
GlobalAlloc = new (GlobalMetadataStorage) BumpPtrAllocator;
1665-
// Conservatively reserve 100MiB
1666-
GlobalAlloc->setMaxSize(0x6400000);
1667+
// The max memory size can be set by -instrumentation-max-size, the default
1668+
// is 100MiB.
1669+
GlobalAlloc->setMaxSize(__bolt_instr_max_size);
16671670
GlobalAlloc->setShared(Shared);
16681671
GlobalWriteProfileMutex = new (*GlobalAlloc, 0) Mutex();
16691672
if (__bolt_instr_num_ind_calls > 0)

0 commit comments

Comments
 (0)