Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Implement an allocator for executable (JIT) memory in PAL #2205

Merged
merged 2 commits into from
Dec 3, 2015

Conversation

sergiy-k
Copy link

@sergiy-k sergiy-k commented Dec 2, 2015

This change improves performance of CoreCLR with Server GC enabled by about 30% according to ASP.NET benchmarks on Linux. The table below shows number of requests per second that an ASP.NET benchmark could handle on my machine before and after the change.

Pipeline Before After Improvement
16 230K Req/sec 305K Req/sec 33%
256 240K Req/sec 340K Req/sec 42%

The problem was that with Server GC enabled, the GC initialization code was reserving a large chunk (about 18GB on my machine) of virtual address space during runtime initialization. Unfortunately, due to implementation details of MM on Linux, GC memory was located next to the location of libcoreclr. As a result, the runtime could not allocate memory for JIT'ed code close to the coreclr library. Because of that the JIT'ed code had to use jump stubs to call functions from the runtime (which can become very expensive, for example, for write barriers).

This change fixes this issue by implementing a simple allocator that tries to reserve (during process startup) a chunk of virtual memory that is located near the coreclr library (within 2GB range) that can be later used for JIT'ed code.

This change improves performance of CoreCLR with Server GC enabled by
about 30% according to ASP.NET benchmarks on Linux. The table below shows
number of requests per second that an ASP.NET benchmark could handle on my
machine before and after the change.

Pipeline        Before          After           Improvement
16              230K Req/sec    305K Req/sec    33%
256             240K Req/sec    340K Req/sec    42%

The problem was that with Server GC enabled, the GC initialization code was
reserving a large chunck (about 18GB on my machine) of virtual address
space during runtime initialization. Unfortunately, due to implementation
details of MM on Linux, GC memory was located next to the location of
libcoreclr. As a result, the runtime could not allocate memory for JIT'ed
code close to the coreclr library. Because of that the JIT'ed code had to
use jump stubs to call functions from the runtime (which can become very
expensive, for example, for write barriers).

This change fixes this issue by implementing a simple allocator that tries
to reserve (during process startup) a chuck of virtual memory that is
located near the coreclr library (within 2GB range) that can be later used
for JIT'ed code.
@@ -3538,6 +3542,7 @@ SetErrorMode(
#define MEM_MAPPED 0x40000
#define MEM_TOP_DOWN 0x100000
#define MEM_WRITE_WATCH 0x200000
#define MEM_RESERVE_EXECUTABLE 0x40000000 // reserve memory using executable memory allocator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two extra "0"? Shouldn't this be
0x400000 or
0x10000000 or
0x1000000

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional because I wanted to have some buffer between the standard Windows flags and PAL specific value.

@janvorli
Copy link
Member

janvorli commented Dec 2, 2015

LGTM modulo the nits.

@sergiy-k
Copy link
Author

sergiy-k commented Dec 2, 2015

I have addressed all code review comments.

@janvorli
Copy link
Member

janvorli commented Dec 2, 2015

LGTM

1 similar comment
@adityamandaleeka
Copy link
Member

LGTM

sergiy-k added a commit that referenced this pull request Dec 3, 2015
Implement an allocator for executable (JIT) memory in PAL
@sergiy-k sergiy-k merged commit 0bdc646 into dotnet:master Dec 3, 2015
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Implement an allocator for executable (JIT) memory in PAL

Commit migrated from dotnet/coreclr@0bdc646
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants