NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/54504: -9/-current WAPBL panic: current transaction too big to flush



> Date: Sat, 26 Jul 2025 12:00:39 -0700
> From: Konrad Schroder <perseant%hhhh.org@localhost>
> 
> Here is another version of the patch.  The problem fixed by this version 
> is that cylinder group bitmap block writes are not accounted for by 
> WAPBL before the decision to flush is made; they are added only when the 
> transaction is flushed.  On a very fragmented filesystem this can cause 
> a transaction overflow if a sufficiently large file is truncated, or 
> even created, since the number of CG bitmap blocks might be equal to the 
> number of blocks already present in the transaction.  This patch solves 
> this issue by having FFS account for the dirty CG blocks and inform 
> WAPBL how much space they will take up.  In addition it performs the 
> same kind of periodic check as my original patch, but with much higher 
> threshold since we can now know the true size of the transaction.
>
> The patch is available at
>
>      http://www.hhhh.org/perseant/54504/ffs-wapbl-check-v4i.diff

Let me see if I understand this correctly.  A file system operation
that deallocates blocks -- truncate, or, in principle, discard or
whatever punches a hole in a file system -- will work something like
this:

1. wapbl_begin
   => wl_bufbytes, wl_bufcount, or wl_dealloccnt is too small to flush
2. Some combination of wapbl/block operations:
   --> ...
   --> bread/bdwrite(blk1)
   --> ...
   --> wapbl_register_deallocation(blk2)
   --> ...
   --> bread/bdwrite(blk3)
   --> ...
   --> wapbl_register_deallocation(blk4)
   --> ...
   --> bread/bdwrite(blk5)
   --> ...
3. wapbl_end

The next transaction will do:

1. wapbl_begin
   => wl_bufbytes, wl_bufcount, or wl_dealloccnt is large enough, so:
      --> wapbl_flush
          --> ffs_wapbl_sync_metadata
              --> ffs_blkfree(blk2)
                  --> bread/bdwrite(cgblk6)
              --> ffs_blkfree(blk4)
                  --> bread/bdwrite(cgblk7)
              --> ffs_cgupdate
                  --> bread/bdwrite(cgblk8)
          --> assert wapbl_transaction_len(wl) fits

For the first transaction, we had enough space for the three bdwrites
and the two deallocs -- but not enough for three additional bdwrites
in ffs_blkfree and ffs_cgupdate.  And so we trip the assertion.

What your change does is record which cgs we are updating in a
transaction, and count one fs block toward the size of the transaction
for each cg to be updated, so that wapbl_begin knows up front about
the additional bdwrites that wapbl_flush would need to issue and can
therefore wapbl_flush earlier when there is still space for it to
succeed without tripping the assertion.  Is that right?


I think there is something I don't understand here, though.  You are
counting each cg toward the transaction size in:

. ffs_alloc (which allocates an unused fs block from the file
  system's free space)

. ffs_realloccg (which extends a fragment into a block or allocates
  a block and moves the fragment to it)

. ffs_blkfree (which frees a block when flushing a transaction)

(a) Why do we need to count the cg when allocating?  Aren't the
    bdwrites for the cg update in that case issued by the file
    system between wapbl_begin/end, not deferred to wapbl_flush?

(b) Shouldn't we count the extra size in ffs_truncate when issuing
    wapbl_register_deallocation between wapbl_begin/end, not in the
    middle of wapbl_flush with ffs_blkfree -- isn't it too late at
    that point?

It's likely I misunderstood the mechanism of this patch.


That said, more broadly, I would like to do two things:

1. Have wapbl_begin require a commitment up front to an upper bound on
   the number of blocks/bytes/deallocs/&c. the caller will issue
   before wapbl_end.  This requires some analysis to ensure the bounds
   are correct!  But we need this kind of analysis anyway in order to,
   e.g., verify whether a candidate log size is big enough to support
   file system operations at all.

2. Add a new logical record for truncate(n,k), to truncate inode n to
   k bytes, as proposed in PR kern/58553 (ffs: garbage data appended
   after crash, https://gnats.NetBSD.org/58553), which can be split
   into multiple physical transactions without losing atomicity, so
   that:

   (a) truncate _has_ an upper bound on the transaction size
       (currently it does not and we just break it into a non-atomic
       loop of transactions in sequence to truncate the file
       piecemeal), and

   (b) we can also solve the garbage-data-appended-after-crash problem
       by having write to a k-byte file issue a truncate(n,k) record
       and then later remove it once the file has been synced.



Home | Main Index | Thread Index | Old Index