Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Linux 6.17: fuse: add a quota admission lease for writeback-cache writes - #300

Closed
hazhou-ddn wants to merge 1 commit into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
hazhou-ddn:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1-qlease
Closed

hazhou-ddn wants to merge 1 commit into
DDNStorage:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1from
hazhou-ddn:redfs-ubuntu-hwe-6.17.0-16.16-24.04.1-qlease

Conversation

@hazhou-ddn

Copy link
Copy Markdown

With the writeback cache, a write returns once it has dirtied the page cache, and the data reaches the server later through writeback. By then the server cannot refuse it for quota without losing data that the application believes written, so quota has to be decided before the page is dirtied.

Add a quota admission lease. The server grants a lease, with a TTL, while the owner of the file is under quota: per uid and gid when the server enforces user and group quota, per dataset otherwise. A buffered write or a store to a shared writable mapping dirties the page cache only while the inode's lease is valid, and the server takes the writeback of those pages without a quota check.

The server offers FUSE_QUOTA_LEASE at INIT, and sets FUSE_QUOTA_ENABLED with it when quota is on for the mount. The quota state is fixed for the session; with quota off the kernel does no lease work.

The lease is checked together with the DLM write grant. When the grant is missing, the write lock request is sent and its reply carries the lease (struct fuse_dlm_lock_lease_out). When the grant is held but the inode has no lease, FUSE_QUOTA_ADMIT asks for one. An expired lease is renewed with FUSE_QADMIT_RENEW after writeback of its inodes has started, and a background work renews a valid lease at half its TTL.

Leases are kept per connection, hashed by lease id, with the inodes that use a lease linked to it. A REJECTED lease fails writes with EDQUOT for qlease_reject_hold_ms. Each lease part carries a generation, so a reply decided from an older voucher neither moves a deadline back nor rejects a lease a newer reply renewed. The server retries a transient failure itself and never answers a lease request with -EAGAIN, which the kernel treats as a protocol error, -EIO. A request the server ends with -EINTR, because the writer was interrupted while it retried, restarts the write when a signal is pending. page_mkwrite without a valid lease unmaps the page so that the store refaults through ->fault, which can admit with mmap_lock dropped; qlease_mmap_retry_ms bounds the retry of an admit error there.

A write reads the lease state without locks, under RCU and a seqcount; a per-lease spinlock serializes updates, and the connection lock covers only the hash and the inode links. The inode grows by the lease pointer, its link, the owner the lease was granted for and a pointer to the shared-mmap state, which is allocated only for shared writable mappings. Tracepoints
cover installs, replies, renewals, expiry and rechecks.

@hbirth

hbirth commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

I have no idea how relevant this is, but the mmap fault retry loop has no guaranteed exit.
You could carry the admission result or error from the slow path into the retried fault, and give up with SIGBUS or a backoff on non-progress

