Skip to content

osd: scale the message cap and the WAL with a small osd_memory_target - #74625

Open
dvanders wants to merge 4 commits into
ceph:mainfrom
dvanders:wip-osd-memory-scale-wal-msgcap
Open

dvanders wants to merge 4 commits into
ceph:mainfrom
dvanders:wip-osd-memory-scale-wal-msgcap

Conversation

@dvanders

@dvanders dvanders commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Second half of #72964, split out as @aclamk asked. It is based on that PR: only the last two commits are new here.

Besides the PG log, two more consumers are bounded by limits sized for the default 4 GiB osd_memory_target that the cache autotuner cannot shrink: the RocksDB WAL and with it the memtables (max_total_wal_size = 1 GiB), and the client message bytes in flight (osd_client_message_size_cap = 500 MiB).

Below 4 GiB, while they are at their defaults, the message cap is multiplied by osd_memory_target / 4 GiB and the WAL by the square root of that ratio (125 MiB and 512 MiB at 1 GiB). The WAL is changed at startup only; a bluestore_rocksdb_options set for any reason is used as is.

Measurements

Both PRs together, the code as it is here with no option set, against #72964 alone and against neither (limits set to today's defaults). vstart, 6 OSDs at a 1 GiB target in a 6 GiB cgroup, 256 PGs each, rbd pool at size 3, a librbd load generator with 16 threads (64 and 256 for the 4M writes), two runs per cell:

neither #72964 alone both
PG log entries / dups 300000 / 3000 150000 / 1500 150000 / 1500
WAL / message cap 1 GiB / 500 MiB 1 GiB / 500 MiB 512 MiB / 125 MiB
peak RSS per OSD 1062, 1052 MiB 1040, 1022 MiB 795, 806 MiB
4K randwrite IOPS 4526, 4464 4516, 4626 4417, 4648
4K randwrite p99.9 10.0, 9.5 ms 10.2, 8.5 ms 10.3, 10.4 ms
4K randread IOPS 27678, 27630 27794, 27729 27679, 27760
4M write, 64 in flight 1156, 1131 MiB/s 1094, 1068 MiB/s 1107, 1077 MiB/s
4M write, 256 in flight 1000, 990 MiB/s 1030, 991 MiB/s 1017, 1047 MiB/s

So a 1 GiB OSD is over its target without the two PRs and about 220 MiB under it with them, at the same speed except for the 4M writes with 64 in flight, which are 2 to 7% lower in both columns that scale anything. The matrix below, with more runs of that workload, puts that inside the spread between runs (1005 to 1121 MiB/s).

Choosing the WAL size and the message cap

An earlier matrix, on a build of the first version of #72964. Same setup, PG log limits at 75000 / 750 in every run (the final 150000 / 1500 was not chosen yet), two runs per cell (mean):

WAL / cap 4K randwrite IOPS p99.9 4K randread IOPS 4M write, 64 in flight 4M write, 256 in flight peak RSS per OSD
1 GiB / 500 MiB (today) 4548 9.2 ms 27652 1111 MiB/s 999 MiB/s 995 MiB
1 GiB / 125 MiB 4607 9.0 ms 27691 1052 MiB/s 1021 MiB/s 1008 MiB
512 MiB / 500 MiB 4727 9.1 ms 27638 1051 MiB/s 986 MiB/s 803 MiB
512 MiB / 125 MiB 4644 10.4 ms 27834 1082 MiB/s 1032 MiB/s 806 MiB
256 MiB / 500 MiB 4631 14.6 ms 27742 1013 MiB/s 1104 MiB/s 655 MiB
256 MiB / 125 MiB 4710 11.0 ms 27893 1067 MiB/s 1130 MiB/s 613 MiB
  • Throughput does not depend on either setting.
  • The WAL sets the memory, about 200 MiB per halving. At 256 MiB the 4K write p99.9 goes up (9.9 to 18.0 ms over the four runs, against 8.7 to 9.5 ms at 1 GiB), hence the square root. Two runs per cell, so this is noisy.
  • The message cap showed no cost and no saving: one client with at most 1 GiB in flight over six OSDs does not reach it. It bounds what many clients with large writes can pin; that case is not tested here.
  • No OOM kills in any run.

