XFS deferred operation
An XFS deferred operation postpones metadata work to a later transaction to satisfy locking or reservation constraints.
A chain of rolling transactions is not atomic in the journal, since recovery replays only up to the last committed member of the chain. An operation that needs several transactions therefore logs intent items, so that recovery can finish it once the first transaction is on disk. This is distinct from delayed logging's journal batching. [1]
Each roll logs an intent item for every pending work item, and a done item is logged as soon as the work completes. If a finishing step runs short of reservation, it logs a done item for the finished part and a new intent for the rest in the same transaction, then rolls and continues. A reference-count update on an n-block extent can change as many as n records, which is why such work is split. [2]
The v6.16 source declares ten deferred operation types, covering block mapping, reference counts, reverse mappings, extent freeing, extended attributes and mapping exchange, including real-time variants. Up to 5 inodes and 2 buffers can be held across a roll, and the inode limit comes from rename with parent pointers. [4]
The source comment's remapping example spans six transactions, t0 to t5. A crash before t2 commits makes recovery replay five logged intents and then generate three more for the work they lead to. [2]
Relations
Advantages
- Work too large for one transaction reservation can still be completed by log recovery after a crash. [1, 2]
Limitations
- Inodes stay locked across the whole chain of rolling transactions, so nothing else can read or write them until it ends. [1]
Citations
- Linux v6.16: XFS Logging Design, introduction and transactions in XFS
- Linux v6.16: xfs_defer.c, deferred operations comment and remapping example
- Linux v6.16: xfs_defer.h, deferred operation types and resources held across a transaction roll
Further reading
Sources & caveats
- design is the XFS Logging Design document in the Linux v6.16 tree, reread on the access date in the introduction and the transactions section.
- defer-code is xfs_defer.c at v6.16, read in the header comment on deferred operations and its remapping example.
- defer-header is xfs_defer.h at v6.16, read for the declared operation types and the held-resource limits.
- Ten types, 5 inodes and 2 buffers come from defer-header. Six transactions, five replayed intents and three generated intents come from defer-code.