Skip to content

Commit

Permalink
Attempt to detect hugepage settings when running multi_read_benchmark…
Browse files Browse the repository at this point in the history
… under __linux__

PiperOrigin-RevId: 715097219
Change-Id: I23dd6e13a66313b54ad37143f593aa597d113dab
  • Loading branch information
laramiel authored and copybara-github committed Jan 13, 2025
1 parent eda046b commit aeaa82f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tensorstore/internal/benchmark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ tensorstore_cc_binary(
"//tensorstore/internal/json_binding",
"//tensorstore/internal/metrics",
"//tensorstore/internal/metrics:metadata",
"//tensorstore/internal/os:file_util",
"//tensorstore/util:future",
"//tensorstore/util:json_absl_flag",
"//tensorstore/util:result",
Expand All @@ -159,6 +160,7 @@ tensorstore_cc_binary(
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/synchronization",
Expand Down
26 changes: 25 additions & 1 deletion tensorstore/internal/benchmark/multi_read_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ bazel run -c opt \
#include "absl/log/absl_log.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include <nlohmann/json_fwd.hpp>
#include <nlohmann/json.hpp>
#include "tensorstore/array.h"
#include "tensorstore/context.h"
#include "absl/flags/parse.h"
Expand All @@ -60,6 +61,7 @@ bazel run -c opt \
#include "tensorstore/internal/json_binding/std_array.h" // IWYU pragma: keep
#include "tensorstore/internal/metrics/metadata.h"
#include "tensorstore/internal/metrics/value.h"
#include "tensorstore/internal/os/file_util.h"
#include "tensorstore/open.h"
#include "tensorstore/open_mode.h"
#include "tensorstore/spec.h"
Expand Down Expand Up @@ -304,6 +306,26 @@ void RunBenchmark(tensorstore::Context::Spec context_spec,
}
}
}
void CheckTransparentHugePages() {
#if defined(__linux__)
auto hugepages = internal_os::ReadAllToString(
"/sys/kernel/mm/transparent_hugepage/enabled");
if (hugepages.ok() && absl::StrContains(hugepages.value(), "[always]")) {
return;
} else if (hugepages.ok()) {
ABSL_LOG(WARNING)
<< "See https://docs.kernel.org/admin-guide/mm/transhuge.html\n"
"Transparent huge pages should be set to \"always\"; the current "
"setting of \""
<< hugepages.value() << "\" may cause reduced read performance.";
} else {
ABSL_LOG(INFO)
<< "See https://docs.kernel.org/admin-guide/mm/transhuge.html\n"
"Transparent huge page settings are unknown; "
"/sys/kernel/mm/transparent_hugepage/enabled is not readable.";
}
#endif
}

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

CheckTransparentHugePages();

if (absl::GetFlag(FLAGS_ith_spec) >= 0) {
ABSL_LOG(INFO) << "Reading only spec #" << absl::GetFlag(FLAGS_ith_spec);
specs = {specs[absl::GetFlag(FLAGS_ith_spec)]};
Expand Down

0 comments on commit aeaa82f

Please sign in to comment.