Skip to content

osd: scale the PG log limits with a small osd_memory_target - #72964

Open
dvanders wants to merge 2 commits into
ceph:mainfrom
dvanders:wip-osd-memory-scale-limits
Open

dvanders wants to merge 2 commits into
ceph:mainfrom
dvanders:wip-osd-memory-scale-limits

Conversation

@dvanders

@dvanders dvanders commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the review of #72884. Split from the original version of this PR as @aclamk asked: this is the PG log part; the client message cap and the RocksDB WAL are in #74625.

The cache autotuner keeps an OSD near osd_memory_target by shrinking its caches, but the PG log is bounded by limits sized for the default 4 GiB target (300k entries per OSD, 3000 dups per PG), and nothing shrinks it. At a 1 GiB target with 256 PGs per OSD and sustained 4K writes, the PG log alone took 216 to 252 MiB per OSD.

Below 4 GiB, the defaults of osd_target_pg_log_entries_per_osd and osd_pg_log_dups_tracked are now multiplied by the square root of osd_memory_target / 4 GiB (150000 and 1500 at 1 GiB). A value set explicitly is used as is, which is also how to opt out. At or above 4 GiB nothing changes.

Why the square root

A shorter log turns the log recovery of a restarted OSD into backfill. vstart, 6 OSDs at a 1 GiB target in a 6 GiB cgroup, 256 PGs each, rbd pool at size 3, 4K random writes (about 4.8k IOPS, 9 per second and PG); one OSD is killed, and restarted after N seconds. PGs backfilled / PGs recovered from the log only, of about 230 on that OSD, one run each. All three runs had the WAL at 512 MiB and the message cap at 125 MiB, the values of the follow-up PR:

OSD down ratio (75000 / 750) square root (150000 / 1500) default (300000 / 3000)
10 s 192 / 11 118 / 108 6 / 220
30 s 188 / 4 116 / 108 6 / 221
60 s 217 / 2 201 / 14 79 / 150
120 s 229 / 0 229 / 3 195 / 25
300 s 230 / 0 244 / 0 231 / 0
ratio square root default
PG log per OSD 58-68 MiB 113-131 MiB 216-252 MiB
peak RSS per OSD 845 MiB 964 MiB 1141 MiB

So the square root halves the PG log and backfills about half of the PGs after a short restart, where scaling by the ratio backfilled most of them. It is still far from the default log, which the release note says.

On its own this PR does not bring a 1 GiB OSD under its target: with the WAL and the message cap at today's defaults, a shorter mixed workload (the one in the follow-up PR, two runs) peaked at 1022 to 1040 MiB per OSD, against 1052 to 1062 MiB without this PR and 795 to 806 MiB with both PRs. "Down" is the time between kill -9 and the restart; boot and peering come on top. Time to clean was 37 to 44 s in every case, which says little: the image was 8 GiB, about 16 MiB per PG.

Not tested: a less busy pool (all three columns move towards log recovery), EC pools, real disks.

unittest_osd_memory_target_defaults 3/3, unittest_pglog 61/61.

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.

Assisted by Claude Code (Claude Fable 5.2).

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Config Diff Tool Output