@yongzech yongzech left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed together with the redfsd part (red/red#30168 on GHE) and the libfuse part (DDNStorage/red-libfuse#139). The wire format matches redfsd and libfuse (fuse_quota_lease 32 bytes, lock lease reply 56 bytes, opcode 103, INIT bits 55/56).

The lease state machine looks correct: locking and lock order, RCU lifetime and reference counting, single-flight renewal, unmount teardown, owner-change detection, and the page_mkwrite/fault path. I found no bug in this PR on its own. One issue spans both sides; it's inline below.

Two related redfsd findings, raised on red#30168, touch this code:

  • On redfsd's TSD-only fallback, a renewal's gen falls below the installed l->gen, so fuse_qlease_apply_renewal() ignores renewals of a valid lease, and fuse_qlease_reject_applies() ignores rejections until the lease expires. The fix belongs in redfsd.
  • redfsd hands an owner with no quota limit ttl_ms = INT32_MAX (about 24.8 days), and this PR doesn't cap it. A kernel-side cap would also be a reasonable guard.

This PR adds no tests.

Comment thread fs/fuse/file.c Resolved
With the writeback cache, a write returns once it has dirtied the page
cache, and the data reaches the server later through writeback.  By then
the server cannot refuse it for quota without losing data that the
application believes written, so quota has to be decided before the
page is dirtied.

Add a quota admission lease.  The server grants a lease, with a TTL,
while the owner of the file is under quota: per uid and gid when the
server enforces user and group quota, per dataset otherwise.  A buffered
write or a store to a shared writable mapping dirties the page cache
only while the inode's lease is valid, and the server takes the
writeback of those pages without a quota check.

The server offers FUSE_QUOTA_LEASE at INIT, and sets FUSE_QUOTA_ENABLED
with it when quota is on for the mount.  The quota state is fixed for
the session; with quota off the kernel does no lease work.

The lease is checked together with the DLM write grant.  When the grant
is missing, the write lock request is sent and its reply carries the
lease (struct fuse_dlm_lock_lease_out).  When the grant is held but the
inode has no lease, FUSE_QUOTA_ADMIT asks for one.  An expired lease is
renewed with FUSE_QADMIT_RENEW after writeback of its inodes has
started, and a background work renews a valid lease at half its TTL.

Leases are kept per connection, hashed by lease id, with the inodes that
use a lease linked to it.  A REJECTED lease fails writes with EDQUOT for
qlease_reject_hold_ms.  Each lease part carries the mint sequence of
the TSD voucher and of the UG voucher it was decided from, or
FUSE_QLEASE_NO_UG when it read no UG voucher.  The kernel keeps the
highest of each and applies a reply only when no sequence it used is
older and at least one is newer, so a reply decided from an older
voucher neither moves a deadline back nor rejects a lease a newer reply
renewed.  The TTL a lease is installed with is capped at
qlease_max_ttl_ms, 120 s by default.  The server retries a transient failure
itself and never answers a lease request with -EAGAIN, which the
kernel treats as a protocol error, -EIO.  A request the server ends
with -EINTR, because the writer was interrupted while it retried,
restarts the write when a signal is pending.  page_mkwrite without a
valid lease unmaps the page so that the store refaults through ->fault,
which can admit with mmap_lock dropped; qlease_mmap_retry_ms bounds the
retry of an admit error there, and each successful admission lets one
store through even if its lease lapsed before the refault.

A write lock request that admits nothing, grant-ahead or a load fault,
sets FUSE_DLM_LOCK_NO_ADMIT in the former reserved field of struct
fuse_dlm_lock_in, so the server fetches no voucher for it.

A write reads the lease state without locks, under RCU and a seqcount;
a per-lease spinlock serializes updates, and the connection lock covers
only the hash and the inode links.  The inode grows by the lease
pointer, its link, the owner the lease was granted for and a pointer to
the shared-mmap state, which is allocated only for shared writable
mappings.  Tracepoints
cover installs, replies, renewals, expiry and rechecks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Hai Zhong Zhou <hazhou@ddn.com>
@hazhou-ddn
hazhou-ddn force-pushed the redfs-ubuntu-hwe-6.17.0-16.16-24.04.1-qlease branch from 910990d to c48b61a Compare November 19, 2026 14:59
@hazhou-ddn

Copy link
Copy Markdown
Author

@hbirth You're right: errors already ended the loop through the SIGBUS mark, but success did not. A successful admission returned VM_FAULT_RETRY, and the retried fault required a valid lease again. If a short TTL lapsed before the refault, or a reserved QUOTA_OFF reply changed no lease, the fault admitted again, and page_mkwrite could unmap and send the store back, with no bound. Each successful admission on the fault path, with mmap_lock dropped or blocking in place, now records an admitted token on the inode next to the error mark. The retried fault's fast path accepts it, and page_mkwrite consumes it once, so each admission lets one store through. Like the error mark, the token expires after a second.

@yongzech Thanks for the review. The two findings from the redfsd side:

  • TSD-only fallback gen. Fixed by changing the wire format. struct fuse_quota_lease now carries tsd_seq and ug_seq in place of gen, plus FUSE_QLEASE_NO_UG for a reply decided without a UG voucher. It is 40 bytes, and the lock reply is 64. The kernel keeps the highest seq of each kind and takes a reply as newer when no seq it used is older and at least one is newer (fuse_qlease_reply_newer()). That covers the fallback, which compares on TSD alone, and also a renewal that refreshes only the UG voucher, which a min of the two would have dropped. A reply newer in one seq and older in the other came from two sthreads with vouchers of different ages, and it is not applied over a valid lease. The reasoning, including why not the sum, the min or a counter, is in red's D11.
  • TTL cap. Added the qlease_max_ttl_ms module parameter, default 120 s, applied to both TTL installs. One correction: an owner with no quota limit gets a voucher TTL of about 52 s. INT32_MAX comes only from a system voucher (qv_sys()). The cap is above the server's longest real voucher TTL of 100 s, so in practice it only clips the system voucher.
  • Tests. This PR adds no in-kernel tests. The ordering rule is mirrored and unit-tested in redfsd (quota_lease_reply_newer() in quota_lease_test.cpp), and the end-to-end cases (a write at quota failing at write(2), a chown racing a lock request, the mmap paths) belong in the test-repo pytests the spec lists.

The kernel changes are synced into red's contrib/redfs.ko 6.17 tree, and the matching libfuse change is on DDNStorage/red-libfuse#139.

@hbirth hbirth changed the title fuse: add a quota admission lease for writeback-cache writes Linux 6.17: fuse: add a quota admission lease for writeback-cache writes Nov 20, 2026

@hbirth hbirth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM
We just have to solve the conflict ... and then we can merge it

@hbirth

hbirth commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

After solving the conflict I will push this directly to DDNStorage

@hbirth

hbirth commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

This is already merged

@hbirth hbirth closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants