PageMemory* FreePagePool::takeFreePage(int index) { MutexLocker locker(m_mutex[index]); while (PoolEntry* entry = m_pool[index]) { m_pool[index] = entry->next; PageMemory* memory = entry->data; ASSERT(memory); delete entry; if (memory->commit()) return memory; // We got some memory, but failed to commit it, try again. delete memory; } return nullptr; }
PageMemory* PageMemory::allocate(size_t payloadSize) { ASSERT(payloadSize > 0); // Virtual memory allocation routines operate in OS page sizes. // Round up the requested size to nearest os page size. payloadSize = roundToOsPageSize(payloadSize); // Overallocate by 2 times OS page size to have space for a // guard page at the beginning and end of blink heap page. size_t allocationSize = payloadSize + 2 * blinkGuardPageSize; PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage(allocationSize); PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, payloadSize); RELEASE_ASSERT(storage->commit()); return storage; }