@@ -106,18 +106,18 @@ namespace node { |
106 | 106 | namespace { |
107 | 107 |
|
108 | 108 | struct text_region { |
109 | | - char* from; |
110 | | - char* to; |
111 | | - int total_hugepages; |
112 | | - bool found_text_region; |
| 109 | + char* from = nullptr; |
| 110 | + char* to = nullptr; |
| 111 | + bool found_text_region = false; |
113 | 112 | }; |
114 | 113 |
|
115 | 114 | static const size_t hps = 2L * 1024 * 1024; |
116 | 115 |
|
117 | 116 | template <typename... Args> |
118 | | -inline void Debug(Args&&... args) { |
| 117 | +inline void Debug(std::string fmt, Args&&... args) { |
119 | 118 | node::Debug(&per_process::enabled_debug_list, |
120 | 119 | DebugCategory::HUGEPAGES, |
| 120 | + (std::string("Hugepages info: ") + fmt).c_str(), |
121 | 121 | std::forward<Args>(args)...); |
122 | 122 | } |
123 | 123 |
|
@@ -145,9 +145,9 @@ inline uintptr_t hugepage_align_down(uintptr_t addr) { |
145 | 145 | #endif // defined(__FreeBSD__) |
146 | 146 |
|
147 | 147 | struct dl_iterate_params { |
148 | | - uintptr_t start; |
149 | | - uintptr_t end; |
150 | | - uintptr_t reference_sym; |
| 148 | + uintptr_t start = 0; |
| 149 | + uintptr_t end = 0; |
| 150 | + uintptr_t reference_sym = reinterpret_cast<uintptr_t>(&__node_text_start); |
151 | 151 | std::string exename; |
152 | 152 | }; |
153 | 153 |
|
@@ -175,11 +175,8 @@ int FindMapping(struct dl_phdr_info* info, size_t, void* data) { |
175 | 175 |
|
176 | 176 | struct text_region FindNodeTextRegion() { |
177 | 177 | struct text_region nregion; |
178 | | - nregion.found_text_region = false; |
179 | 178 | #if defined(__linux__) || defined(__FreeBSD__) |
180 | | - dl_iterate_params dl_params = { |
181 | | - 0, 0, reinterpret_cast<uintptr_t>(&__node_text_start), "" |
182 | | - }; |
| 179 | + dl_iterate_params dl_params; |
183 | 180 | uintptr_t lpstub_start = reinterpret_cast<uintptr_t>(&__start_lpstub); |
184 | 181 |
|
185 | 182 | #if defined(__FreeBSD__) |
@@ -196,29 +193,28 @@ struct text_region FindNodeTextRegion() { |
196 | 193 | #endif // defined(__FreeBSD__) |
197 | 194 |
|
198 | 195 | if (dl_iterate_phdr(FindMapping, &dl_params) == 1) { |
199 | | - Debug("Hugepages info: start: %p - sym: %p - end: %p\n", |
| 196 | + Debug("start: %p - sym: %p - end: %p\n", |
200 | 197 | reinterpret_cast<void*>(dl_params.start), |
201 | 198 | reinterpret_cast<void*>(dl_params.reference_sym), |
202 | 199 | reinterpret_cast<void*>(dl_params.end)); |
203 | 200 |
|
204 | 201 | dl_params.start = dl_params.reference_sym; |
205 | 202 | if (lpstub_start > dl_params.start && lpstub_start <= dl_params.end) { |
206 | | - Debug("Hugepages info: Trimming end for lpstub: %p\n", |
| 203 | + Debug("Trimming end for lpstub: %p\n", |
207 | 204 | reinterpret_cast<void*>(lpstub_start)); |
208 | 205 | dl_params.end = lpstub_start; |
209 | 206 | } |
210 | 207 |
|
211 | 208 | if (dl_params.start < dl_params.end) { |
212 | 209 | char* from = reinterpret_cast<char*>(hugepage_align_up(dl_params.start)); |
213 | 210 | char* to = reinterpret_cast<char*>(hugepage_align_down(dl_params.end)); |
214 | | - Debug("Hugepages info: Aligned range is %p - %p\n", from, to); |
| 211 | + Debug("Aligned range is %p - %p\n", from, to); |
215 | 212 | if (from < to) { |
216 | 213 | size_t pagecount = (to - from) / hps; |
217 | 214 | if (pagecount > 0) { |
218 | 215 | nregion.found_text_region = true; |
219 | 216 | nregion.from = from; |
220 | 217 | nregion.to = to; |
221 | | - nregion.total_hugepages = pagecount; |
222 | 218 | } |
223 | 219 | } |
224 | 220 | } |
@@ -249,7 +245,6 @@ struct text_region FindNodeTextRegion() { |
249 | 245 | nregion.found_text_region = true; |
250 | 246 | nregion.from = start; |
251 | 247 | nregion.to = end; |
252 | | - nregion.total_hugepages = esize / hps; |
253 | 248 | break; |
254 | 249 | } |
255 | 250 |
|
@@ -258,7 +253,7 @@ struct text_region FindNodeTextRegion() { |
258 | 253 | } |
259 | 254 | } |
260 | 255 | #endif |
261 | | - Debug("Hugepages info: Found %d huge pages\n", nregion.total_hugepages); |
| 256 | + Debug("Found %d huge pages\n", (nregion.to - nregion.from) / hps); |
262 | 257 | return nregion; |
263 | 258 | } |
264 | 259 |
|
|