code: mafs

Download patch

ref: dc6c8525bacd30794e6e7b7ad6604d112411f8e4
parent: 09233644202cb9d4b5623424db913767e42b29fc
author: 9ferno <gophone2015@gmail.com>
date: Wed Oct 26 13:50:26 EDT 2022

updated Iobuf structure in the document

--- a/docs/mafs.ms
+++ b/docs/mafs.ms
@@ -663,7 +663,7 @@
 .sp
 An Iobuf is protected by a read-write lock (RWlock). This ensures synchronization across multiple processes updating the same file.
 .sp
-getbuf(), putbuf() and putbuffree() are used to manage Iobuf's. The contents of an Iobuf is not touched unless it is locked between getbuf(), putbuf() and putbuffree() calls.
+getbuf(), putbuf() and putbuffree() are used to manage Iobuf's. The contents of an Iobuf is not touched unless it is locked between getbuf(), putbuf() and putbuffree() calls. The Iobuf.dirties Ref is decremented by the writer's dowrite() without a lock(). This is to avoid deadlocks between putbuf() and the writer especially when the writer queue is full.
 .sp
 allocblock() allocates a free block into an Iobuf.
 .sp
@@ -688,8 +688,7 @@
 		u8	*xiobuf;	/* "real" buffer pointer */
 		Content *io;	/* cast'able to contents */
 	};
-	u32	dirties;	/* number of dirty blocks yet to be written by the writer */
-	u8 tofree;		/* free this Iobuf after the dirty blocks are written to the disk */
+	Ref	dirties;	/* number of dirty blocks yet to be written by the writer */
 };
 .fi
 .sp
--- a/iobuf.c
+++ b/iobuf.c
@@ -154,7 +154,7 @@
 		much either way. If it does, there is a changelru() function to do so in the
 		git history that can be reused.
 
-		dirties is decremented without a wlock() on the buffer.
+		dirties is decremented without a wlock() on the buffer in dowrite().
 		Using a wlock() in dowrite() deadlocks with putwrite().
 		getbuf() guarantees that even a free'ed block cannot be
 		stolen until the dirties == 0. This avoids dirty blocks