@@ -106,18 +106,18 @@ namespace node {
106106namespace  {
107107
108108struct  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 ;
113112};
114113
115114static  const  size_t  hps = 2L  * 1024  * 1024 ;
116115
117116template  <typename ... Args>
118- inline  void  Debug (Args&&... args) {
117+ inline  void  Debug (std::string fmt,  Args&&... args) {
119118  node::Debug (&per_process::enabled_debug_list,
120119              DebugCategory::HUGEPAGES,
120+               (std::string (" Hugepages info: "  ) + fmt).c_str (),
121121              std::forward<Args>(args)...);
122122}
123123
@@ -145,9 +145,9 @@ inline uintptr_t hugepage_align_down(uintptr_t addr) {
145145#endif   //  defined(__FreeBSD__)
146146
147147struct  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) ;
151151  std::string exename;
152152};
153153
@@ -175,11 +175,8 @@ int FindMapping(struct dl_phdr_info* info, size_t, void* data) {
175175
176176struct  text_region  FindNodeTextRegion () {
177177  struct  text_region  nregion;
178-   nregion.found_text_region  = false ;
179178#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;
183180  uintptr_t  lpstub_start = reinterpret_cast <uintptr_t >(&__start_lpstub);
184181
185182#if  defined(__FreeBSD__)
@@ -196,29 +193,28 @@ struct text_region FindNodeTextRegion() {
196193#endif   //  defined(__FreeBSD__)
197194
198195  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 "  ,
200197          reinterpret_cast <void *>(dl_params.start ),
201198          reinterpret_cast <void *>(dl_params.reference_sym ),
202199          reinterpret_cast <void *>(dl_params.end ));
203200
204201    dl_params.start  = dl_params.reference_sym ;
205202    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 "  ,
207204            reinterpret_cast <void *>(lpstub_start));
208205      dl_params.end  = lpstub_start;
209206    }
210207
211208    if  (dl_params.start  < dl_params.end ) {
212209      char * from = reinterpret_cast <char *>(hugepage_align_up (dl_params.start ));
213210      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);
215212      if  (from < to) {
216213        size_t  pagecount = (to - from) / hps;
217214        if  (pagecount > 0 ) {
218215          nregion.found_text_region  = true ;
219216          nregion.from  = from;
220217          nregion.to  = to;
221-           nregion.total_hugepages  = pagecount;
222218        }
223219      }
224220    }
@@ -249,7 +245,6 @@ struct text_region FindNodeTextRegion() {
249245        nregion.found_text_region  = true ;
250246        nregion.from  = start;
251247        nregion.to  = end;
252-         nregion.total_hugepages  = esize / hps;
253248        break ;
254249      }
255250
@@ -258,7 +253,7 @@ struct text_region FindNodeTextRegion() {
258253    }
259254  }
260255#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 );
262257  return  nregion;
263258}
264259
0 commit comments