1
1
---
2
- title : " GSoC 2022 Experience of Anubhab Ghosh"
3
- layout : gridlay
4
- excerpt : " GSoC 2022 Experience of Anubhab Ghosh"
2
+ title : " Shared Memory Based JITLink Memory Manager"
3
+ layout : post
4
+ excerpt : " LLVM JIT APIs include JITLink, a just-in-time linker that links
5
+ together objects code units directly in memory and executes them. It uses the
6
+ JITLinkMemoryManager interface to allocate and manage memory for the generated
7
+ code. When the generated code is run in the same process as the linker, memory
8
+ is directly allocated using OS APIs. But for code that runs in a separate
9
+ executor process, an RPC scheme Executor Process Control (EPC) is used. The
10
+ controller process invokes RPCs in the target or executor process to allocate
11
+ memory and then when the code is generated, all the section contents are
12
+ transferred through finalize calls."
5
13
sitemap : false
6
14
permalink : blogs/gsoc22_ghosh_experience_blog/
7
15
---
8
16
9
- # Shared Memory Based JITLink Memory Manager
10
-
11
- ** Developer:** Anubhab Ghosh (Computer Science and Engineering, Indian Institute
12
- of Information Technology, Kalyani, India)
13
-
14
- ** Mentors:** Stefan Gränitz (Freelance Compiler Developer, Berlin, Deutschland),
15
- Lang Hames (Apple), Vassil Vassilev (Princeton University/CERN)
16
-
17
- ** Funding:** [ Google Summer of Code 2022] ( https://summerofcode.withgoogle.com/ )
18
-
19
- ---
20
-
21
- ** Contact me!**
22
-
23
-
24
-
25
- Github Username: [ argentite] ( https://github.com/argentite )
26
-
27
- ** Link to GSoC project proposal:** [ Anubhab_Ghosh_Proposal_GSoC_2022] ( https://compiler-research.org/assets/docs/Anubhab_Ghosh_Proposal_2022.pdf )
28
-
29
- ** Link to GSoC project proposal:** [ Anubhab_Ghosh_Final_Report_GSoC_2022] ( https://compiler-research.org/assets/docs/Anubhab_Ghosh_GSoC2022_Report.pdf )
30
-
31
- ---
32
-
33
-
34
- ## Overview of the Project
17
+ ### Overview of the Project
35
18
LLVM JIT APIs include JITLink, a just-in-time linker that links together objects
36
19
code units directly in memory and executes them. It uses the
37
20
JITLinkMemoryManager interface to allocate and manage memory for the generated
@@ -42,14 +25,14 @@ controller process invokes RPCs in the target or executor process to allocate
42
25
memory and then when the code is generated, all the section contents are
43
26
transferred through finalize calls.
44
27
45
- ### Shared Memory
28
+ #### Shared Memory
46
29
The main problem was that EPC runs on top of file descriptor streams like Unix
47
30
pipes or TCP sockets. As all the generated code and data bytes are transferred
48
31
over the EPC this has some overhead that could be avoided by using shared
49
32
memory. If the two processes share the same physical memory pages then we can
50
33
completely avoid extra memory copying.
51
34
52
- ### Small code model
35
+ #### Small code model
53
36
While we are at it, another goal was to introduce a simple slab-based memory
54
37
manager. It would allocate a large chunk of memory in the beginning from the
55
38
executor process and allocate smaller blocks from that entirely at the
@@ -97,9 +80,9 @@ Small code model is the default for most compilations so this is actually
97
80
required to load ordinary precompiled code, e.g., from existing static archives.
98
81
99
82
100
- ## My Approach
83
+ ### My Approach
101
84
102
- ### Memory Mappers
85
+ #### Memory Mappers
103
86
I introduced a new ` MemoryMapper ` abstraction for interacting with OS APIs at
104
87
different situations. It has separate implementations based on whether the code
105
88
will be executed in the same or different process. The ` InProcessMemoryMapper `
@@ -116,7 +99,7 @@ address. Once JITLink has written the code to those mapped addresses, they are
116
99
now already in place in the executor processes so finalization is just a matter
117
100
of sending the memory protections.
118
101
119
- ### Slab-based allocator
102
+ #### Slab-based allocator
120
103
Furthermore, I developed a slab-based memory allocator for JITLink, reserving a
121
104
large region of memory in the address space of the target process on the first
122
105
allocation. All subsequent allocations result in sub-regions of that to be
@@ -125,7 +108,7 @@ involvement. Furthermore as our all the allocation are from a contiguous memory
125
108
region, it also guarantees that JIT’d memory satisfies the layout constraints
126
109
required by the small code model.
127
110
128
- ### Concurrency problems
111
+ #### Concurrency problems
129
112
After the implmentation, I tried JIT linking the CPython interpreter to
130
113
benchmark the implementation. We discovered that our overall CPU execution time
131
114
decreased by 45% but somewhat paradoxically clock time increased by 45%. In
@@ -149,9 +132,33 @@ For a more detailed description and all the patches, please consult my
149
132
[ GSoC final report] ( https://compiler-research.org/assets/docs/Anubhab_Ghosh_GSoC2022_Report.pdf ) .
150
133
151
134
152
- ## Acknowledgements
135
+ ### Acknowledgements
153
136
154
137
I would like to share my gratitude for the LLVM community members and my mentors
155
138
Stefan Gränitz, Lang Hames, and Vassil Vassilev, who shared their suggestions
156
139
during the project development. I hope that this project will find its place in
157
140
many applications.
141
+
142
+ ---
143
+
144
+ ### Credits
145
+
146
+ ** Developer:** Anubhab Ghosh (Computer Science and Engineering, Indian Institute
147
+ of Information Technology, Kalyani, India)
148
+
149
+ ** Mentors:** Stefan Gränitz (Freelance Compiler Developer, Berlin, Deutschland),
150
+ Lang Hames (Apple), Vassil Vassilev (Princeton University/CERN)
151
+
152
+ ** Funding:** [ Google Summer of Code 2022] ( https://summerofcode.withgoogle.com/ )
153
+
154
+ ---
155
+
156
+ ** Contact me!**
157
+
158
+
159
+
160
+ Github Username: [ argentite] ( https://github.com/argentite )
161
+
162
+ ** Link to GSoC project proposal:** [ Anubhab_Ghosh_Proposal_GSoC_2022] ( https://compiler-research.org/assets/docs/Anubhab_Ghosh_Proposal_2022.pdf )
163
+
164
+ ** Link to GSoC project proposal:** [ Anubhab_Ghosh_Final_Report_GSoC_2022] ( https://compiler-research.org/assets/docs/Anubhab_Ghosh_GSoC2022_Report.pdf )
0 commit comments