Skip to content

common/options: build option tables in place - #71665

Merged
SrinivasaBharath merged 1 commit into
ceph:mainfrom
tchaikov:wip-options-avoid-stack-init-list
Nov 13, 2026
Merged

SrinivasaBharath merged 1 commit into
ceph:mainfrom
tchaikov:wip-options-avoid-stack-init-list

Conversation

@tchaikov

@tchaikov tchaikov commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

y2c.py generates each get_{name}_options() as one braced list:

  return std::vector<Option>({ Option(...)..., Option(...)..., ... });

This is expensive in two ways.

Every Option backing the initializer_list is live at once in a single frame. -fstack-usage reports 746192 bytes for get_global_options() (857 entries) and 404736 for get_rgw_options() (458), far larger than any other function in these libraries.

initializer_list elements are const, so vector cannot move out of them. Every Option is built on the stack, copied to the heap, then destroyed, duplicating each name, description, tag and service string.

Use reserve() and emplace_back() instead. emplace_back() returns a reference to the new element, so the .set_...() chain applies to it directly: each Option is built in the vector, with no stack temporary and no copy.

On x86-64 (gcc 14.2.0, -O2 -fstack-clash-protection -fstack-protector-strong) get_global_options() goes from a 746192 to a 1136 byte frame, from 445856 to 85884 bytes of .text, and compiles in 3.5s instead of 18.8s. get_rgw_options() goes from 404736 to 3792 bytes of frame.

The frame size also breaks unwinding on arm64. A frame that large makes gcc emit stack-clash probing as a loop, and gcc 14 (up to at least Debian's 14.2.0-19) gets the unwind info for that loop wrong by the callee-save size [0]. gdb, C++ exceptions, and full tcmalloc taking a heap-growth backtrace then read garbage instead of the return address. Where pointer authentication is enforced this traps, and ceph-mon/ceph-osd have been seen dying with SIGILL at startup, even for --version [1]. A small frame avoids the probing loop without waiting for a compiler fix to reach stable distros.

The generated definitions do not change: --raw output (for pasting option definitions elsewhere, not used by the build) and the generated legacy option headers are byte-identical across all 13 tables, and the .cc differs only in how each Option is appended.

[0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119610
[1] https://bugzilla.proxmox.com/show_bug.cgi?id=7941

Fixes: https://tracker.ceph.com/issues/81551

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov

Copy link
Copy Markdown
Contributor Author

@ceph/core hi maintainers , could you help review this change?

@tchaikov

Copy link
Copy Markdown
Contributor Author

@ceph/core hi maintainers , just a gentle ping?

@rzarzynski rzarzynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Looks like a workaround for https://tracker.ceph.com/issues/81551 – perhaps Fixes would be adequate.

y2c.py generates each get_{name}_options() as one braced list:

  return std::vector<Option>({ Option(...)..., Option(...)..., ... });

This is expensive in two ways.

Every Option backing the initializer_list is live at once in a single
frame. -fstack-usage reports 746192 bytes for get_global_options()
(857 entries) and 404736 for get_rgw_options() (458), far larger than
any other function in these libraries.

initializer_list elements are const, so vector cannot move out of
them. Every Option is built on the stack, copied to the heap, then
destroyed, duplicating each name, description, tag and service string.

Use reserve() and emplace_back() instead. emplace_back() returns a
reference to the new element, so the .set_...() chain applies to it
directly: each Option is built in the vector, with no stack temporary
and no copy.

On x86-64 (gcc 14.2.0, -O2 -fstack-clash-protection
-fstack-protector-strong) get_global_options() goes from a 746192 to a
1136 byte frame, from 445856 to 85884 bytes of .text, and compiles in
3.5s instead of 18.8s. get_rgw_options() goes from 404736 to 3792
bytes of frame.

The frame size also breaks unwinding on arm64. A frame that large
makes gcc emit stack-clash probing as a loop, and gcc 14 (up to at
least Debian's 14.2.0-19) gets the unwind info for that loop wrong by
the callee-save size [0]. gdb, C++ exceptions, and full tcmalloc
taking a heap-growth backtrace then read garbage instead of the return
address. Where pointer authentication is enforced this traps, and
ceph-mon/ceph-osd have been seen dying with SIGILL at startup, even
for `--version` [1]. A small frame avoids the probing loop without
waiting for a compiler fix to reach stable distros.

The generated definitions do not change: --raw output (for pasting
option definitions elsewhere, not used by the build) and the generated
legacy option headers are byte-identical across all 13 tables, and the
.cc differs only in how each Option is appended.

[0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119610
[1] https://bugzilla.proxmox.com/show_bug.cgi?id=7941

Fixes: https://tracker.ceph.com/issues/81551
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov force-pushed the wip-options-avoid-stack-init-list branch from 8e42ea1 to 4755987 Compare October 22, 2026 01:02
@tchaikov

Copy link
Copy Markdown
Contributor Author

LGTM. Looks like a workaround for https://tracker.ceph.com/issues/81551 – perhaps Fixes would be adequate.

thanks. added "Fixes" tag.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath11-testing-20261027.070430-main.

@connorfawcett

Copy link
Copy Markdown
Contributor

@SrinivasaBharath
SrinivasaBharath merged commit d5d15fc into ceph:main Nov 13, 2026
18 checks passed
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.

4 participants