You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Huge page support for composite images loaded on Linux (#37673)
Add support for loading composite R2R images utilizing huge pages on Linux
Support is broken into 3 major portions
- Changes to the compiler to add a switch which can compile the composite image with higher than normal alignment
- Changes to the runtime to make some slight tweaks to PE file loading on Linux to support these images correctly
- Documentation on how to tie these various features together to achieve large page loading on Linux
Configuring Huge Pages for loading composite binaries using CoreCLR on Linux
2
+
----
3
+
4
+
Huge pages can provide performance benefits to reduce the cost of TLB cache misses when
5
+
executing code. In general, the largest available wins may be achieved by enabling huge
6
+
pages for use by the GC, which will dominate the memory use in the process, but in some
7
+
circumstances, if the application is sufficiently large, there may be a benefit to using
8
+
huge pages to map in code.
9
+
10
+
It is expected that consumers who have these needs have very large applications, and are
11
+
able to tolerate somewhat complex solutions. CoreCLR supports loading composite R2R
12
+
images using the hugetlbfs. Doing some requires several steps.
13
+
14
+
1. The composite image must be created with a switch such as `--custom-pe-section-alignment=2097152`. This will align the PE sections in the R2R file on 2MB virtual address boundaries, and align the sections in the PE file itself on the same boundaries.
15
+
- This will increase the size of the image by up to 5 * the specified alignment. Typical increases will be more similar to 3 * the specified alignment
16
+
2. The composite image must be copied into a hugetlbfs filesystem which is visible to the .NET process instead of the composite image being loaded from the normal path.
17
+
- IMPORTANT: The composite image must NOT be located in the normal path next to the application binary, or that file will be used instead of the huge page version.
18
+
- The environment variable `COMPlus_NativeImageSearchPaths` must be set to point at the location of the hugetlbfs in use. For instance, `COMPlus_NativeImageSearchPaths` might be set to `/var/lib/hugetlbfs/user/USER/pagesize-2MB`
19
+
- As the cp command does not support copying into a hugetlbfs due to lack of support for the write syscall in that file system, a custom copy application must be used. A sample application that may be used to perform this task has a source listing in Appendix A.
20
+
3. The machine must be configured to have sufficient huge pages available in the appropriate huge page pool. The memory requirements of huge page PE loading are as follows.
21
+
- Sufficient pages to hold the unmodified copy of the composite image in the hugetlbfs. These pages will be used by the initial copy which emplaces the composite image into huge pages.
22
+
- By default the runtime will map each page of the composite image using a MAP_PRIVATE mapping. This will require that the maximum number of huge pages is large enough to hold a completely separate copy of the image as loaded.
23
+
- To reduce that cost, launch the application with the PAL_MAP_READONLY_PE_HUGE_PAGE_AS_SHARED environment variable set to 1. This environment variable will change the way that the composite image R2R files are mapped into the process to create the mappings to read only sections as MAP_SHARED mappings. This will reduce the extra huge pages needed to only be the sections marked as RW in the PE file. On a Windows machine use the link tool (`link /dump /header compositeimage.dll` to determine the number of pages needed for the these `.data` section of the PE file.)
24
+
- If the PAL_MAP_READONLY_PE_HUGE_PE_AS_SHARED is set, the number of huge pages needed is `<Count of huge pages for composite file> + <count of processes to run> * <count of huge pages needed for the .data section of the composite file>`
25
+
26
+
Appendix A - Source for a simple copy into hugetlbfs program.
27
+
28
+
```
29
+
// Licensed to the .NET Foundation under one or more agreements.
30
+
// The .NET Foundation licenses this file to you under the MIT license.
31
+
// See the LICENSE file in the project root for more information.
32
+
33
+
#include <stdlib.h>
34
+
#include <stdio.h>
35
+
#include <unistd.h>
36
+
#include <sys/mman.h>
37
+
#include <sys/stat.h>
38
+
#include <fcntl.h>
39
+
#include <string.h>
40
+
#include <unistd.h>
41
+
42
+
int main(int argc, char** argv)
43
+
{
44
+
if (argc != 3)
45
+
{
46
+
printf("Incorrect number arguments specified. Arguments are <src> <dest>");
0 commit comments