Skip to content

Avoid allocation when storing jemalloc profile name#87149

Merged
azat merged 4 commits intomasterfrom
no-allocation-on-flush
Sep 21, 2025
Merged

Avoid allocation when storing jemalloc profile name#87149
azat merged 4 commits intomasterfrom
no-allocation-on-flush

Conversation

@antonio2368
Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

We cannot allocate in MemoryTracker in all cases.

https://github.com/ClickHouse/clickhouse-private/issues/38064

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh Bot commented Sep 16, 2025

Workflow [PR], commit [0ba634a]

Summary:

job_name test_name status info comment
AST fuzzer (amd_debug) failure
Task failed: $?=1 FAIL
AST fuzzer (arm_asan) failure
Task failed: $?=1 FAIL
AST fuzzer (amd_tsan) failure
Task failed: $?=1 FAIL
AST fuzzer (amd_msan) failure
Task failed: $?=1 FAIL
AST fuzzer (amd_ubsan) failure
Task failed: $?=1 FAIL
BuzzHouse (amd_debug) failure
Task failed: $?=1 FAIL
BuzzHouse (arm_asan) failure
Task failed: $?=1 FAIL
BuzzHouse (amd_tsan) failure
Task failed: $?=1 FAIL
BuzzHouse (amd_msan) failure
Task failed: $?=1 FAIL
BuzzHouse (amd_ubsan) failure
Task failed: $?=1 FAIL

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 16, 2025
Comment thread src/Common/Jemalloc.cpp
Comment thread src/Common/Jemalloc.cpp
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
Copy link
Copy Markdown
Member

@azat azat left a comment

Choose a reason for hiding this comment

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

LGTM

Also, it looks like we can update the callers of flushProfile, i.e.

$ git di
diff --git a/src/Coordination/FourLetterCommand.cpp b/src/Coordination/FourLetterCommand.cpp
index e7ed119c0cc..02e5d4d1daf 100644
--- a/src/Coordination/FourLetterCommand.cpp
+++ b/src/Coordination/FourLetterCommand.cpp
@@ -652,8 +652,8 @@ String JemallocDumpStats::run()

 String JemallocFlushProfile::run()
 {
-    Jemalloc::flushProfile("/tmp/jemalloc_keeper");
-    return std::string{Jemalloc::getLastFlushProfileForThread()};
+    auto profile_path = Jemalloc::flushProfile("/tmp/jemalloc_keeper");
+    return profile_path;
 }

 String JemallocEnableProfile::run()
diff --git a/src/Interpreters/InterpreterSystemQuery.cpp b/src/Interpreters/InterpreterSystemQuery.cpp
index df806db9eee..a137483b8a0 100644
--- a/src/Interpreters/InterpreterSystemQuery.cpp
+++ b/src/Interpreters/InterpreterSystemQuery.cpp
@@ -915,10 +915,9 @@ BlockIO InterpreterSystemQuery::execute()
         case Type::JEMALLOC_FLUSH_PROFILE:
         {
             getContext()->checkAccess(AccessType::SYSTEM_JEMALLOC);
-            Jemalloc::flushProfile(query.jemalloc_profile_path.empty() ? "/tmp/jemalloc_clickhouse" : query.jemalloc_profile_path);
-            auto filename = Jemalloc::getLastFlushProfileForThread();
+            auto profile_path = Jemalloc::flushProfile(query.jemalloc_profile_path.empty() ? "/tmp/jemalloc_clickhouse" : query.jemalloc_profile_path);
             auto col = ColumnString::create();
-            col->insertData(filename.data(), filename.size());
+            col->insertData(profile_path.data(), profile_path.size());
             Columns columns;
             columns.emplace_back(std::move(col));
             Chunk chunk(std::move(columns), 1);

@azat
Copy link
Copy Markdown
Member

azat commented Sep 21, 2025

I need this changes to avoid conflicts, merging.

CI is unrelated (fixed in #87339)

@azat azat added this pull request to the merge queue Sep 21, 2025
Merged via the queue into master with commit 19a5a49 Sep 21, 2025
112 of 123 checks passed
@azat azat deleted the no-allocation-on-flush branch September 21, 2025 16:52
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants