Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios Kernel

Coherency

Single-page view · as markdown

Coherency

Peios Kernel / Internals / StrataFS / Coherency

Use these articles to understand coherency in the Peios kernel.

  • Model and revalidation
  • Inode Identity and Lifecycle

Model and revalidation

Peios Kernel / Internals / StrataFS / Coherency

Every stratum of a mount may be modified at any time by an agent that does not know stratafs exists. stratafs observes such changes without being told of them.

No coordination #

There is no notification machinery anywhere in the filesystem — no fsnotify registration, no inotify, nothing a stratum's filesystem is expected to report. No writer announces a change, quiesces, or participates in any protocol. Every resolution is performed from scratch by re-walking the stratum path string, so nothing has to be told anything.

What can change a resolution #

A resolution depends only on which names each participating stratum directory holds and what type each entry has. It does not depend on the contents of any file.

A change to an object's contents therefore requires no action at all. stratafs inodes carry no address-space operations; there is no second page cache, and every data operation is forwarded to a backing file opened on the provider. A change to that object is observed through the mount immediately and by construction, because there is nothing to invalidate.

A change to the structure of a participating stratum directory — an entry created, removed, renamed, or replaced by one of another type — may change which stratum provides a name. Revalidation covers how that is handled, which is by not caching anything.

The guarantee #

A structural change in a stratum becomes visible to any resolution begun after the stratum's own filesystem exposes that change to an ordinary lookup. stratafs adds no delay of its own: there is no timeout, no jiffies comparison, no generation counter, and no resolution cache to serve a stale answer from.

It cannot anticipate a change the underlying filesystem is not yet reporting. A network filesystem holding an attribute cache does not show a change to stratafs any sooner than to any other caller, and nothing claims otherwise.

Resolutions already completed are not revisited. Every regular-file open is detached onto a descriptor-private dentry and inode holding their own reference to the provider, and I/O runs against the file opened at that time, so later masking or removal in any stratum cannot reach that descriptor. It is not re-pointed and it does not fail. A process holding a configuration file open across a package upgrade continues to read the file it opened.

The one exception is copy-up, which Inode Identity and Lifecycle covers: a descriptor whose own write caused a copy-up keeps its inode while that inode's backing object becomes the copy.

The open file description retains its sequential file position across copy-up. read and write advance that position, and lseek with SEEK_CUR uses it even after the backing file changes. Positioned I/O through pread or pwrite leaves it unchanged.

Live strata #

Because resolutions are made against current state, and because a stratum is a path rather than a directory object (The Stratum Stack), a stratum's directory may be replaced wholesale — by a package transaction, by a reconciler, by an administrator — while the mount is live, with no remount and no interruption to callers. That is the requirement the filesystem exists to satisfy, and Revalidation is the whole of its cost.

The specification permits an implementation to cache resolutions, subject to a version tuple recorded per stratum and an identity comparison on reuse. This implementation caches nothing, and so implements neither.

Always invalidate #

d_revalidate returns 0 for every dentry except the mount root. The VFS therefore discards the dentry and re-enters lookup on every path walk, and the lookup re-resolves the parent and the child from their relative path strings across every stratum.

Nothing is memoised. No version value is recorded, no directory identity is retained for comparison, no nearest-existing-ancestor walk happens, and no i_version is read anywhere in the filesystem. The per-dentry provider path that is retained is not a cache of a resolution: it is dropped when the dentry is released, and the dentry is released on the next walk.

The specification's machinery exists to know when a cached resolution has gone stale. With no cached resolution, the questions it answers do not arise:

What the tuple would detectWhy it is unnecessary here
A stratum gaining or losing a nameThe next walk resolves the name afresh
A stratum's directory appearingThe next walk finds it
A stratum's directory removed, renamed away, or renamed overThe next walk finds nothing, or finds the replacement

The result is strictly stronger than the specification requires, in the safe direction. The internal filesystem-domain, fallback-inode and staging-name counters do not validate cached resolutions.

What it costs #

The cost is real and lands on the hottest path in the kernel.

d_revalidate refuses RCU-walk unconditionally: a lookup in RCU mode returns ECHILD and the walk is retried in ref-walk mode, and the directory permission check does the same. RCU-walk is therefore never used on a stratafs mount, and the fallback is taken always rather than only where it genuinely cannot proceed.

The refusal, invisible to the caller by design, is visible at two tracepoints. stratafs:stratafs_rcu_walk_refused marks the directory permission check turning a walk back under MAY_NOT_BLOCK — in practice the first stratafs directory a walk must traverse does this, so it is the point that actually takes every walk out of RCU mode. stratafs:stratafs_d_revalidate records each revalidation verdict — mount cookie, merged inode number (zero for a negative entry), whether the call was in RCU mode, and the return value — and because the permission check fires first, every recorded call arrives already in ref-walk mode; its -ECHILD branch is the backstop. Like every PKM tracepoint, neither records a pathname.

What replaces it, per path component, is one full filename_lookup per stratum — up to sixteen — plus one merged resolution per proper prefix of the path, for the ancestor-masking test of Type Conflicts. Where a mount is established over a directory of executables, that lies on the path of every program execution, and there is no dentry cache hit to avoid it.

This is the one part of the filesystem whose cost is worth measuring rather than assuming, and closing the gap — recording enough per resolution to reuse one safely, and making the comparison RCU-safe — is tracked as work in its own right.

Inode Identity and Lifecycle

Peios Kernel / Internals / StrataFS / Coherency

stratafs presents its own inodes, allocated from its own superblock. Each stands for a provider object and forwards operations to it; none holds file data, directory entries, or a security descriptor.

