[profile] Decommit memory after counter relocation

After we relocate counters, we no longer need to keep the original copy
around so we can return the memory back to the operating system.

Differential Revision: https://reviews.llvm.org/D104839
This commit is contained in:
Petr Hosek
2021-02-20 22:11:33 -08:00
parent 39a36999f9
commit 25dade54d3
6 changed files with 70 additions and 7 deletions

View File

@@ -490,6 +490,8 @@ static void relocateCounters(void) {
* __llvm_profile_get_size_for_buffer(). */
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
const uint64_t *CountersBegin = __llvm_profile_begin_counters();
const uint64_t *CountersEnd = __llvm_profile_end_counters();
uint64_t DataSize = __llvm_profile_get_data_size(DataBegin, DataEnd);
const uint64_t CountersOffset = sizeof(__llvm_profile_header) +
(DataSize * sizeof(__llvm_profile_data));
@@ -542,8 +544,11 @@ static void relocateCounters(void) {
}
/* Update the profile fields based on the current mapping. */
__llvm_profile_counter_bias = (intptr_t)Profile -
(uintptr_t)__llvm_profile_begin_counters() + CountersOffset;
__llvm_profile_counter_bias =
(intptr_t)Profile - (uintptr_t)CountersBegin + CountersOffset;
/* Return the memory allocated for counters to OS. */
lprofReleaseMemoryPagesToOS((uintptr_t)CountersBegin, (uintptr_t)CountersEnd);
}
static void initializeProfileForContinuousMode(void) {