Skip to content

osd/OSDMap: don't copy the map to compute a read balance score - #73044

Merged
SrinivasaBharath merged 1 commit into
ceph:mainfrom
anthonyeleven:wip-osdmap-read-balance-no-copy
Nov 25, 2026
Merged

SrinivasaBharath merged 1 commit into
ceph:mainfrom
anthonyeleven:wip-osdmap-read-balance-no-copy

Conversation

@anthonyeleven

@anthonyeleven anthonyeleven commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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

OSDMap::calc_read_balance_score made a deepish_copy_from of the whole OSDMap and scored the copy, and get_pgs_by_osd, which the score calls for every pool, made another copy to map the pool's PGs. Nothing changes either copy: every call made on them is const, and deepish_copy_from doesn't copy the CRUSH map anyway. This uses the map itself in both and drops the OSDMap argument from calc_rbs_fair and calc_rbs_size_optimal, which only read it.

OSDMap::dump scores every replicated pool, so each dump copied the map twice per replicated pool, including every pg_upmap_items entry. The mgr dumps osd_map under the GIL whenever a Python module asks for it, and the mons do the same for osd dump and osd pool ls detail.

Measured with osdmaptool --dump json on one host, using the map of a Reef cluster with 1,018 OSDs, 134 replicated pools and 10,108 pg_upmap_items entries:

Build Dump time
main 2.52 s
main with this change 2.05 s

The output is byte-identical. Each copy took about 1.7 ms, twice per replicated pool. Most of the remaining time is spent mapping every PG of every replicated pool for the scores. #73045 leaves the scores out of the mgr's osd_map getter. The prometheus module reads osd_map twice per collection, and on that cluster the mgr stops dispatching messages for about 7 s each time.

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.

Signed-off-by: Anthony D'Atri [email protected]
Assisted-by: Claude Opus-5.5

calc_read_balance_score made a deepish copy of the whole OSDMap and
scored the copy, and get_pgs_by_osd, which the score calls for every
pool, made another copy to map the pool's PGs. Nothing changes either
copy: every call made on them is const, and deepish_copy_from doesn't
copy the CRUSH map anyway. Use the map itself in both, and drop the
OSDMap argument from calc_rbs_fair and calc_rbs_size_optimal, which
only read it.

OSDMap::dump scores every replicated pool, so each dump copied the map
twice per replicated pool, including every pg_upmap_items entry. The
mgr dumps osd_map under the GIL for its Python modules, and the mons
dump it for osd dump and osd pool ls detail.

Fixes: https://tracker.ceph.com/issues/82062
Signed-off-by: Anthony D'Atri <[email protected]>
Assisted-by: Claude Opus-5.5
@anthonyeleven
anthonyeleven force-pushed the wip-osdmap-read-balance-no-copy branch from e0d3505 to 1a27404 Compare October 24, 2026 05:52
@anthonyeleven

Copy link
Copy Markdown
Contributor Author

Build and test results, on a CentOS Stream 9 container with GCC 11.5, RelWithDebInfo, main at de83537 with #73044, #73045 and #73046 applied:

  • unittest_osdmap: 45 of 45 tests pass, including the read balance score tests.
  • osdmaptool --dump json on the map described above:
Build Runs
this tree with both copies put back 2.50, 2.52, 2.52, 2.52, 2.53 s
with only the copy in calc_read_balance_score removed 2.28, 2.29, 2.31, 2.31, 2.32 s
this PR 2.04, 2.04, 2.09 s

The JSON output is byte-identical in all three.

@anthonyeleven
anthonyeleven marked this pull request as ready for review October 24, 2026 07:08
@anthonyeleven
anthonyeleven requested a review from a team as a code owner October 24, 2026 07:08
@anthonyeleven

Copy link
Copy Markdown
Contributor Author

@ljflores Gentle ping for a review when you have a chance. #73045, which leaves the scores out of the mgr's osd_map getter, is approved. This one makes the scores cheaper for the callers that still compute them, such as osd dump, osd pool ls detail and the balancer's read modes.

@idryomov idryomov 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.

I was looking at other @anthonyeleven's PRs in this area and this one seems more than sensible to me.

anthonyeleven added a commit to anthonyeleven/ceph that referenced this pull request Nov 4, 2026
Keep the pools loop in OSDMap::dump(), which now passes true for
dump_pool()'s with_read_balance parameter, and have the osd_map_pools
getter call dump_pool() for each pool itself, without the read balance
scores.

Also drop "copy the map" from the getter's comment, since
ceph#73044 stops the read balance score
from copying the OSDMap.

Signed-off-by: Anthony D'Atri <[email protected]>
Assisted-by: Claude Opus-5.5
anthonyeleven added a commit to anthonyeleven/ceph that referenced this pull request Nov 4, 2026
ceph#73044 removes the OSDMap copies that calc_read_balance_score() and
get_pgs_by_osd() make, so drop "copy the map" from the osd_map getter
comment. This is the wording Ilya Dryomov suggested on ceph#72719.

Fixes: https://tracker.ceph.com/issues/82063
Signed-off-by: Anthony D'Atri <[email protected]>
Assisted-by: Claude Opus-5.5
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath10-testing-20261109.054620-main.

@lee-j-sanders

Copy link
Copy Markdown
Member

@SrinivasaBharath
SrinivasaBharath merged commit 4f91e58 into ceph:main Nov 25, 2026
20 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.

5 participants