NetBSD-Bugs archive

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

Re: kern/60621 (panic: ufs_inactive: dirty filesystem?)



On Thu, Nov 19, 2026 at 12:27:54AM +0000, Taylor R Campbell wrote:
<snip>
> > * The "wapbl_flush: current transaction too big to flush" panic
> > goes back to PR kern/47146 at least.  It was fixed with a
> > reorganization of ffs_truncate() and the change to
> > wapbl_register_deallocation() to return EAGAIN on resource shortage.
> > Unfortunately th evaluation of resource shortage looks incomplete as
> > only "wl_dealloccnt" is checked.  Replacing this check with
> > the "doflush" check already in wapbl_begin() but replacing "/ 2"
> > with "* 3 / 4" I cannot reproduce this panic anymore.  I use 75% instead
> > of 50% so after wapbl_register_deallocation() returning EAGAIN the
> > next wapbl_begin() will always flush.  This is the diff:
> > 
> > --- sys/kern/vfs_wapbl.c	Wed Nov 11 15:17:24 2026 +0100
> > +++ sys/kern/vfs_wapbl.c	Wed Nov 18 15:39:40 2026 +0100
> > @@ -2193,7 +2193,18 @@ wapbl_register_deallocation(struct wapbl
> >  
> >  	mutex_enter(&wl->wl_mtx);
> >  
> > -	if (__predict_false(wl->wl_dealloccnt >= wl->wl_dealloclim)) {
> > +	int doflush;
> > +	unsigned lockcount;
> > +
> > +	lockcount = wl->wl_lock_count;
> > +	doflush = ((wl->wl_bufbytes + (lockcount * MAXPHYS)) >
> > +		wl->wl_bufbytes_max * 3 / 4) ||
> > +	    ((wl->wl_bufcount + (lockcount * 10)) >
> > +		wl->wl_bufcount_max * 3 / 4) ||
> > +	    (wapbl_transaction_len(wl) > wl->wl_circ_size * 3 / 4) ||
> > +	    (wl->wl_dealloccnt >= (wl->wl_dealloclim * 3 / 4));
> > +
> > +	if (__predict_false(doflush)) {
> >  		if (!force) {
> >  			error = SET_ERROR(EAGAIN);
> >  			goto out;
> 
> I would believe this mitigates the problem, and have no objection to
> committing it, but:
> 
> 1. I'm not convinced it _fixes_ the problem and I would like to see
>    some clearer explanation of the bounds written down.
> 
>    Surely the bounds depend on the maximum size of any transaction
>    issued by the file system, no?  And that in turn depends both on
>    the logic in the file system and potentially on the content like
>    the shape of the indirect block tree when it is recursively
>    processed.  But we have no mechanism to pass fs-specific bounds on
>    transaction size into wapbl_start or wapbl_begin.
> 
>    The ffs_truncate workaround (by which I assume you mean
>    https://mail-index.netbsd.org/source-changes/2016/10/28/msg078723.html)
>    is also just that: a workaround, not a solution, which makes
>    truncate operations (including unlink) non-atomic by breaking them
>    into multiple transactions in a loop.

Sure.

> 2. It would be nice if this flushing criterion were factored out
>    somewhere and not copied & pasted in two places that will get out
>    of sync.
> 
> 3. Would like to make sure the multiplications don't overflow, by
>    asserting (and otherwise enforcing) bounds on wl_bufbytes_max,
>    wl_bufcount_max, wl_circ_size, and wl_dealloclim < SIZE_MAX/3.

Current diff is attached, if noone objects I will commit over the weekend.

-- 
J. Hannken-Illjes - hannken%netbsd.org@localhost

--- sys/kern/vfs_wapbl.c	Fri Nov 20 09:44:45 2026 +0100
+++ sys/kern/vfs_wapbl.c	Fri Nov 20 16:23:03 2026 +0100
@@ -450,6 +450,27 @@ wapbl_dkcache_init(struct wapbl *wl)
 		wl->wl_jwrite_flags |= B_MEDIA_DPO;
 }
 
+static bool
+wapbl_should_flush(struct wapbl *wl, int nquarter)
+{
+	unsigned lockcount;
+
+	KASSERT(mutex_owned(&wl->wl_mtx));
+
+	/*
+	 * XXX this needs to be made much more sophisticated.
+	 * perhaps each wapbl_begin could reserve a specified
+	 * number of buffers and bytes.
+	 */
+	lockcount = wl->wl_lock_count;
+	return ((wl->wl_bufbytes + (lockcount * MAXPHYS)) >
+		wl->wl_bufbytes_max / 4 * nquarter) ||
+	    ((wl->wl_bufcount + (lockcount * 10)) >
+		wl->wl_bufcount_max / 4 * nquarter) ||
+	    (wapbl_transaction_len(wl) > wl->wl_circ_size / 4 * nquarter) ||
+	    (wl->wl_dealloccnt >= (wl->wl_dealloclim / 4 * nquarter));
+}
+
 static int
 wapbl_start_flush_inodes(struct wapbl *wl, struct wapbl_replay *wr)
 {
@@ -1203,24 +1224,12 @@ wapbl_circ_write(struct wapbl *wl, void 
 int
 wapbl_begin(struct wapbl *wl, const char *file, int line)
 {
-	int doflush;
-	unsigned lockcount;
+	bool doflush;
 
 	KDASSERT(wl);
 
-	/*
-	 * XXX this needs to be made much more sophisticated.
-	 * perhaps each wapbl_begin could reserve a specified
-	 * number of buffers and bytes.
-	 */
 	mutex_enter(&wl->wl_mtx);
-	lockcount = wl->wl_lock_count;
-	doflush = ((wl->wl_bufbytes + (lockcount * MAXPHYS)) >
-		wl->wl_bufbytes_max / 2) ||
-	    ((wl->wl_bufcount + (lockcount * 10)) >
-		wl->wl_bufcount_max / 2) ||
-	    (wapbl_transaction_len(wl) > wl->wl_circ_size / 2) ||
-	    (wl->wl_dealloccnt >= (wl->wl_dealloclim / 2));
+	doflush = wapbl_should_flush(wl, 2);
 	mutex_exit(&wl->wl_mtx);
 
 	if (doflush) {
@@ -2193,7 +2202,7 @@ wapbl_register_deallocation(struct wapbl
 
 	mutex_enter(&wl->wl_mtx);
 
-	if (__predict_false(wl->wl_dealloccnt >= wl->wl_dealloclim)) {
+	if (__predict_false(wapbl_should_flush(wl, 3))) {
 		if (!force) {
 			error = SET_ERROR(EAGAIN);
 			goto out;



Home | Main Index | Thread Index | Old Index