Skip to content

Commit 0cbfea4

Browse files
authored
[mono] Allocate helper page with mono_valloc so it doesn't confuse instruments (#120060)
* Revert "[mono][interp] Avoid leaving around pages without access (#119754)" This reverts commit 9031045. * Allocate helper page with mono_valloc so it doesn't confuse instruments mono_valloc uses mmap behind the scene.
1 parent 2c3b2a6 commit 0cbfea4

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/mono/mono/utils/mono-threads-posix.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,15 @@ mono_memory_barrier_process_wide (void)
289289
g_assert (status == 0);
290290

291291
if (memory_barrier_process_wide_helper_page == NULL) {
292-
status = posix_memalign (&memory_barrier_process_wide_helper_page, mono_pagesize (), mono_pagesize ());
293-
g_assert (status == 0);
292+
memory_barrier_process_wide_helper_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_NONE, MONO_MEM_ACCOUNT_OTHER);
293+
g_assert (memory_barrier_process_wide_helper_page != NULL);
294294
}
295295

296296
// Changing a helper memory page protection from read / write to no access
297297
// causes the OS to issue IPI to flush TLBs on all processors. This also
298298
// results in flushing the processor buffers.
299+
status = mono_mprotect (memory_barrier_process_wide_helper_page, mono_pagesize (), MONO_MMAP_READ | MONO_MMAP_WRITE);
300+
g_assert (status == 0);
299301

300302
// Ensure that the page is dirty before we change the protection so that
301303
// we prevent the OS from skipping the global TLB flush.
@@ -304,12 +306,6 @@ mono_memory_barrier_process_wide (void)
304306
status = mono_mprotect (memory_barrier_process_wide_helper_page, mono_pagesize (), MONO_MMAP_NONE);
305307
g_assert (status == 0);
306308

307-
// We expected the protection change above to have triggered the memory barrier.
308-
// We now undo the protection change so that memory allocation profilers don't
309-
// get confused by this memory lacking access permissions (ex with Instruments).
310-
status = mono_mprotect (memory_barrier_process_wide_helper_page, mono_pagesize (), MONO_MMAP_READ | MONO_MMAP_WRITE);
311-
g_assert (status == 0);
312-
313309
status = pthread_mutex_unlock (&memory_barrier_process_wide_mutex);
314310
g_assert (status == 0);
315311
}

0 commit comments

Comments
 (0)