Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: clean up large pages code #33255

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions src/large_pages/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ namespace node {
namespace {

struct text_region {
char* from;
char* to;
int total_hugepages;
bool found_text_region;
char* from = nullptr;
char* to = nullptr;
bool found_text_region = false;
};

static const size_t hps = 2L * 1024 * 1024;

template <typename... Args>
inline void Debug(Args&&... args) {
inline void Debug(std::string fmt, Args&&... args) {
node::Debug(&per_process::enabled_debug_list,
DebugCategory::HUGEPAGES,
(std::string("Hugepages info: ") + fmt).c_str(),
std::forward<Args>(args)...);
jasnell marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -145,10 +145,10 @@ inline uintptr_t hugepage_align_down(uintptr_t addr) {
#endif // defined(__FreeBSD__)

struct dl_iterate_params {
uintptr_t start;
uintptr_t end;
uintptr_t reference_sym;
std::string exename;
uintptr_t start = 0;
uintptr_t end = 0;
uintptr_t reference_sym = reinterpret_cast<uintptr_t>(&__node_text_start);
std::string exename = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string exename = "";
std::string exename;

(it's superfluous for std::string.)

};

int FindMapping(struct dl_phdr_info* info, size_t, void* data) {
Expand All @@ -175,11 +175,8 @@ int FindMapping(struct dl_phdr_info* info, size_t, void* data) {

struct text_region FindNodeTextRegion() {
struct text_region nregion;
nregion.found_text_region = false;
#if defined(__linux__) || defined(__FreeBSD__)
dl_iterate_params dl_params = {
0, 0, reinterpret_cast<uintptr_t>(&__node_text_start), ""
};
dl_iterate_params dl_params;
uintptr_t lpstub_start = reinterpret_cast<uintptr_t>(&__start_lpstub);

#if defined(__FreeBSD__)
Expand All @@ -196,29 +193,28 @@ struct text_region FindNodeTextRegion() {
#endif // defined(__FreeBSD__)

if (dl_iterate_phdr(FindMapping, &dl_params) == 1) {
Debug("Hugepages info: start: %p - sym: %p - end: %p\n",
Debug("start: %p - sym: %p - end: %p\n",
reinterpret_cast<void*>(dl_params.start),
reinterpret_cast<void*>(dl_params.reference_sym),
reinterpret_cast<void*>(dl_params.end));

dl_params.start = dl_params.reference_sym;
if (lpstub_start > dl_params.start && lpstub_start <= dl_params.end) {
Debug("Hugepages info: Trimming end for lpstub: %p\n",
Debug("Trimming end for lpstub: %p\n",
reinterpret_cast<void*>(lpstub_start));
dl_params.end = lpstub_start;
}

if (dl_params.start < dl_params.end) {
char* from = reinterpret_cast<char*>(hugepage_align_up(dl_params.start));
char* to = reinterpret_cast<char*>(hugepage_align_down(dl_params.end));
Debug("Hugepages info: Aligned range is %p - %p\n", from, to);
Debug("Aligned range is %p - %p\n", from, to);
if (from < to) {
size_t pagecount = (to - from) / hps;
if (pagecount > 0) {
nregion.found_text_region = true;
nregion.from = from;
nregion.to = to;
nregion.total_hugepages = pagecount;
}
}
}
Expand Down Expand Up @@ -249,7 +245,6 @@ struct text_region FindNodeTextRegion() {
nregion.found_text_region = true;
nregion.from = start;
nregion.to = end;
nregion.total_hugepages = esize / hps;
break;
}

Expand All @@ -258,7 +253,7 @@ struct text_region FindNodeTextRegion() {
}
}
#endif
Debug("Hugepages info: Found %d huge pages\n", nregion.total_hugepages);
Debug("Found %d huge pages\n", (nregion.to - nregion.from) / hps);
return nregion;
}

Expand Down