Skip to content

Make flushing trace_log under MSan 25% faster by disabling frame pointers for demangling - #91579

Merged
azat merged 4 commits into
ClickHouse:masterfrom
azat:disable-msan-for-demangle
Dec 9, 2025
Merged

azat merged 4 commits into
ClickHouse:masterfrom
azat:disable-msan-for-demangle

Conversation

@azat

@azat azat commented Dec 5, 2025

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Refs: #91410

@azat
azat requested a review from Algunenano December 5, 2025 14:18
@clickhouse-gh

clickhouse-gh Bot commented Dec 5, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f7fd715]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_msan, parallel) failure
00816_long_concurrent_alter_column FAIL cidb, issue
Integration tests (amd_asan, db disk, old analyzer, 2/6) failure
test_dotnet_client/test.py::test_dotnet_client FAIL cidb
BuzzHouse (amd_debug) failure
Logical error: Inconsistent AST formatting in A: the query: FAIL cidb
Integration tests (amd_asan, db disk, old analyzer, 3/6) error
test_scheduler_cpu_preemptive/test.py::test_cpu_time_fairness[fixed_longer_prd] FAIL cidb
test_restore_replica/test.py::test_fix_metadata_version_on_attach_part_after_restore FAIL cidb, issue
OOM in dmesg FAIL cidb
AST fuzzer (amd_ubsan) error

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Dec 5, 2025
@Algunenano Algunenano self-assigned this Dec 5, 2025
Comment thread tests/msan_ignorelist.txt Resolved

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's see how it goes. Do you think it'd be an option to keep a small-ish cache of symbol -> demangled symbol? I'd expect most of the symbols, specially at the top of the tree, to appear over and over

…n for __cxa_demangle

I've tested and demangling takes 50% of time, for 12K entries, 3.6s w/
demangle and 1.8-4sec w/o
@azat
azat force-pushed the disable-msan-for-demangle branch from 81721fa to b11cc93 Compare December 5, 2025 14:48
@azat

azat commented Dec 5, 2025

Copy link
Copy Markdown
Member Author

Let's see how it goes. Do you think it'd be an option to keep a small-ish cache of symbol -> demangled symbol? I'd expect most of the symbols, specially at the top of the tree, to appear over and over

I thought about this as well, but if this will work OK, we can do it separately, if not, will need to introduce some LRU-like cache

Anyway this is the biggest change in terms of CUs :)

Comment thread cmake/sanitize.cmake Outdated
# Linking can fail due to relocation overflows (see #49145), caused by too big object files / libraries.
# Work around this with position-independent builds (-fPIC and -fpie), this is slightly slower than non-PIC/PIE but that's okay.
set (MSAN_FLAGS "-fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -fno-optimize-sibling-calls -fPIC -fpie")
set (MSAN_FLAGS "${MSAN_FLAGS} -fsanitize-ignorelist=${PROJECT_SOURCE_DIR}/tests/msan_ignorelist.txt")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function initializes its result, which means - if you no longer instrument it, you have to also unpoison the result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting that I did not see any issues with it... But anyway, not required anymore

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alternative solution is to disable demangling of trace_log under MSan.

azat added 2 commits December 6, 2025 16:38
…mentation for __cxa_demangle"

The problem was not in MSan instrumentation, but in frame pointers

This reverts commit b11cc93.
…inters)

Disable frame pointers for libcxxabi to reduce demangle cost, llvm
parser has some recursion there.

This makes SYSTEM FLUSH LOGS 2x faster
@azat

azat commented Dec 6, 2025

Copy link
Copy Markdown
Member Author

Turns out the problem was due to frame-pointers, confirmed manually, works 2x faster

@clickhouse-gh clickhouse-gh Bot added the submodule changed At least one submodule changed in this PR. label Dec 6, 2025
@azat azat changed the title Make flushing trace_log under MSan faster by disabling instrumentation for __cxa_demangle Make flushing trace_log under MSan 2x faster by disabling frame pointers for demangling Dec 6, 2025
@azat
azat marked this pull request as ready for review December 6, 2025 15:41
@azat

azat commented Dec 6, 2025

Copy link
Copy Markdown
Member Author

Alternative solution is to disable demangling of trace_log under MSan.

Sure, but I want to avoid difference for MSan if possible, and now, w/o frame-pointers it does not have this overhead

@azat
azat enabled auto-merge December 9, 2025 07:36
@azat
azat added this pull request to the merge queue Dec 9, 2025
Merged via the queue into ClickHouse:master with commit 74654a2 Dec 9, 2025
@azat
azat deleted the disable-msan-for-demangle branch December 9, 2025 07:52
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Dec 9, 2025

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to omit frame pointers when it's the default for the compiler and the project? Who's enabling them?

@azat

azat commented Dec 10, 2025

Copy link
Copy Markdown
Member Author

Why do we need to omit frame pointers when it's the default for the compiler and the project? Who's enabling them?

set (SAN_FLAGS "${SAN_FLAGS} -g -fno-omit-frame-pointer -DSANITIZER")

@azat azat added the 🍃 green ci 🌿 Fixing flaky tests in CI label Dec 12, 2025
@azat azat added the 🚀 Fast CI 🥒 A fast database deserves a fast CI label Dec 14, 2025
@azat azat changed the title Make flushing trace_log under MSan 2x faster by disabling frame pointers for demangling Make flushing trace_log under MSan 25% faster by disabling frame pointers for demangling Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀 Fast CI 🥒 A fast database deserves a fast CI 🍃 green ci 🌿 Fixing flaky tests in CI 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 submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants