Skip to content

broker: reduce the number of mallocs in logging path #6917

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

Merged
merged 2 commits into from
Jul 17, 2025

Conversation

garlick
Copy link
Member

@garlick garlick commented Jul 17, 2025

Problem: the broker ring buffer implementation is malloc-heavy.

This converts the logging ring buffer from zlist_t to a CCAN list so that a list node doesn't need to be allocated each time an entry is appended to the ring. It also combines two mallocs used to allocate a list entry into one.

This is probably not significant since our log volume is not too crazy, but it was an easy change, so there.

Problem: Each log buffer entry requires two mallocs to allocate.

Allocate the ring buffer entry struct and buffer member with one
malloc call.
Copy link
Contributor

@grondo grondo left a comment

Choose a reason for hiding this comment

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

I didn't do any real testing, but a flux dmesg on this branch seems so much faster now! Approved!

Problem: the use of zlist_t in the logging ring buffer
implementation means that a list node has to be separately
allocated each time a log entry is appended to the ring.

Switch to a CCAN list which embeds the list node in the
log entry struct and thus avoid the extra malloc call.
@garlick
Copy link
Member Author

garlick commented Jul 17, 2025

I didn't do any real testing, but a flux dmesg on this branch seems so much faster now!

Huh! I didn't expect that!

Sorry for the force pushes: one sloppy error, one pedantic compiler warning we always hit with list_for_each.

@grondo
Copy link
Contributor

grondo commented Jul 17, 2025

Huh! I didn't expect that!

Well I should have added a ;-)

@garlick
Copy link
Member Author

garlick commented Jul 17, 2025

OK, setting MWP!

@mergify mergify bot merged commit e863069 into flux-framework:master Jul 17, 2025
59 of 60 checks passed
Copy link

codecov bot commented Jul 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.90%. Comparing base (7986127) to head (d4929cf).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6917   +/-   ##
=======================================
  Coverage   83.90%   83.90%           
=======================================
  Files         540      540           
  Lines       90539    90525   -14     
=======================================
- Hits        75963    75957    -6     
+ Misses      14576    14568    -8     
Files with missing lines Coverage Δ
src/broker/log.c 75.95% <100.00%> (+1.02%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@garlick garlick deleted the log_malloc branch July 17, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants