-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util/backtrace: Optimize formatter to reduce memory allocation overhead #2572
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tested with scylla master HEAD. the new implementation is able to format the backtrace, like
the format is identical to existing implementation. |
c0abaf9
to
f0792c1
Compare
avikivity
reviewed
Dec 10, 2024
f0792c1
to
dd9c2b1
Compare
This commit addresses a critical memory allocation issue in backtrace formatting by directly specializing fmt::formatter for backtrace types, eliminating dependency on iostream-based formatting. Problem: When Seastar applications experience high memory pressure, logging backtrace information could fail due to additional memory allocation required by iostream formatting. This resulted in errors like: ``` ERROR 2024-12-10 01:59:16,905 [shard 0:main] seastar_memory - seastar/src/core/memory.cc:2126 @void seastar::memory::maybe_dump_memory_diagnostics(size_t, bool): failed to log message: fmt='Failed to allocate {} bytes at {}': std::__ios_failure (error iostream:1, basic_ios::clear: iostream error)" ``` Solution: - Implement direct fmt::formatter specialization for backtrace - Remove reliance on operator<< for string representation - Reduce memory allocation pressure during out-of-memory scenarios - Improve reliability of backtrace logging under extreme memory constraints Compatibility Improvements: - Ensure consistent `fmt::formatter` availability across fmt library versions - Deprecate two `simple_backtrace` constructors previously added in 095a07b, as they are no longer needed with fmt::join - Maintain robust formatting approach independent of library version Impact: This change enhances system resilience by enabling backtrace logging even under significant memory pressure, providing more reliable post-mortem debugging information. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
dd9c2b1
to
342e93c
Compare
v2:
|
avikivity
approved these changes
Dec 10, 2024
@scylladb/seastar-maint hello maintainers, could you help merge this change? |
tchaikov
added a commit
to tchaikov/scylla-seastar
that referenced
this pull request
Feb 6, 2025
This commit addresses a critical memory allocation issue in backtrace formatting by directly specializing fmt::formatter for backtrace types, eliminating dependency on iostream-based formatting. Problem: When Seastar applications experience high memory pressure, logging backtrace information could fail due to additional memory allocation required by iostream formatting. This resulted in errors like: ``` ERROR 2024-12-10 01:59:16,905 [shard 0:main] seastar_memory - seastar/src/core/memory.cc:2126 @void seastar::memory::maybe_dump_memory_diagnostics(size_t, bool): failed to log message: fmt='Failed to allocate {} bytes at {}': std::__ios_failure (error iostream:1, basic_ios::clear: iostream error)" ``` Solution: - Implement direct fmt::formatter specialization for backtrace - Remove reliance on operator<< for string representation - Reduce memory allocation pressure during out-of-memory scenarios - Improve reliability of backtrace logging under extreme memory constraints Compatibility Improvements: - Ensure consistent `fmt::formatter` availability across fmt library versions - Deprecate two `simple_backtrace` constructors previously added in 095a07b, as they are no longer needed with fmt::join - Maintain robust formatting approach independent of library version Impact: This change enhances system resilience by enabling backtrace logging even under significant memory pressure, providing more reliable post-mortem debugging information. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com> (cherry picked from commit 3133ecd) Parent PR: scylladb/seastar#2572 Refs scylladb/scylladb#22727
denesb
pushed a commit
to scylladb/scylla-seastar
that referenced
this pull request
Feb 11, 2025
This commit addresses a critical memory allocation issue in backtrace formatting by directly specializing fmt::formatter for backtrace types, eliminating dependency on iostream-based formatting. Problem: When Seastar applications experience high memory pressure, logging backtrace information could fail due to additional memory allocation required by iostream formatting. This resulted in errors like: ``` ERROR 2024-12-10 01:59:16,905 [shard 0:main] seastar_memory - seastar/src/core/memory.cc:2126 @void seastar::memory::maybe_dump_memory_diagnostics(size_t, bool): failed to log message: fmt='Failed to allocate {} bytes at {}': std::__ios_failure (error iostream:1, basic_ios::clear: iostream error)" ``` Solution: - Implement direct fmt::formatter specialization for backtrace - Remove reliance on operator<< for string representation - Reduce memory allocation pressure during out-of-memory scenarios - Improve reliability of backtrace logging under extreme memory constraints Compatibility Improvements: - Ensure consistent `fmt::formatter` availability across fmt library versions - Deprecate two `simple_backtrace` constructors previously added in 095a07b, as they are no longer needed with fmt::join - Maintain robust formatting approach independent of library version Impact: This change enhances system resilience by enabling backtrace logging even under significant memory pressure, providing more reliable post-mortem debugging information. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com> (cherry picked from commit 3133ecd) Parent PR: scylladb/seastar#2572 Refs scylladb/scylladb#22727 Close #9
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit addresses a critical memory allocation issue in backtrace formatting by directly specializing fmt::formatter for backtrace types, eliminating dependency on iostream-based formatting.
Problem:
When Seastar applications experience high memory pressure, logging backtrace information could fail due to additional memory allocation required by iostream formatting. This resulted in errors like:
Solution:
Additional Compatibility Note:
Due to changes in fmt library versioning, this implementation ensures fmt::formatter is always defined for backtrace types, even when using fmt versions earlier than 9.0. Previously, these formatters were conditionally defined based on the fmt version. Now, the formatters are consistently available, with operator<< implemented using the new fmt::formatter specialization.
This change ensures that backtrace logging can proceed even when the system is under significant memory pressure, providing more reliable post-mortem debugging information.