-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util/backtrace: Optimize formatter to reduce memory allocation overhead
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 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. Signed-off-by: Kefu Chai <[email protected]>
- Loading branch information
Showing
2 changed files
with
70 additions
and
32 deletions.
There are no files selected for viewing
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
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