@@ -14,9 +14,11 @@ sitemap: false
14
14
author : Anubhab Ghosh
15
15
permalink : blogs/gsoc22_ghosh_experience_blog/
16
16
date : 2022-12-07
17
+ tags : gsoc llvm jitlink memory-manager
17
18
---
18
19
19
20
### Overview of the Project
21
+
20
22
LLVM JIT APIs include JITLink, a just-in-time linker that links together objects
21
23
code units directly in memory and executes them. It uses the
22
24
JITLinkMemoryManager interface to allocate and manage memory for the generated
@@ -28,13 +30,15 @@ memory and then when the code is generated, all the section contents are
28
30
transferred through finalize calls.
29
31
30
32
#### Shared Memory
33
+
31
34
The main problem was that EPC runs on top of file descriptor streams like Unix
32
35
pipes or TCP sockets. As all the generated code and data bytes are transferred
33
36
over the EPC this has some overhead that could be avoided by using shared
34
37
memory. If the two processes share the same physical memory pages then we can
35
38
completely avoid extra memory copying.
36
39
37
40
#### Small code model
41
+
38
42
While we are at it, another goal was to introduce a simple slab-based memory
39
43
manager. It would allocate a large chunk of memory in the beginning from the
40
44
executor process and allocate smaller blocks from that entirely at the
@@ -53,16 +57,20 @@ int main() {
53
57
return value + 1;
54
58
}
55
59
```
60
+
56
61
** Small code model**
62
+
57
63
``` asm
58
64
0000000000001119 <main>:
59
- 1119: 55 push rbp
60
- 111a: 48 89 e5 mov rbp,rsp
61
- 111d: 8b 05 ed 2e 00 00 mov eax,DWORD PTR [rip+0x2eed] # 4010 <value>
62
- 1123: 5d pop rbp
63
- 1124: c3 ret
65
+ 1119: 55 push rbp
66
+ 111a: 48 89 e5 mov rbp,rsp
67
+ 111d: 8b 05 ed 2e 00 00 mov eax,DWORD PTR [rip+0x2eed] # 4010 <value>
68
+ 1123: 5d pop rbp
69
+ 1124: c3 ret
64
70
```
71
+
65
72
** Large code model**
73
+
66
74
``` asm
67
75
0000000000001119 <main>:
68
76
1119: 55 push rbp
@@ -81,10 +89,10 @@ int main() {
81
89
Small code model is the default for most compilations so this is actually
82
90
required to load ordinary precompiled code, e.g., from existing static archives.
83
91
84
-
85
92
### My Approach
86
93
87
94
#### Memory Mappers
95
+
88
96
I introduced a new ` MemoryMapper ` abstraction for interacting with OS APIs at
89
97
different situations. It has separate implementations based on whether the code
90
98
will be executed in the same or different process. The ` InProcessMemoryMapper `
@@ -102,6 +110,7 @@ now already in place in the executor processes so finalization is just a matter
102
110
of sending the memory protections.
103
111
104
112
#### Slab-based allocator
113
+
105
114
Furthermore, I developed a slab-based memory allocator for JITLink, reserving a
106
115
large region of memory in the address space of the target process on the first
107
116
allocation. All subsequent allocations result in sub-regions of that to be
@@ -111,6 +120,7 @@ region, it also guarantees that JIT’d memory satisfies the layout constraints
111
120
required by the small code model.
112
121
113
122
#### Concurrency problems
123
+
114
124
After the implmentation, I tried JIT linking the CPython interpreter to
115
125
benchmark the implementation. We discovered that our overall CPU execution time
116
126
decreased by 45% but somewhat paradoxically clock time increased by 45%. In
@@ -133,7 +143,6 @@ this to access memory at runtime.
133
143
For a more detailed description and all the patches, please consult my
134
144
[ GSoC final report] ( https://compiler-research.org/assets/docs/Anubhab_Ghosh_GSoC2022_Report.pdf ) .
135
145
136
-
137
146
### Acknowledgements
138
147
139
148
I would like to share my gratitude for the LLVM community members and my mentors
@@ -157,7 +166,7 @@ many applications.
157
166
158
167
** Contact me!**
159
168
160
-
169
+
161
170
162
171
Github Username: [ argentite] ( https://github.com/argentite )
163
172
0 commit comments