diff options
author | James Addison <jay@jp-hosting.net> | 2021-01-28 22:40:48 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2021-02-28 16:39:53 +0300 |
commit | daad7bbd3447f04f50af24dd487563c60bc1a9dd (patch) | |
tree | 7213e2ed59fa5ac08a0ba1dcca51df4568edab5c /src | |
parent | 01773ab614443998e215348a221cbd5fb3683db1 (diff) |
src: adjust THP sysfs config token retrieval and file closure
PR-URL: https://github.com/nodejs/node/pull/37187
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/large_pages/node_large_page.cc | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/large_pages/node_large_page.cc b/src/large_pages/node_large_page.cc index 22810ef08fb..eb546c581a1 100644 --- a/src/large_pages/node_large_page.cc +++ b/src/large_pages/node_large_page.cc @@ -258,23 +258,21 @@ struct text_region FindNodeTextRegion() { #if defined(__linux__) bool IsTransparentHugePagesEnabled() { - std::ifstream ifs; - // File format reference: // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/huge_memory.c?id=13391c60da3308ed9980de0168f74cce6c62ac1d#n163 - ifs.open("/sys/kernel/mm/transparent_hugepage/enabled"); - if (!ifs) { + const char* filename = "/sys/kernel/mm/transparent_hugepage/enabled"; + std::ifstream config_stream(filename, std::ios::in); + if (!config_stream.good()) { PrintWarning("could not open /sys/kernel/mm/transparent_hugepage/enabled"); return false; } - std::string always, madvise; - if (ifs.is_open()) { - ifs >> always >> madvise; - } - ifs.close(); - - return always == "[always]" || madvise == "[madvise]"; + std::string token; + config_stream >> token; + if ("[always]" == token) return true; + config_stream >> token; + if ("[madvise]" == token) return true; + return false; } #elif defined(__FreeBSD__) bool IsSuperPagesEnabled() { |