Reported identity #

The device identifier reported for any object in a mount is the stratafs superblock's own anonymous device, not the provider's. getattr calls the provider's directly and then overrides dev, ino and, for directories, nlink; all four inode-operations tables install that same getattr.

The inode number is derived from the provider filesystem's reported inode number and a small mount-local identifier for its reported device. The device identifier distinguishes filesystem domains, not stratum positions: a stratum can cross mount points. The reported device also distinguishes Btrfs subvolumes, which can share a kernel superblock and inode numbers. Two paths to the same provider identity, including hard links and bind-mounted aliases, therefore report the same number.

Derivation reserves the high bit for allocated fallback numbers. A self-delimiting tag in the low bits identifies the filesystem domain; the provider inode number occupies the remaining bits. Small provider numbers stay small enough to derive again through nested stratafs views. Neither the bit layout nor the mount-local domain assignment is a persistent identifier or an ABI that callers should decode. Numbers may differ between mounts; within a mount, reloading the same provider identity after cache eviction produces the same number.

Only identities that cannot fit, or providers that do not report a usable inode number, use the fallback map. It allocates a distinct number and holds a reference on the provider inode until unmount to prevent address reuse. Repeated encounters with that provider reuse its allocation. Synthetic provider-less roots use the same allocated number space without a provider reference. Exhaustion returns EOVERFLOW rather than wrapping, including on 32-bit builds. An attribute lookup error is returned to the caller instead of silently assigning a new identity.

The mount root #

The root inode is created once, when the superblock is filled, and the root dentry is never replaced — d_revalidate returns 1 for it. Its provider is nevertheless re-resolved live on every use, and the number follows: resolving the root's provider derives or looks up its identity and writes the result to the root inode's number. Mode, owner, timestamps and number are therefore all current.

That the number follows is what keeps Inode Identity and Lifecycle's identity rule true at the root. Identity belongs to the provider, so the number the root reports is the number every other merged path to that same provider reports; without it, a root whose provider is also reachable elsewhere would report a different number from that other path — two paths naming one object, unequal. That is the false-inequality direction, the one that breaks hard-link detection.

Where no stratum root exists at mount time, the root receives a stable synthetic number, distinct from derived provider numbers. If a provider later appears, the root's number follows that provider.

Attributes of merged directories #

A merged directory's owner, group, mode and timestamps are its provider's — the highest-precedence participating directory — taken straight from a getattr on the provider path, so what is reported is a real directory's attributes rather than a composite.

The security descriptor of a merged directory is not a single descriptor; Checks on Merged Directories defines which participating directory's descriptor governs each operation.

The synthetic link count #

Its link count is forced to 1, both in the cached inode and in the reported stat. The true count of subdirectories spans strata and cannot be maintained, so the value carries no meaning beyond indicating that the object is a directory. Nothing should infer a subdirectory count from it.

Provider change #

When the provider for a path changes — because a higher-precedence stratum gained the name, because the previous provider's entry was removed, or because copy-up produced a new object — a resolution of that path yields a new inode. An inode reached by resolution is never re-associated with a different provider.

That is required because per-inode state is populated from the provider the inode was resolved against and is not in general re-derivable. In particular KACS caches a security descriptor against the outer stratafs inode; applying it to a different provider's object would govern access to one object by another object's descriptor.

The implementation enforces this bluntly. The one function that re-associates an inode with a new provider is reachable from exactly one call site, on the descriptor-private dentry created at open, and never on a hashed dentry reached by resolution. A copy-up performed for a path rather than a descriptor drops the dentry instead of rebinding it. Provider change by masking or removal needs no special handling at all, because the unconditional invalidation of Revalidation forces a fresh lookup and a fresh inode.

An object's reported inode number therefore changes when its provider changes. That is expected: it is the same change a caller would observe if the file had been replaced, which is what has happened.

Descriptors already open #

A descriptor open at the moment its own operation copies its object up is not re-pointed. It keeps the inode it was opened against, and that inode's backing object becomes the copy: the provider path and provider inode are swapped in place under a per-inode lock, the attributes are refreshed, and the backing file is replaced, so subsequent operations through the descriptor reach the copy.

This is the one case in which an inode's backing object changes, and it is safe for the reason the general rule exists: copy-up preserves the source's security descriptor exactly (Descriptors on Copy-Up), so the descriptor cached on that inode remains correct for the copy.

At open, the descriptor-private inode is deliberately given the path inode's number, so before any copy-up fstat and stat agree. After one they do not: the descriptor keeps the number assigned to the pre-copy-up provider, while a fresh resolution of the path derives or allocates a number for the copy. Both name the copy; the numbers disagree for as long as that descriptor lives. Failure Modes records it.

Lifetime #

A stratafs inode holds a reference on its provider inode for as long as it lives, released on eviction. The dentry additionally holds a full path reference. Ordinary derived identities add no provider reference and no per-inode entry to the identity map. Walking a persistent-backed view and dropping caches can therefore reclaim the provider inodes while the stratafs mount remains live. The per-mount device-domain table stays until unmount; its size tracks encountered filesystem domains rather than the number of files walked.

The fallback alone adds a provider reference held until unmount. That cost applies only to identities that could not be derived.

Renaming a provider out of the view and back, or evicting and reloading its cached inode, preserves its derived identity. Ordinary inode-number reuse by the provider after deletion remains possible, just as it is when accessing that filesystem directly.

Releasing the last reference to a stratafs inode modifies nothing: eviction truncates its own empty mapping, clears the inode, drops the provider reference, and frees its private state.

Peios Learn — documentation for Peios software.

Built with Trail.