Skip to content

mds: block client mutations when the journal grows too big - #71802

Open
joscollin wants to merge 4 commits into
ceph:mainfrom
joscollin:wip-73868-journal-hard-limit
Open

joscollin wants to merge 4 commits into
ceph:mainfrom
joscollin:wip-73868-journal-hard-limit

Conversation

@joscollin

@joscollin joscollin commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

When client sessions stall and prevent journal trimming, the MDS journal
can grow without bound. Replaying an oversized journal uses unbounded
memory and can crash the MDS.

This adds mds_log_hard_limit_factor. When the journal reaches the hard
limit, which is the factor times mds_log_max_segments, new client
mutating requests are parked until trimming brings the journal back
under the limit. The hard limit is kept above the warn threshold, so
MDS_TRIM is raised before clients are blocked. Between the warn threshold
and the hard limit, new mutations are delayed in proportion to the backlog.

While the limit is reached, the MDS raises MDS_JOURNAL_HARD_LIMIT as a
health error, and the monitor refuses "mds fail" and "fs fail" unless
--yes-i-really-mean-it is given.

This also fixes a trim stall. Expired segments waiting for a major segment
were counted as already gone, so trim stopped at the ceiling and the
journal stayed above max_segments.

QA: adds tasks.cephfs.test_journal_limits. It checks that a create blocks
while the limit is held, that MDS_JOURNAL_HARD_LIMIT is raised, that mds
fail is refused and the refusal names the new code, and that parked creates
complete once trimming resumes.

Known limitations: MDS_TRIM is always raised with the hard limit, so the
integration test cannot isolate the monitor's refusal logic. Steady-state
trimming can differ slightly from before when expired segments are waiting
for the next major segment.

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

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.

@github-actions

Copy link
Copy Markdown

Config Diff Tool Output

+ added: mds_log_hard_limit_segments (mds.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.

@joscollin

Copy link
Copy Markdown
Member Author

/config check ok

Comment thread src/common/options/mds.yaml.in Outdated
be strictly greater than ``mds_log_max_segments * mds_log_warn_factor``. If configured
lower than this calculated safety threshold, the MDS will automatically clamp the limit
to the safe minimum. Set to 0 to disable.
default: 512

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.

Isn't this too low? At 256 untrimmed segments (mds_log_max_segments * mds_log_warn_factor), the MDS emits MDS_TRIM warning which for the most part should be transient and auto-resovle soon. We are talking about a huge backlog of untrimmed segments., so, this number should be pretty large.

Also, I think we should base this number as a multiplier of mds_log_max_segments. Additionally, consider adding a MDS warning message when we hit the hard limit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I agree, the hard limit should be in at least tens of thousands of log segments.

Additionally, I am not sure whether -ENOSPC is the correct result here, as opposed to simply blocking and not returning until the condition is resolved. (I don't know if this is an option).

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.

Yeh, we need to block updated. Returning ENOSPC is going to trip up applications and all at the same time which isn't going to be a good user-experience.

@vshankar
vshankar requested a review from a team September 15, 2026 16:57

@gregsfortytwo gregsfortytwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Philosophically, is the journal really where we really want this logic to live?
We need to get more back pressure slowing down client ops in general when the MDS can't keep up, but I'm not sure this is the way to go about it. If it is, it really needs to be a big fat hammer you never reach, with other slowdown mechanisms precluding it.

There are a LOT of operations which don't expect to get ENOSPC, so this might be better than the cluster going down on MDS restart, but...not a lot?

@vshankar

Copy link
Copy Markdown
Contributor

Philosophically, is the journal really where we really want this logic to live? We need to get more back pressure slowing down client ops in general when the MDS can't keep up, but I'm not sure this is the way to go about it. If it is, it really needs to be a big fat hammer you never reach, with other slowdown mechanisms precluding it.

There are a LOT of operations which don't expect to get ENOSPC, so this might be better than the cluster going down on MDS restart, but...not a lot?

Agreed. But we don't have such an explicit back-pressure mechanism in the client <-> MDS protocol right now. Theoretically, an IOPS control mechanism could be built around cap grants/revocations, distinct from general QoS.

Returning -ENOSPC is definitely the wrong semantic here -- POSIX applications assume the pool or quota is full and will fail or panic, whereas CephFS clients are already designed to tolerate operations blocking under cluster pressure or cap revocations.

A tiered approach makes far more sense:

Soft Limit: Aggressively recall caps from clients holding back the trim boundary and throttle/delay new cap grants. We can also progressively delay dispatching mutating client requests to slow down incoming mutations and give MDLog::trim() breathing room.

Hard Limit: Instead of failing with -ENOSPC, block further mutating client operations. However, this gate must be selective: cap releases, flushes, session closures, and evictions must still be processed, otherwise we risk a deadlock where the trim boundary will never progress.

Suggestions?

MDLog::trim() decides whether to keep expiring segments by subtracting
the expired segments from the segment count. An expired segment only
leaves the journal once the removal walk in _trim_expired_segments()
reaches a major segment past it. Expired segments stuck behind an
unexpired segment were therefore counted as gone while still occupying
the journal. Trim stopped at max_segments and never expired the
unexpired segment that blocked the walk, so the journal stayed above
max_segments indefinitely.

Subtract only the expired segments that the next removal pass will drop,
computed by count_removable_expired_segments(). The subtraction from
commit 7de3738 (tracker 21975) is kept for those segments.

Reproduced with a backlog of 20 segments and max_segments of 8: trim
expired 12 segments, reported 8 remaining, and stopped with segment 122
unexpired and the journal's expire position unchanged.

Behavior change: when expired segments are waiting for the next major
segment, trim may expire up to that many additional segments in one
pass, so steady-state trimming can differ slightly from before.

Signed-off-by: Jos Collin <[email protected]>
When client sessions stall and prevent journal trimming, the MDS
journal can grow without bound. Replaying an oversized journal uses
unbounded memory and can crash the MDS.

Add mds_log_hard_limit_factor. The hard limit is the journal segment
count at which new client mutating requests are parked, computed as
the factor times mds_log_max_segments. With the default factor of 250
and mds_log_max_segments at 128, the limit is 32000 segments. Parked
requests resume once trimming brings the journal back under the
limit. The limit is kept strictly above the warn threshold
(mds_log_max_segments times mds_log_warn_factor), so MDS_TRIM is
reported before clients are blocked.

Between the warn threshold and the hard limit, new mutations are
delayed in proportion to the backlog. The delay is controlled by
mds_log_admission_min_delay and mds_log_admission_max_delay. If the
max is configured below the min, it is raised to the min.

Also:
- Report MDS_JOURNAL_HARD_LIMIT as a health error while the limit is
  reached.
- Refuse "mds fail" and "fs fail" in that state unless
  --yes-i-really-mean-it is given, since failover would replay the
  oversized journal.
- Make mds_log_trim_upkeep_interval a runtime option, and wake the
  trim thread when it changes so the new interval applies immediately.
- Resume parked requests on MDS shutdown. They are answered with
  -EAGAIN instead of stalling shutdown.
- Register the new options with the MDS config observer, so changes to
  them reach handle_conf_change.

Fixes: https://tracker.ceph.com/issues/73868
Signed-off-by: Jos Collin <[email protected]>
Add test_journal_limits to the fs/functional suite, and ignorelist the
new cluster log and health messages in its yaml.

The test stops trimming by setting mds_log_trim_upkeep_interval to 10
minutes, then runs a burst of concurrent file creates until the journal
reaches the hard limit. It checks that:

* A new create does not complete while the limit is held.
* MDS_JOURNAL_HARD_LIMIT appears in "ceph health detail".
* "ceph mds fail" is refused, and the refusal names
  MDS_JOURNAL_HARD_LIMIT.

It then restores the trim interval. It waits for the health check to
clear, failing with a reason if trimming does not resume, and checks
that all parked creates complete.

Clean up any creates still running in the client on exit, so teardown
does not wait on them.

Fixes: https://tracker.ceph.com/issues/73868
Signed-off-by: Jos Collin <[email protected]>
@joscollin
joscollin removed request for a team November 6, 2026 03:26
@joscollin joscollin changed the title mds: stop accepting writes when the journal grows too big mds: block client mutations when the journal grows too big Nov 6, 2026
@joscollin

Copy link
Copy Markdown
Member Author

I'm posting an email notification, which doesn't show up in this PR:

@patrakov asks:

Are you sure that this is still needed? One point behind the new feature is that the journal, even in the worst case, is small enough to be safely replayed.
I meant, do we still need to require --yes-i-really-mean-it in cases like failing an MDS where previously it was required due to the fear of replaying a huge journal?

Reply:
The flag isn’t only about the unknown replay time. Failover also means the MDS restarts into replay with a journal near the limit, and the failover itself may be slower than usual. The confirmation covers that case too. Replay time is the main reason, and it’s the number we'd need to measure to drop the flag.

The point is that the fix doesn’t make replay faster. It makes the worst case bounded. Before, an oversized journal could grow until replay exhausted memory or never finished. With the hard limit, the journal stops growing at a configured size and thus the replay time and memory have an upper bound.

@patrakov

patrakov commented Nov 7, 2026

Copy link
Copy Markdown

Replay time is ... the number we'd need to measure to drop the flag.

Agreed. So we can do it when we have data, which is not now.

Describe the new journal back-pressure behavior and its configuration:

- mds-journaling.rst: add a "Journal back-pressure" section covering the
  delay band, the hard limit, and the trim interval, with confval entries
  for mds_log_admission_min_delay, mds_log_admission_max_delay,
  mds_log_hard_limit_factor, and mds_log_trim_upkeep_interval.
- health-messages.rst: add an MDS_JOURNAL_HARD_LIMIT entry, and point the
  MDS_TRIM entry to it.
- administration.rst, add-remove-mds.rst: list MDS_JOURNAL_HARD_LIMIT with
  MDS_TRIM and MDS_CACHE_OVERSIZED as warnings that require
  --yes-i-really-mean-it for "ceph fs fail" and "ceph mds fail".
- troubleshooting.rst: correct the health code name from MDS_HEALTH_TRIM
  to MDS_TRIM, which is the name operators see.
- PendingReleaseNotes: add a CephFS entry for the new back-pressure
  behavior, the health error, the refusal of mds fail and fs fail, and the
  -EAGAIN response during shutdown.

Fixes: https://tracker.ceph.com/issues/73868
Signed-off-by: Jos Collin <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

Comment thread src/mds/Server.cc
// Journal back-pressure. Only live, new client mutations are throttled or parked.
// Replayed and reconnecting requests must run so the journal can make progress,
// and nothing is gated while the MDS is not active.
if (req->may_write() && mds->is_active() &&

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.

This runs again for every C_MDS_RetryRequest, so an in-progress op is parked or delayed while it still holds locks, pins, or uncommitted_leaders. try_to_expire waits on that state, and the waiter is resumed only after the journal drops below the limit. Skip admission once the request has locks, pins, or peer state. The delay at line 2835 has the same hole for one timer interval.

@salieri11

salieri11 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Blocking client mutations instead of returning ENOSPC, keeping the limit above MDS_TRIM, and raising MDS_JOURNAL_HARD_LIMIT make sense. However, there are two issues that need to be addressed before merging this PR.

dispatch_client_request blocks all write retries, including requests that already hold locks, auth pins, or have an uncommitted leader. Trim may be waiting for these requests to complete, while the requests themselves are waiting for trim to complete. For example, a rename waiting for a peer response can prevent the oldest segment from being trimmed indefinitely. The same mechanism can also block shutdown_pass before it gets to terminate_sessions.

removable_expired is calculated once before entering the trim loop. When a segment expires during try_expire, it is removed from expiring_segments but is not accounted for in removable_expired. As a result, num_remaining_segments remains high and we continue expiring segments up to mds_log_trim_threshold (128 by default). This means that even on a healthy rank with just one segment above mds_log_max_segments, we may unnecessarily revoke caps for up to 128 segments in a single trim pass.

Regarding the functional test, it does not actually verify MDS_JOURNAL_HARD_LIMIT independently. The refusal message always contains that name, and MDS_TRIM is already set at this point. The comment also refers to a monitor unit test which is not part of this PR.

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