Skip to content

Commit aeaa82f

Browse files
laramielcopybara-github
authored andcommitted
Attempt to detect hugepage settings when running multi_read_benchmark under __linux__
PiperOrigin-RevId: 715097219 Change-Id: I23dd6e13a66313b54ad37143f593aa597d113dab
1 parent eda046b commit aeaa82f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

tensorstore/internal/benchmark/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ tensorstore_cc_binary(
148148
"//tensorstore/internal/json_binding",
149149
"//tensorstore/internal/metrics",
150150
"//tensorstore/internal/metrics:metadata",
151+
"//tensorstore/internal/os:file_util",
151152
"//tensorstore/util:future",
152153
"//tensorstore/util:json_absl_flag",
153154
"//tensorstore/util:result",
@@ -159,6 +160,7 @@ tensorstore_cc_binary(
159160
"@com_google_absl//absl/log:absl_check",
160161
"@com_google_absl//absl/log:absl_log",
161162
"@com_google_absl//absl/status",
163+
"@com_google_absl//absl/strings",
162164
"@com_google_absl//absl/strings:str_format",
163165
"@com_google_absl//absl/strings:string_view",
164166
"@com_google_absl//absl/synchronization",

tensorstore/internal/benchmark/multi_read_benchmark.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ bazel run -c opt \
4646
#include "absl/log/absl_log.h"
4747
#include "absl/log/log.h"
4848
#include "absl/status/status.h"
49+
#include "absl/strings/match.h"
4950
#include "absl/strings/str_format.h"
5051
#include "absl/strings/string_view.h"
5152
#include "absl/synchronization/mutex.h"
5253
#include "absl/time/clock.h"
5354
#include "absl/time/time.h"
54-
#include <nlohmann/json_fwd.hpp>
55+
#include <nlohmann/json.hpp>
5556
#include "tensorstore/array.h"
5657
#include "tensorstore/context.h"
5758
#include "absl/flags/parse.h"
@@ -60,6 +61,7 @@ bazel run -c opt \
6061
#include "tensorstore/internal/json_binding/std_array.h" // IWYU pragma: keep
6162
#include "tensorstore/internal/metrics/metadata.h"
6263
#include "tensorstore/internal/metrics/value.h"
64+
#include "tensorstore/internal/os/file_util.h"
6365
#include "tensorstore/open.h"
6466
#include "tensorstore/open_mode.h"
6567
#include "tensorstore/spec.h"
@@ -304,6 +306,26 @@ void RunBenchmark(tensorstore::Context::Spec context_spec,
304306
}
305307
}
306308
}
309+
void CheckTransparentHugePages() {
310+
#if defined(__linux__)
311+
auto hugepages = internal_os::ReadAllToString(
312+
"/sys/kernel/mm/transparent_hugepage/enabled");
313+
if (hugepages.ok() && absl::StrContains(hugepages.value(), "[always]")) {
314+
return;
315+
} else if (hugepages.ok()) {
316+
ABSL_LOG(WARNING)
317+
<< "See https://docs.kernel.org/admin-guide/mm/transhuge.html\n"
318+
"Transparent huge pages should be set to \"always\"; the current "
319+
"setting of \""
320+
<< hugepages.value() << "\" may cause reduced read performance.";
321+
} else {
322+
ABSL_LOG(INFO)
323+
<< "See https://docs.kernel.org/admin-guide/mm/transhuge.html\n"
324+
"Transparent huge page settings are unknown; "
325+
"/sys/kernel/mm/transparent_hugepage/enabled is not readable.";
326+
}
327+
#endif
328+
}
307329

308330
void Run(int argc, char** argv) {
309331
ABSL_CHECK(absl::GetFlag(FLAGS_repeat_reads) > 0);
@@ -322,6 +344,8 @@ void Run(int argc, char** argv) {
322344
ABSL_QCHECK(!specs.empty()) << "Empty config; supply non-empty --read_config "
323345
"or pass specs on the command line.";
324346

347+
CheckTransparentHugePages();
348+
325349
if (absl::GetFlag(FLAGS_ith_spec) >= 0) {
326350
ABSL_LOG(INFO) << "Reading only spec #" << absl::GetFlag(FLAGS_ith_spec);
327351
specs = {specs[absl::GetFlag(FLAGS_ith_spec)]};

0 commit comments

Comments
 (0)