Skip to content

RFC: mds: don't cow an old_inode no snapshot can reference - #72447

Open
vshankar wants to merge 4 commits into
ceph:mainfrom
vshankar:wip-vshankar-old-inodes-fix
Open

vshankar wants to merge 4 commits into
ceph:mainfrom
vshankar:wip-vshankar-old-inodes-fix

Conversation

@vshankar

@vshankar vshankar commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Fixes: https://tracker.ceph.com/issues/67102
Related-to: https://tracker.ceph.com/issues/76455

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.

pre_cow_old_inode() takes @follows from the global snaprealm seq, which
is max(last_created, last_destroyed) over the whole filesystem, and then
cows unconditionally:

    if (first <= follows)
      cow_old_inode(follows, true);

However, staleness is inferred later against the inode's OWN realm's snap
set - CInode::purge_stale_snap_data(), reached from CInode::store() for a
base inode and from CDir::_parse_dentry() for everything else.  For an
inode whose realm has no snaps the two never agree: every old_inode it
mints is stale the moment it is created.

That is the steady state of a pure subvolume workload.  A subvolume owns
its own snaprealm, so its snapids never enter /volumes realm, yet
predirty_journal_parents() walks to root and cows every ancestor on each
mksnap.  With 90 subvolume snapshots, /volumes, the subvolume group and /
each accumulate 89 old_inodes that no snapshot can ever reference. Snapshot
removal costs the same again -- rmsnap allocates a fresh snapid as the realm's
seq, so the global seq advances and the ancestors are cowed once more.

The global snaprealm was introduced by

    1bc6297 ("mds: update CInode/CDentry's first according to global snapshot seq")

to keep @FIRST monotonic across realms, which is what makes an inode
moving between realms manageable.  CInode::pre_cow_old_inode() has only
one way to advance @FIRST - call cow_old_inode() - so the old_inode is
collateral damage from range bookkeeping.

MDCache::journal_cow_dentry() already separates the two jobs:

    if (!realm->has_snaps_in_range(in->first, follows)) {
      in->first = follows + 1;
      return;
    }
    in->cow_old_inode(follows, cow_head);

Make pre_cow_old_inode() do the same. @follows still comes from the
global seq and @FIRST still advances past it.

This also makes mds_use_global_snaprealm_seq_for_subvol redundant -- the
general check includes the subvolume special case added by

    1cebd41 ("mds: Don't use global snaprealm seq for subvolume")

and additionally covers non-subvolume trees with no snapshots.  The
option is left in place for now and should be deprecated separately.

Fixes: https://tracker.ceph.com/issues/67102
Signed-off-by: Venky Shankar <[email protected]>
This is a recovery measure for filesystems that already carry stale
old_inodes, not a correctness fix.  With the preceding patch nothing new
is minted, so on a freshly fixed cluster there is nothing here to do.

CDir::_omap_commit() only hands a snap set to try_trim_snap_dentry() and
_parse_dentry() when

    fnode->snap_purged_thru < realm->get_last_destroyed()

i.e. only once some snapshot has been destroyed since this dirfrag was
last fetched.  That is the right trigger for anything a cow produces,
because MDCache::journal_cow_dentry() only ever mints a snapped dentry or
an old_inode when realm->has_snaps_in_range() says a snapshot covers the
range - so it is born live and can only go stale when a snapshot is
destroyed.

It is the wrong trigger for the old_inodes an MDS without the preceding
patch produced.  Those were minted with @follows from the global
snaprealm seq and no range check at all, so they were stale the moment
they were created, with no destroy anywhere in the picture.  Nothing will
ever open the gate for them --  snap_purged_thru has exactly one writer,
CDir::_omap_fetched(), which sets it to last_destroyed, and last_destroyed
only moves when a snapshot is destroyed.  A cluster that retains every
snapshot it takes therefore keeps them forever, and they are not merely
wasted space - EMetaBlob::fullbit re-encodes the whole old_inodes map
into every journal entry that touches the inode.

Stop consulting the watermark and let purge_stale_snap_data() and
try_trim_snap_dentry() decide, which is what they are for.  Both are
swept, not just old_inodes -- a snapped dentry and an old_inode are two
encodings of the same thing, picked by CInode::is_multiversion(), minted
under the same guard and stale under the identical predicate.

Do not advance the watermark here.  _omap_commit() writes only the dirty
dentries, so marking the whole dirfrag purged would claim the clean ones
had been swept too.  The commented-out assignment that said as much is
replaced by a comment that explains it.

Related-to: https://tracker.ceph.com/issues/67102
Related-to: https://tracker.ceph.com/issues/76455
Signed-off-by: Venky Shankar <[email protected]>
A subvolume owns its snaprealm, so its snapids never reach /volumes, the
subvolume group or /.  Snaprealms inherit downward, not upward, so an
old_inode CoW'd onto one of those ancestors for a subvolume snapid can
never be referenced by anything, and nothing in the write path is
guaranteed to reclaim it.

Both directions are covered, because either alone is passable by a broken
change: an over-suppressing guard satisfies "the ancestors stay empty",
and the unfixed code satisfies "a covered inode is still cow'd".

  - subvolume snapshots: /volumes and the group keep no old_inodes, the
    subvolume keeps its own, .snap lists every snapshot and each one reads
    back the content that was current when it was taken, and removing them
    all mints nothing either - rmsnap allocates a fresh snapid, so it moves
    the global seq just as creation does.  Checked under both settings of
    mds_use_global_snaprealm_seq_for_subvol, which pick a different
    @follows for pre_cow_old_inode();

  - a snapshot on /volumes itself: /volumes and the subvolume group MUST be
    cow'd, and / must not;

  - a snapshot on a plain directory: the same three-way outcome within a
    single ancestor walk.

The subvolume cases run with the snap purge gate shut and journal trimming
suppressed, so what they show is the absence of a CoW rather than reclaim
after the fact.

test_volumes.py::_verify_old_inodes() already asserts old_inodes counts on
these inodes, but with the gate open and without reading any snapshot back.

Assisted-by: Gemini
Signed-off-by: Venky Shankar <[email protected]>
Assert the one property that holds however the MDS chooses to represent
old versions: every snapshot must still read back exactly what was visible
when it was taken, through the real .snap path.  An assertion on
len(old_inodes) cannot catch a change that simply stops preserving data,
which is the failure mode worth guarding against when touching
CInode::pre_cow_old_inode() or MDCache::journal_cow_dentry().

The scenarios are the ones where the CoW decision and the staleness
decision consult different snaprealms:

  - a rename inside one snaprealm: the old name must stay readable in a
    snapshot that covered it, and the new name must not appear in one taken
    before the rename;

  - a rename across snaprealms, for a file and for a directory.  The
    directory cases matter most - pre_cow_old_inode() is only ever called
    on directories.  One covers a directory that inherits its realm, where
    the srnode gate in Server::_rename_prepare() reads get_oldest_snap();
    the other a directory that owns one, where that gate short-circuits.
    In both, the source realm's snapshot must keep serving the inode and
    the destination's older snapshot must not start covering it;

  - what a snapshot preserves beyond file content: mode and xattrs, plus
    mtime for a directory, which has no content at all;

  - a realm that goes empty because its snapshots were deleted, which is
    the state in which the MDS may advance an inode's first without
    copying, and snapshot rotation, where each removal moves the global
    seq the CoW runs against.

Not duplicated here: test_snapshots.py::test_multimds_hardlink already
covers hardlinks end to end, and test_multimds_past_parents covers a
cross-authority directory rename - but only by comparing the snapshot name
list, without reading content back.  The subvolume shape needs a real
subvolume and is checked in test_old_inodes.py::TestOldInodeCoW instead.

Assisted-by: Gemini
Signed-off-by: Venky Shankar <[email protected]>
@vshankar
vshankar requested review from a team, gregsfortytwo, ifed01, kotreshhr and xiubli October 7, 2026 04:27
@github-actions github-actions Bot added cephfs Ceph File System tests labels Oct 7, 2026
@dparmar18

Copy link
Copy Markdown
Contributor

