code: mafs

Download patch

ref: abc8e796f627bf35b8f2971f5a0f8f477b0ad0eb
parent: 752335306e2813baceb1a690cba7232d895cc7c1
author: 9ferno <gophone2015@gmail.com>
date: Thu Dec 8 15:08:49 EST 2022

allocate Maxdatablockunits from the top and the rest from the bottom

--- a/extents.c
+++ b/extents.c
@@ -456,7 +456,7 @@
 }
 
 u64
-slice(Extents *es, Extent *e, u64 len)
+slicetop(Extents *es, Extent *e, u64 len)
 {
 	u64 oldstart, oldlen;
 
@@ -464,6 +464,19 @@
 		panic("pluck(): should not happen");
 	oldlen = e->len;
 	oldstart = pluck(es, e);
+	add(es, oldstart, oldlen - len);
+	return oldstart+oldlen-len;
+}
+
+u64
+slicebottom(Extents *es, Extent *e, u64 len)
+{
+	u64 oldstart, oldlen;
+
+	if(es == nil || e == nil || es->lru == nil || len == 0 || e->len <= len)
+		panic("pluck(): should not happen");
+	oldlen = e->len;
+	oldstart = pluck(es, e);
 	add(es, oldstart+len, oldlen - len);
 	return oldstart;
 }
@@ -488,8 +501,12 @@
 		showextents(2, msg, es);
 	}*/
 again:
-	for(e = lowest(es); e != nil && e->len < n; e = e->high)
-		;
+	if(n == Maxdatablockunits)
+		for(e = highest(es); e != nil && e->len < n; e = e->low)
+			;
+	else
+		for(e = lowest(es); e != nil && e->len < n; e = e->high)
+			;
 	if(e == nil){
 		snprint(msg, 64, "balloc() %llud %s: waiting\n", n, es->name);
 		showextents(2, msg, es);
@@ -503,8 +520,12 @@
 	}
 	else if(e->len == n)
 		start = pluck(es, e);
-	else /* found something bigger */
-		start = slice(es, e, n);
+	else{ /* found something bigger */
+		if(n == Maxdatablockunits)
+			start = slicetop(es, e, n);
+		else
+			start = slicebottom(es, e, n);
+	}
 
 	qunlock(&es->lck);
 	return start;
--- a/tests/test.3/blocks/40956
+++ /dev/null
@@ -1,1 +1,0 @@
-Tblank