Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@f40d571b5d] [MERGE #3725 @obastemur] xp…
Browse files Browse the repository at this point in the history
…lat: improve virtual memory region lookups

Merge pull request #3725 from obastemur:exp_prop_in

virtual memory region linked list reaches to ~400 items during AcmeAir
warmup and successful lookups are mostly around the last found item.
  • Loading branch information
chakrabot authored and kfarnung committed Jan 9, 2018
1 parent b26e183 commit 60c004d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions deps/chakrashim/core/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct FREE_BLOCK {
#endif // MMAP_IGNORES_HINT

// The first node in our list of allocated blocks.
static PCMI pVirtualMemoryLastFound;
static PCMI pVirtualMemory;

#if MMAP_IGNORES_HINT
Expand Down Expand Up @@ -126,6 +127,7 @@ VIRTUALInitialize( void )
InternalInitializeCriticalSection(&virtual_realloc);

pVirtualMemory = NULL;
pVirtualMemoryLastFound = NULL;

return TRUE;
}
Expand Down Expand Up @@ -165,6 +167,7 @@ void VIRTUALCleanup()
InternalFree(pTempEntry );
}
pVirtualMemory = NULL;
pVirtualMemoryLastFound = NULL;

#if MMAP_IGNORES_HINT
// Clean up the free list.
Expand Down Expand Up @@ -534,6 +537,19 @@ static PCMI VIRTUALFindRegionInformation( IN UINT_PTR address )

pEntry = pVirtualMemory;

if (pVirtualMemoryLastFound && pVirtualMemoryLastFound->startBoundary <= address)
{
pEntry = pVirtualMemoryLastFound;
if (pEntry->startBoundary == address)
{
return pEntry;
}
}
else
{
pEntry = pVirtualMemory;
}

while( pEntry )
{
if ( pEntry->startBoundary > address )
Expand All @@ -549,6 +565,8 @@ static PCMI VIRTUALFindRegionInformation( IN UINT_PTR address )

pEntry = pEntry->pNext;
}

if (pEntry) pVirtualMemoryLastFound = pEntry;
return pEntry;
}

Expand Down Expand Up @@ -613,6 +631,11 @@ static BOOL VIRTUALReleaseMemory( PCMI pMemoryToBeReleased )
}
}

if (pVirtualMemoryLastFound->startBoundary >= pMemoryToBeReleased->startBoundary)
{
pVirtualMemoryLastFound = NULL;
}

#if MMAP_IGNORES_HINT
// We've removed the block from our allocated list. Add it to the
// free list.
Expand Down Expand Up @@ -2002,6 +2025,7 @@ VirtualProtect(
MemSize = (((UINT_PTR)(dwSize) + ((UINT_PTR)(lpAddress) & VIRTUAL_PAGE_MASK)
+ VIRTUAL_PAGE_MASK) & ~VIRTUAL_PAGE_MASK);

#if DEBUG
if ( VIRTUALContainsInvalidProtectionFlags( flNewProtect ) )
{
ASSERT( "flProtect can be one of PAGE_NOACCESS, PAGE_READONLY, "
Expand All @@ -2017,6 +2041,7 @@ VirtualProtect(
SetLastError( ERROR_NOACCESS );
goto ExitVirtualProtect;
}
#endif

pEntry = VIRTUALFindRegionInformation( StartBoundary );
if ( NULL != pEntry )
Expand Down

0 comments on commit 60c004d

Please sign in to comment.