! changed: osd_client_message_size_cap: old:  (osd.yaml.in)
! changed: osd_client_message_size_cap: new: ['runtime'] (osd.yaml.in)
! changed: osd_client_message_size_cap: old: The maximum total memory devoted to in-flight client request messages. When the in-flight total exceeds this value, the OSD stops reading new client data from the network until memory is freed. (osd.yaml.in)
! changed: osd_client_message_size_cap: new: The maximum total memory devoted to in-flight client request messages. When the in-flight total exceeds this value, the OSD stops reading new client data from the network until memory is freed. Below an osd_memory_target of 4 GiB the default is scaled down by osd_memory_target / 4 GiB; a value set explicitly is used as is. (osd.yaml.in)
! changed: osd_target_pg_log_entries_per_osd: old:  (global.yaml.in)
! changed: osd_target_pg_log_entries_per_osd: new: ['runtime'] (global.yaml.in)
! changed: osd_pg_log_dups_tracked: old:  (global.yaml.in)
! changed: osd_pg_log_dups_tracked: new: ['runtime'] (global.yaml.in)
! changed: osd_memory_target: old: ['bluestore_cache_autotune', 'osd_memory_cache_min', 'osd_memory_base', 'osd_memory_target_autotune'] (global.yaml.in)
! changed: osd_memory_target: new: ['bluestore_cache_autotune', 'osd_memory_cache_min', 'osd_memory_base', 'osd_memory_target_autotune', 'osd_client_message_size_cap', 'osd_target_pg_log_entries_per_osd', 'osd_pg_log_dups_tracked', 'bluestore_rocksdb_options'] (global.yaml.in)
! changed: osd_memory_target: old: When TCMalloc is available and cache autotuning is enabled, the OSD tries to keep this many bytes mapped in memory. The value must be at least ``osd_memory_base`` + ``osd_memory_cache_min``. Note that this may not exactly match the process's RSS: although the total heap memory mapped is usually close to this target, the kernel is not guaranteed to reclaim unmapped memory. Some kernels have been observed to let the OSD's RSS exceed the mapped memory by up to 20%, though kernels may reclaim more aggressively under memory pressure. Your mileage may vary. (global.yaml.in)
! changed: osd_memory_target: new: When TCMalloc is available and cache autotuning is enabled, the OSD tries to keep this many bytes mapped in memory. The value must be at least ``osd_memory_base`` + ``osd_memory_cache_min``. Note that this may not exactly match the process's RSS: although the total heap memory mapped is usually close to this target, the kernel is not guaranteed to reclaim unmapped memory. Some kernels have been observed to let the OSD's RSS exceed the mapped memory by up to 20%, though kernels may reclaim more aggressively under memory pressure. Your mileage may vary. Below 4 GiB, some limits on memory that the autotuner cannot shrink are scaled down by ``osd_memory_target`` / 4 GiB while they are at their defaults: ``osd_client_message_size_cap``, ``osd_target_pg_log_entries_per_osd`` and ``osd_pg_log_dups_tracked``, and, by the square root of that ratio and when the OSD starts, the RocksDB ``max_total_wal_size``. A value set explicitly is used as is. (global.yaml.in)
! changed: osd_memory_target: old: When TCMalloc is available and cache autotuning is enabled, the OSD tries to keep this many bytes mapped in memory. The value must be at least osd_memory_base + osd_memory_cache_min. Note that this may not exactly match the process's RSS: although the total heap memory mapped is usually close to this target, the kernel is not guaranteed to reclaim unmapped memory. Some kernels have been observed to let the OSD's RSS exceed the mapped memory by up to 20%, though kernels may reclaim more aggressively under memory pressure. Your mileage may vary. (global.yaml.in)
! changed: osd_memory_target: new: When TCMalloc is available and cache autotuning is enabled, the OSD tries to keep this many bytes mapped in memory. The value must be at least osd_memory_base + osd_memory_cache_min. Note that this may not exactly match the process's RSS: although the total heap memory mapped is usually close to this target, the kernel is not guaranteed to reclaim unmapped memory. Some kernels have been observed to let the OSD's RSS exceed the mapped memory by up to 20%, though kernels may reclaim more aggressively under memory pressure. Your mileage may vary. Below 4 GiB, some limits on memory that the autotuner cannot shrink are scaled down by osd_memory_target / 4 GiB while they are at their defaults: osd_client_message_size_cap, osd_target_pg_log_entries_per_osd and osd_pg_log_dups_tracked, and, by the square root of that ratio and when the OSD starts, the RocksDB max_total_wal_size. A value set explicitly is used as is. (global.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

@ming1

ming1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The approach makes sense: the autotuner can only shrink the caches, and the PG log, client throttle and memtables are what actually grow at a small target.

One bug in _get_rocksdb_options(): the WAL value is read with strtoull(..., 10), but RocksDB accepts K/M/G/T suffixes (the default string already uses compaction_readahead_size=2MB). With max_total_wal_size=2G in the annex the helper appends max_total_wal_size=1, a 1-byte WAL cap, and RocksDB flushes memtables on nearly every write. 1024MB gives 512 bytes. 1G is a no-op (1 -> 1), which hides it. The key scan also only recognises a key after , or ;, while StringToMap in RocksDBStore.cc accepts space and newline too, so ..., max_total_wal_size=... is silently not scaled.

Suggest parsing the merged string (StringToMap, or ParseOptionsFromStringStatic as _open_bluefs already does) and reading the numeric value from the result, plus a unit test for the annex override, a suffixed value and a space-separated string.

One point for discussion: do we need osd_memory_target_scale_limits at all? If the scaling only applied to limits still at their default, and an explicitly set value were used as is, the option could go away and operators who already tuned these limits would not get scaled twice. The config layer can tell the two apart (get_val_default / diff).

@dvanders
dvanders force-pushed the wip-osd-memory-scale-limits branch from 9bac776 to 8aaf994 Compare October 22, 2026 20:09
@dvanders

Copy link
Copy Markdown
Contributor Author

Thanks @ming1, good catch on the WAL parsing. Fixed: the value is now read with RocksDBStore::ParseOptionsFromStringStatic(), as _open_bluefs() does, so 2G / 1024MB are read correctly, and , max_total_wal_size=… with spaces is found too. (A plain space isn't a separator for RocksDBStore's StringToMap(), only , and ;, so a space-separated string fails at DB open anyway.) There are new tests in unittest_bluestore_types for the default string, a suffixed annex value, spaced separators and an unparseable string. I also checked a vstart OSD at a 1 GiB target with max_total_wal_size=2G in the annex.

On the option: agreed, scaling only what's still at its default is better. Done in the same push: explicitly set values are used as is, and osd_memory_target_scale_limits is gone. The WAL counts as default when it matches the default bluestore_rocksdb_options, so changing other RocksDB options doesn't turn the scaling off. On a 1 GiB vstart OSD: everything at defaults gives a 512 MiB WAL and a 125 MiB client byte cap; max_total_wal_size=2G in the annex is kept at 2 GiB; osd_client_message_size_cap=200M is kept at 200 MiB.

@ming1

ming1 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Thanks, the parser-based WAL read and dropping the option both look right, and you're correct that a bare space isn't a separator for StringToMap (the comment at RocksDBStore.cc:274 says it is, which misled me).

Two things remain:

  1. The helper takes the config lock three times per call (get_val, get_schema, get_val of osd_memory_target). pg_log_dups_tracked() runs twice per IndexedLog::trim(), which runs on every write from append_log(), plus get_target_pg_log_entries(): nine lock-plus-lookups per write op under the PG lock, where the old code read two legacy fields. handle_conf_change() already tracks osd_memory_target; adding the PG log keys there and caching the scaled values in atomics would remove it.

  2. PendingReleaseNotes and bluestore-config-ref.rst are still untouched. Clusters autotuned below 4 GiB change behaviour on upgrade (shorter log window, fewer dups, smaller client throttle, more backfill after a restart under writes).

@dvanders

Copy link
Copy Markdown
Contributor Author

Thanks @ming1, both done in a9e9bf2:

  1. The OSD now computes the scaled PG log entry budget and dups count once, at startup and in handle_conf_change() (on osd_memory_target and either limit), and caches them in atomics. get_target_pg_log_entries() and pg_log_dups_tracked() just load them, so the per-write path is lock-free again. That also fixes the crimson build failure: crimson compiles osd_types.cc with its own ConfigProxy, which has no get_schema(), and the shared code no longer includes the scaling helper. On a vstart OSD at 1 GiB it logs 75000 entries and 750 dups; after setting osd_memory_target to 2 GiB live, 150000 and 1500; an explicit osd_pg_log_dups_tracked=1000 is kept as is.
  2. Added a PendingReleaseNotes entry (covering osd_memory_target_autotune clusters, and that shorter PG logs mean more backfill after a restart under writes) and a paragraph under "Automatic Cache Sizing" in bluestore-config-ref.rst.

And thanks for #73018. I'll review it and run it through the same hot-read benchmark.

@dvanders
dvanders force-pushed the wip-osd-memory-scale-limits branch from 8aaf994 to a9e9bf2 Compare October 23, 2026 15:55
@dvanders
dvanders requested a review from a team as a code owner October 23, 2026 15:55
@ming1

ming1 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Thanks for the update. One thought on simplifying further: the config system already has the "scale while at default, explicit wins" rule. If the OSD lowers the defaults with set_val_default(), every reader stays as it is:

// ceph_osd.cc, right after global_init(); again from handle_conf_change() on osd_memory_target
for (key : {osd_client_message_size_cap, osd_target_pg_log_entries_per_osd, osd_pg_log_dups_tracked})
  conf.set_val_default(key, to_string(default(key) * scale));
// at startup only: max_total_wal_size rewritten inside the default bluestore_rocksdb_options string

A CONF_DEFAULT value yields to any higher level, so an explicit value is kept even when it equals the default (which the release note promises), set_val_default() refreshes the legacy fields in place so the PG log and throttle paths need no change, and the scaled values show in ceph config show. The OSD already does this for the mClock defaults. The whole change then becomes one function in OSD.cc plus the yaml/docs; memory_target_scale.h, the BlueStore parsing and the osd_types.cc cache go away. The trade-off is that a user-set bluestore_rocksdb_options keeps its own WAL size, which matches the documented rule.

For reference only, two commits (code, tests): https://github.com/ming1/ceph/commits/wip-72964-simple. Verified on a vstart cluster at 1 GiB including live target changes, and the 1 GiB OSD survives the 4K write run that OOM-killed it before.

@dvanders
dvanders force-pushed the wip-osd-memory-scale-limits branch from a9e9bf2 to 2a2f6be Compare October 27, 2026 17:23
@dvanders
dvanders requested a review from a team as a code owner October 27, 2026 17:23
@dvanders

Copy link
Copy Markdown
Contributor Author

Thanks @ming1, that's much simpler. I've taken your two commits (with you as co-author), and the PR is now just scale_memory_target_defaults() plus the yaml, docs and test. I checked the tricky parts: get_val_default() returns the schema default, so repeated target changes don't compound; observers run without the config lock, so calling set_val_default() from handle_conf_change() is safe and doesn't re-enter; the startup call runs before common_init_finish(), so rewriting bluestore_rocksdb_options is still allowed; and the two PG log options need the runtime flag you added, or set_val_default() would assert once the OSD is up. The only other change is in the CMake: the new test moved below unittest_pglog and was added to OSD_UNITTESTS.

On a vstart OSD: 1 GiB at runtime gives 125 MiB / 75000 / 750; after a restart the WAL is 512 MiB, and RocksDB reports it too; 2 GiB and 4 GiB scale back up; explicitly set values (including dups at its default, 3000) are kept, and once they're removed it falls back to the scaled default. unittest_osd_memory_target_defaults 3/3, unittest_pglog 54/54.

@dvanders

Copy link
Copy Markdown
Contributor Author

/config check ok

@aclamk

aclamk commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

I feel like this PR is logically 2 parts:

Part one of this PR is doing scaling of osd_target_pg_log_entries_per_osd and osd_pg_log_dups_tracked, values that do not play a role in performance of OSD in sunny day scenarios and playing huge role in fast catchup and recovery. It would be nice to have someone perform the testing and report how much worse with the values reduced.

Part two of this PR is osd_client_message_size_cap and manipulation of RocksDB WAL size. These, alongside BlueStore cache sizes have an immediate effect on OSD performance. For these we can quite easily create workloads and run performance scenarios with different values.

I believe we should split this PR.
Part one will get usual review, but can be accepted without testing.
Part two should be backed up by series of tests that maps {message size}x{WAL size}x{test scenario} -> performance.
It is on the base of test results decision like "square root" approximation should be made.

@RaminNietzsche

Copy link
Copy Markdown
Member

Ceph PR triage — related open PRs

Queried #72964 against KB snapshot 2026-11-10T06:02:21 in 2.3s.
Signals are candidates for human review, not merge blockers.

Category Confidence Other PR(s) Note
stated-supersede medium #73018 #72964 description says: "Running OSDs at 1.5 GiB (HDD) / 2 GiB (flash) instead of 4 / 6 GiB, together with #73018" (both still open)
stated-supersede medium #73273 #72964 description says: "Running OSDs at 1.5 GiB (HDD) / 2 GiB (flash) instead of 4 / 6 GiB, together with #73018 and #73273" (both still open)

This comment is updated in place when the workflow re-runs (hidden HTML marker). Data: read-only GitHub + local git analysis; no labels or merges were changed.

@dvanders
dvanders force-pushed the wip-osd-memory-scale-limits branch from 2a2f6be to d1cd80f Compare December 1, 2026 02:46
@dvanders dvanders changed the title osd: scale uncached memory limits with a small osd_memory_target osd: scale the PG log limits with a small osd_memory_target Dec 1, 2026
@dvanders

dvanders commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @aclamk, done as you suggest.

This PR is now the PG log part only. I ran the catch-up test: with the limits scaled by the ratio, even a 10 s restart of an OSD under 4K writes backfilled 192 of about 230 PGs, against 6 with the default log. So they are scaled by the square root now (118 backfilled), which still halves the PG log (113-131 MiB per OSD against 216-252 MiB). The table is in the description. This half alone does not get a 1 GiB OSD under its target; that needs the other one.

The message cap and the WAL are in #74625, with the WAL size x message cap x workload matrix. Short version: with both, a 1 GiB OSD peaks at about 800 MiB against 1050 MiB today; throughput is flat, the WAL sets the memory, a 256 MiB WAL raises the 4K write p99.9, and the message cap made no difference with one client.

the values specified in the ``bluestore_cache_meta_ratio`` and
``bluestore_cache_kv_ratio`` options are used as fallback cache ratios.

The caches are not the only memory an OSD uses. The PG log is bounded by

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 think the whole section is too important to be a side note.
Also, it applies to both automatic and manual cache sizing.
Let's make it a separate topic.
Most likely we will identify more things to scale in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: it is a section of its own now, "Limits Scaled with the Memory Target", with a table of the limits, their defaults and how each is scaled, so more can be added. It also says that this applies with automatic and with manual cache sizing. #74625 adds its two rows to the same table.

dvanders and others added 2 commits December 1, 2026 15:06
The cache autotuner keeps an OSD near osd_memory_target by shrinking
its caches, but the PG log is bounded by limits sized for the default
4 GiB target (osd_target_pg_log_entries_per_osd=300000,
osd_pg_log_dups_tracked=3000 per PG), and nothing shrinks it. At a
1 GiB target with 256 PGs per OSD and sustained 4K writes, the PG log
alone took 216 to 252 MiB per OSD.

Below the default target, lower the defaults of both options by the
square root of osd_memory_target / 4 GiB (150000 and 1500 at 1 GiB).
The OSD does it with set_val_default() right after global_init() and
again whenever osd_memory_target changes. A default set this way yields
to a value set at any higher level, so an explicit value is used as is,
even one equal to the default, and setting one is how to opt out.
set_val_default() updates the config fields in place, so the readers
are unchanged, and the scaled values show in `ceph config show`. The
two options are flagged runtime, which they already are in practice,
so that the OSD may lower them after startup. At or above 4 GiB nothing
changes.

The square root, not the ratio itself, because a shorter log turns the
log recovery of a restarted OSD into backfill. Six OSDs at a 1 GiB
target, 256 PGs each, 4K random writes at about 9 per second and PG,
one OSD killed and restarted after N seconds (WAL at 512 MiB and
message cap at 125 MiB in all three); PGs backfilled / PGs recovered
from the log only, of about 230 on that OSD:

  down    ratio (75000/750)  square root (150000/1500)  default
  10 s    192 / 11           118 / 108                  6 / 220
  30 s    188 / 4            116 / 108                  6 / 221
  60 s    217 / 2            201 / 14                   79 / 150
  120 s   229 / 0            229 / 3                    195 / 25
  300 s   230 / 0            244 / 0                    231 / 0

  PG log per OSD    58-68 MiB   113-131 MiB   216-252 MiB
  peak RSS per OSD  845 MiB     964 MiB       1141 MiB

So at this write rate a short restart still backfills about half of
the PGs, where the default log backfills almost none; that is the
price of the smaller log, and the release note says so. On its own
this does not bring a 1 GiB OSD under its target (1022 to 1040 MiB
peak in a shorter mixed workload, against 1052 to 1062 MiB); the WAL
has to shrink as well, which the next commits do.

Document it in the BlueStore configuration reference and in
PendingReleaseNotes.

Co-authored-by: Ming Lei <[email protected]>
Assisted-by: Claude-Code-v2.1.331:claude-fable-5-2
Signed-off-by: Dan van der Ster <[email protected]>
Add unittest_osd_memory_target_defaults: the OSD lowers the two
defaults at a 1 GiB target, restores them when the target goes back
up, leaves them alone at the default target, and keeps an explicitly
set value, including one equal to the default.

Co-authored-by: Ming Lei <[email protected]>
Assisted-by: Claude-Code-v2.1.331:claude-fable-5-2
Signed-off-by: Dan van der Ster <[email protected]>
@dvanders
dvanders force-pushed the wip-osd-memory-scale-limits branch from d1cd80f to 48c9628 Compare December 1, 2026 22:16
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