I was sort of pushing something for snap_pruged_thru. I saw something interesting while testing my PR #72152. A takeover wrote stale snapshot data back to disk i.e. the new active MDS wrote back a copy the old one had purged, because snap_purged_thru had advanced. I still need to read the patch but does the second commit address this? from the commit description it looks like it (?)

@vshankar

vshankar commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

I was sort of pushing something for snap_pruged_thru. I saw something interesting while testing my PR #72152. A takeover wrote stale snapshot data back to disk i.e. the new active MDS wrote back a copy the old one had purged,

A failover is strictly not required for cleaning up old inodes, a log flush does the same with a minor caveat of the snap_pruged_thru comparison against last_destroyed, which in a certain case, if its never true, will never clean up old_inodes.

because snap_purged_thru had advanced. I still need to read the patch but does the second commit address this?

Yes.

EDIT: s/strictly/strictly not/

@vshankar

Copy link
Copy Markdown
Contributor Author

Just a note that this change is not targeted for Vampire. The plan is to bake in main branch post Vampire branch cut-off (provided that reviewers consider this as an acceptable change).

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

Tested it with vstart_runner, comparing base, first-commit-only and the full PR. The change works as described; details inline.

Why this matters. Snapshot ids are global, so a snapshot anywhere
in the tree makes the next change on every ancestor cow an old_inode,
even though no snapshot in the ancestor's own realm can ever reference
it. Shared ancestors such as /volumes and the group dirs collect
these from the snapshots of every subvolume below them. Before this
PR they were only purged after a snapshot was destroyed, so they pile
up in the inode, the dirfrag omap, the journal and the MDS cache.

old_inodes after 30 snapshots of one subvolume (test_old_inodes.py):

+-----------+------+----+--------------------------------+
| inode     | base | PR | base                           |
+-----------+------+----+--------------------------------+
| subvolume |   30 | 30 | ############################## |
| group     |   26 |  0 | ##########################     |
| /volumes  |   17 |  0 | #################              |
| /         |    9 |  0 | #########                      |
+-----------+------+----+--------------------------------+

The subvolume itself keeps its 30 old_inodes, and they are needed.
With only the first commit, old_inodes that are already stale (for
example ones written before an upgrade) survive commits and restarts.
With the full PR they are dropped on the next dirfrag commit. As a
side effect, the reproducer for the mds_snap_rstat crash in
https://tracker.ceph.com/issues/81672 crashes base within 20 rounds,
and did not crash in 20 and 30 rounds on the PR.

Regression runs on the PR:

  • test_old_inodes.py: 4/4 pass (3 fail on base).
  • test_snap_cow.py, test_volumes use_global_snaprealm_seq: pass.
  • test_snapshots.py: all pass except test_kill_mdstable, which fails
    the same way on base.
  • Snapshot rstat with nested realms and mds_snap_rstat=true stays
    correct, also across an MDS restart. I can send this as a qa test
    if you want it here.

The changes LGTM anyway except the minor nit, but it won't block it. Thank @vshankar

Comment thread src/mds/CInode.cc
/*
* @follows is taken from the global snaprealm so that @first stays
* monotonic across snaprealms, which is what makes an inode moving between
* realms easily managable - that is the sole reason the global seq is

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.

nit: "managable" -> "manageable"

Comment thread src/mds/CInode.cc
<< "], advancing first only on " << *this << dendl;
first = follows + 1;
return;
}

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.

Verified: test_old_inodes.py, old_inodes after 30 subvolume snapshots:

    |                                     | subvol | group | /volumes | / |
    |-------------------------------------|--------|-------|----------|---|
    | base                                | 30     | 26    | 17       | 9 |
    | PR                                  | 30     | 0     | 0        | 0 |
    | PR, global_seq_for_subvol=false     | 30     | 0     | 0        | 0 |

The ancestors also stay at 0 after all 30 snapshots are removed.

The check does not skip a cow that is needed. In both "must still cow"
cases (snapshot on /volumes, snapshot on a plain parent) the covered
inodes keep exactly one old_inode on base and on the PR. The only
difference is /, which goes from 1 on base to 0 on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants