mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +00:00
LibJS: Make BlockAllocator cache reuse blocks in random order
This commit is contained in:
parent
17f239e1c0
commit
23f4ff7247
1 changed files with 4 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Platform.h>
|
#include <AK/Platform.h>
|
||||||
|
#include <AK/Random.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibJS/Heap/BlockAllocator.h>
|
#include <LibJS/Heap/BlockAllocator.h>
|
||||||
#include <LibJS/Heap/HeapBlock.h>
|
#include <LibJS/Heap/HeapBlock.h>
|
||||||
|
@ -38,7 +39,9 @@ BlockAllocator::~BlockAllocator()
|
||||||
void* BlockAllocator::allocate_block([[maybe_unused]] char const* name)
|
void* BlockAllocator::allocate_block([[maybe_unused]] char const* name)
|
||||||
{
|
{
|
||||||
if (!m_blocks.is_empty()) {
|
if (!m_blocks.is_empty()) {
|
||||||
auto* block = m_blocks.take_last();
|
// To reduce predictability, take a random block from the cache.
|
||||||
|
size_t random_index = get_random_uniform(m_blocks.size());
|
||||||
|
auto* block = m_blocks.unstable_take(random_index);
|
||||||
ASAN_UNPOISON_MEMORY_REGION(block, HeapBlock::block_size);
|
ASAN_UNPOISON_MEMORY_REGION(block, HeapBlock::block_size);
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
if (set_mmap_name(block, HeapBlock::block_size, name) < 0) {
|
if (set_mmap_name(block, HeapBlock::block_size, name) < 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue