From 709bdf9e73bb36fc7bab6b7badaefff4c3a6a393 Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Tue, 19 Mar 2024 01:42:43 +0000 Subject: [PATCH] Bug 1857841 - pt 7. Also amortise VirtualAlloc in SplitRun() r=glandium Differential Revision: https://phabricator.services.mozilla.com/D195515 --- memory/build/mozjemalloc.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/memory/build/mozjemalloc.cpp b/memory/build/mozjemalloc.cpp index a38bb444a1e1..bab7e057cf69 100644 --- a/memory/build/mozjemalloc.cpp +++ b/memory/build/mozjemalloc.cpp @@ -2653,6 +2653,20 @@ bool arena_t::SplitRun(arena_run_t* aRun, size_t aSize, bool aLarge, (CHUNK_MAP_FRESH | CHUNK_MAP_MADVISED)) == 0); } + // Consider committing more pages to amortise calls to VirtualAlloc. + // This only makes sense at the edge of our run hence the if condition + // here. + if (i + j == need_pages) { + size_t extra_commit = ExtraCommitPages(j, rem_pages); + for (; i + j < need_pages + extra_commit && + (chunk->map[run_ind + i + j].bits & + CHUNK_MAP_MADVISED_OR_DECOMMITTED); + j++) { + MOZ_ASSERT((chunk->map[run_ind + i + j].bits & + (CHUNK_MAP_FRESH | CHUNK_MAP_MADVISED)) == 0); + } + } + if (!pages_commit( (void*)(uintptr_t(chunk) + ((run_ind + i) << gPageSize2Pow)), j << gPageSize2Pow)) {