| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e097980 commit 5ea3d60
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -854,7 +854,8 @@ | |||
| 854 | 854 | ], | |
| 855 | 855 | }], | |
| 856 | 856 | [ 'OS in "linux freebsd mac" and ' | |
| 857 | - 'target_arch=="x64"', { | ||
| 857 | + 'target_arch=="x64" and ' | ||
| 858 | + 'node_target_type=="executable"', { | ||
| 858 | 859 | 'defines': [ 'NODE_ENABLE_LARGE_CODE_PAGES=1' ], | |
| 859 | 860 | 'sources': [ | |
| 860 | 861 | 'src/large_pages/node_large_page.cc', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -317,22 +317,6 @@ | |||
| 317 | 317 | 'ldflags': [ '-Wl,-z,relro', | |
| 318 | 318 | '-Wl,-z,now' ] | |
| 319 | 319 | }], | |
| 320 | - [ 'OS=="linux" and ' | ||
| 321 | - 'target_arch=="x64" and ' | ||
| 322 | - 'llvm_version=="0.0"', { | ||
| 323 | - 'ldflags': [ | ||
| 324 | - '-Wl,-T', | ||
| 325 | - '<!(echo "$(pwd)/src/large_pages/ld.implicit.script")', | ||
| 326 | - ] | ||
| 327 | - }], | ||
| 328 | - [ 'OS=="linux" and ' | ||
| 329 | - 'target_arch=="x64" and ' | ||
| 330 | - 'llvm_version!="0.0"', { | ||
| 331 | - 'ldflags': [ | ||
| 332 | - '-Wl,-T', | ||
| 333 | - '<!(echo "$(pwd)/src/large_pages/ld.implicit.script.lld")', | ||
| 334 | - ] | ||
| 335 | - }], | ||
| 336 | 320 | [ 'node_use_openssl=="true"', { | |
| 337 | 321 | 'defines': [ 'HAVE_OPENSSL=1' ], | |
| 338 | 322 | 'conditions': [ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,11 @@ | |||
| 65 | 65 | // Use madvise with MADV_HUGEPAGE to use Anonymous 2M Pages | |
| 66 | 66 | // If successful copy the code there and unmap the original region. | |
| 67 | 67 | ||
| 68 | - extern char __nodetext; | ||
| 68 | + #if defined(__linux__) | ||
| 69 | + extern "C" { | ||
| 70 | + extern char __executable_start; | ||
| 71 | + } // extern "C" | ||
| 72 | + #endif // defined(__linux__) | ||
| 69 | 73 | ||
| 70 | 74 | namespace node { | |
| 71 | 75 | ||
@@ -116,17 +120,6 @@ static struct text_region FindNodeTextRegion() { | |||
| 116 | 120 | return nregion; | |
| 117 | 121 | } | |
| 118 | 122 | ||
| 119 | - std::string exename; | ||
| 120 | - { | ||
| 121 | - char selfexe[PATH_MAX]; | ||
| 122 | - | ||
| 123 | - size_t size = sizeof(selfexe); | ||
| 124 | - if (uv_exepath(selfexe, &size)) | ||
| 125 | - return nregion; | ||
| 126 | - | ||
| 127 | - exename = std::string(selfexe, size); | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | 123 | while (std::getline(ifs, map_line)) { | |
| 131 | 124 | std::istringstream iss(map_line); | |
| 132 | 125 | iss >> std::hex >> start; | |
@@ -136,26 +129,42 @@ static struct text_region FindNodeTextRegion() { | |||
| 136 | 129 | iss >> offset; | |
| 137 | 130 | iss >> dev; | |
| 138 | 131 | iss >> inode; | |
| 139 | - if (inode != 0) { | ||
| 140 | - std::string pathname; | ||
| 141 | - iss >> pathname; | ||
| 142 | - if (pathname == exename && permission == "r-xp") { | ||
| 143 | - uintptr_t ntext = reinterpret_cast<uintptr_t>(&__nodetext); | ||
| 144 | - if (ntext >= start && ntext < end) { | ||
| 145 | - char* from = reinterpret_cast<char*>(hugepage_align_up(ntext)); | ||
| 146 | - char* to = reinterpret_cast<char*>(hugepage_align_down(end)); | ||
| 147 | - | ||
| 148 | - if (from < to) { | ||
| 149 | - size_t size = to - from; | ||
| 150 | - nregion.found_text_region = true; | ||
| 151 | - nregion.from = from; | ||
| 152 | - nregion.to = to; | ||
| 153 | - nregion.total_hugepages = size / hps; | ||
| 154 | - } | ||
| 155 | - break; | ||
| 156 | - } | ||
| 157 | - } | ||
| 158 | - } | ||
| 132 | + | ||
| 133 | + if (inode == 0) | ||
| 134 | + continue; | ||
| 135 | + | ||
| 136 | + std::string pathname; | ||
| 137 | + iss >> pathname; | ||
| 138 | + | ||
| 139 | + if (start != reinterpret_cast<uintptr_t>(&__executable_start)) | ||
| 140 | + continue; | ||
| 141 | + | ||
| 142 | + // The next line is our .text section. | ||
| 143 | + if (!std::getline(ifs, map_line)) | ||
| 144 | + break; | ||
| 145 | + | ||
| 146 | + iss = std::istringstream(map_line); | ||
| 147 | + iss >> std::hex >> start; | ||
| 148 | + iss >> dash; | ||
| 149 | + iss >> std::hex >> end; | ||
| 150 | + iss >> permission; | ||
| 151 | + | ||
| 152 | + if (permission != "r-xp") | ||
| 153 | + break; | ||
| 154 | + | ||
| 155 | + char* from = reinterpret_cast<char*>(hugepage_align_up(start)); | ||
| 156 | + char* to = reinterpret_cast<char*>(hugepage_align_down(end)); | ||
| 157 | + | ||
| 158 | + if (from >= to) | ||
| 159 | + break; | ||
| 160 | + | ||
| 161 | + size_t size = to - from; | ||
| 162 | + nregion.found_text_region = true; | ||
| 163 | + nregion.from = from; | ||
| 164 | + nregion.to = to; | ||
| 165 | + nregion.total_hugepages = size / hps; | ||
| 166 | + | ||
| 167 | + break; | ||
| 159 | 168 | } | |
| 160 | 169 | ||
| 161 | 170 | ifs.close(); | |
@@ -408,14 +417,12 @@ int MapStaticCodeToLargePages() { | |||
| 408 | 417 | return -1; | |
| 409 | 418 | } | |
| 410 | 419 | ||
| 411 | - #if defined(__linux__) || defined(__FreeBSD__) | ||
| 412 | - if (r.from > reinterpret_cast<void*>(&MoveTextRegionToLargePages)) | ||
| 413 | - return MoveTextRegionToLargePages(r); | ||
| 420 | + #if defined(__FreeBSD__) | ||
| 421 | + if (r.from < reinterpret_cast<void*>(&MoveTextRegionToLargePages)) | ||
| 422 | + return -1; | ||
| 423 | + #endif | ||
| 414 | 424 | ||
| 415 | - return -1; | ||
| 416 | - #elif defined(__APPLE__) | ||
| 417 | 425 | return MoveTextRegionToLargePages(r); | |
| 418 | - #endif | ||
| 419 | 426 | } | |
| 420 | 427 | ||
| 421 | 428 | bool IsLargePagesEnabled() { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments