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