Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class StructureMemoryManager {
#if OS(WINDOWS) || PLATFORM(PLAYSTATION)
// libpas isn't calling pas_page_malloc commit, so we've got to commit the region ourselves
// https://bugs.webkit.org/show_bug.cgi?id=292771
OSAllocator::commit(result, MarkedBlock::blockSize, true, false);
if (result) [[likely]]
OSAllocator::commit(result, MarkedBlock::blockSize, true, false);
#endif
return result;
#elif USE(MIMALLOC)
Expand Down
17 changes: 9 additions & 8 deletions Source/bmalloc/libpas/src/libpas/pas_page_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static void commit_impl(void* ptr, size_t size, bool do_mprotect, pas_mmap_capab
void *currentPtr = ptr;
while (totalSeen < size) {
MEMORY_BASIC_INFORMATION memInfo;
VirtualQuery(currentPtr, &memInfo, sizeof(memInfo));
PAS_ASSERT(VirtualQuery(currentPtr, &memInfo, sizeof(memInfo)));
PAS_ASSERT(memInfo.State != 0x10000);
PAS_ASSERT(memInfo.RegionSize > 0);
PAS_ASSERT(virtual_alloc_with_retry(currentPtr, PAS_MIN(memInfo.RegionSize, size - totalSeen), MEM_COMMIT, PAGE_READWRITE));
Expand Down Expand Up @@ -456,25 +456,26 @@ static void decommit_impl(void* ptr, size_t size,
void* currentPtr = ptr;
while (totalSeen < size) {
MEMORY_BASIC_INFORMATION memInfo;
VirtualQuery(currentPtr, &memInfo, sizeof(memInfo));
PAS_ASSERT(VirtualQuery(currentPtr, &memInfo, sizeof(memInfo)));
PAS_ASSERT(memInfo.RegionSize > 0);
PAS_ASSERT(VirtualFree(currentPtr, PAS_MIN(memInfo.RegionSize, size - totalSeen), MEM_DECOMMIT));
currentPtr = (void*)((uintptr_t)currentPtr + memInfo.RegionSize);
totalSeen += memInfo.RegionSize;
}
}
} else {
/* do_mprotect=false callers (pas_expendable_memory) read payload directly
and rely on seeing zeros after decommit, like MADV_FREE. MEM_DECOMMIT
would make those reads AV, so use DiscardVirtualMemory which frees
physical RAM but keeps pages accessible. This does not release commit
charge, but expendable memory is bounded metadata. */
/* The only do_mprotect=false caller is pas_expendable_memory, which reads
payload directly and relies on seeing zeros after decommit, like
MADV_FREE. MEM_DECOMMIT would make those reads AV, so use
DiscardVirtualMemory which frees physical RAM but keeps pages
accessible. This does not release commit charge, but expendable memory
is bounded metadata. */
if (DiscardVirtualMemory(ptr, size)) {
size_t totalSeen = 0;
void* currentPtr = ptr;
while (totalSeen < size) {
MEMORY_BASIC_INFORMATION memInfo;
VirtualQuery(currentPtr, &memInfo, sizeof(memInfo));
PAS_ASSERT(VirtualQuery(currentPtr, &memInfo, sizeof(memInfo)));
PAS_ASSERT(memInfo.RegionSize > 0);
PAS_ASSERT(VirtualAlloc(currentPtr, PAS_MIN(memInfo.RegionSize, size - totalSeen), MEM_RESET, PAGE_READWRITE));
currentPtr = (void*)((uintptr_t)currentPtr + memInfo.RegionSize);
Expand Down
6 changes: 3 additions & 3 deletions Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void deallocate(pas_thread_local_cache* thread_local_cache)
thread_local_cache->allocator_index_capacity);

/* If we're doing symmetric decommit, then we need to commit the memory for the TLC now. */
pas_page_malloc_commit_without_mprotect(begin, size, pas_may_mmap);
pas_page_malloc_commit(begin, size, pas_may_mmap);

pas_large_utility_free_heap_deallocate(begin, size);
}
Expand Down Expand Up @@ -512,7 +512,7 @@ void pas_thread_local_cache_ensure_committed(pas_thread_local_cache* thread_loca

/* Don't attempt to do fancy things with spans for commit, since we're no longer really
optimizing for symmetric commit anyway. */
pas_page_malloc_commit_without_mprotect(
pas_page_malloc_commit(
(char*)thread_local_cache + (page_index << pas_page_malloc_alignment_shift()),
pas_page_malloc_alignment(),
pas_may_mmap);
Expand Down Expand Up @@ -996,7 +996,7 @@ static void decommit_allocator_range(pas_thread_local_cache* cache,
if (verbose)
pas_log("Decommitting %p...%p\n", (void*)decommit_range.begin, (void*)decommit_range.end);

pas_page_malloc_decommit_without_mprotect(
pas_page_malloc_decommit(
(char*)cache + decommit_range.begin, pas_range_size(decommit_range), pas_may_mmap);

if (verbose) {
Expand Down
Loading