Not tested: many clients, EC pools, real disks (the OSDs ran on files on one NVMe-backed virtual disk).

unittest_osd_memory_target_defaults 3/3.

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 Dec 1, 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: 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 while they are at their defaults: osd_client_message_size_cap by osd_memory_target / 4 GiB, and osd_target_pg_log_entries_per_osd, osd_pg_log_dups_tracked and (when the OSD starts) the RocksDB max_total_wal_size by the square root of that ratio. 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 while they are at their defaults: ``osd_client_message_size_cap`` by ``osd_memory_target`` / 4 GiB, and ``osd_target_pg_log_entries_per_osd``, ``osd_pg_log_dups_tracked`` and (when the OSD starts) the RocksDB ``max_total_wal_size`` by the square root of that ratio. A value set explicitly is used as is. (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)

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.

@dvanders

dvanders commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/config check ok

dvanders and others added 4 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]>
Besides the PG log, two more consumers are bounded by limits sized for
the default 4 GiB target that the cache autotuner cannot shrink: the
RocksDB WAL, and with it the memtables (max_total_wal_size=1 GiB in
bluestore_rocksdb_options), and the client message bytes in flight
(osd_client_message_size_cap=500 MiB).

Below the default target, lower their defaults as well, while they are
at their defaults: the message cap by osd_memory_target / 4 GiB, and
the WAL by the square root of that ratio (125 MiB and 512 MiB at
1 GiB). The WAL is rewritten inside the default
bluestore_rocksdb_options string at startup only, before BlueStore
mounts; a bluestore_rocksdb_options set for any reason is used as is.
handle_conf_change() resets the client throttle when the target
changes. osd_client_message_size_cap is flagged runtime, which it
already is in practice.

Six OSDs at a 1 GiB target, 256 PGs each, rbd pool at size 3, a
librbd load generator with 16 threads. With no option set, against
today's limits set explicitly, two runs each: peak RSS per OSD 795
and 806 MiB against 1062 and 1052 MiB; 4K random writes 4417 and 4648
against 4526 and 4464 IOPS; 4K random reads 27.7k IOPS in both; 4M
writes with 64 in flight 1107 and 1077 against 1156 and 1131 MiB/s.

How the two sizes were chosen (an earlier build, PG log limits at
75000 / 750, two runs per cell, mean):

  WAL / cap          4K randwrite  p99.9    4K randread  4M write    peak RSS
                     IOPS                   IOPS         64 in fl.   per OSD
  1 GiB / 500 MiB    4548          9.2 ms   27652        1111 MiB/s  995 MiB
  1 GiB / 125 MiB    4607          9.0 ms   27691        1052 MiB/s  1008 MiB
  512 MiB / 500 MiB  4727          9.1 ms   27638        1051 MiB/s  803 MiB
  512 MiB / 125 MiB  4644          10.4 ms  27834        1082 MiB/s  806 MiB
  256 MiB / 500 MiB  4631          14.6 ms  27742        1013 MiB/s  655 MiB
  256 MiB / 125 MiB  4710          11.0 ms  27893        1067 MiB/s  613 MiB

Throughput does not depend on either. The WAL sets the memory, about
200 MiB per halving, and at a quarter (256 MiB) the 4K write p99.9
goes up, because the memtables flush more often: hence the square
root. The message cap showed no cost in these runs and no saving
either: one client with at most 1 GiB in flight does not reach it. It
bounds what many clients sending large writes can pin.

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]>
Extend unittest_osd_memory_target_defaults: at a 1 GiB target the
message cap is a quarter and the WAL half of the default, the cap is
restored when the target goes back up while the RocksDB options, read
at mount, are left alone, and an explicit cap or a
bluestore_rocksdb_options set for other reasons is kept.

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-wal-msgcap branch from 3ce837f to c20706a Compare December 1, 2026 22:16
@anthonyeleven

Copy link
Copy Markdown
Contributor

Nice, this could really add up on dense archival hosts.

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