code: mafs

Download patch

ref: 5a0f60650e7e27d4340313edb141fd728bf099d3
parent: a94ee500f9e1a478269b1b930478902692053bf3
author: 9ferno <gophone2015@gmail.com>
date: Sun Dec 25 04:12:23 EST 2022

cleaned up searchlrus

--- a/extents.c
+++ b/extents.c
@@ -37,14 +37,15 @@
 	if(es == nil || es->lowest == nil)
 		panic("searchlrus: should not happen");
 
-	if(es->lru == nil)
-		eclosest = e = es->lowest;
-	else
-		eclosest = e = es->lru;
+	if(es->lru == nil){
+		*closest = belongs(es->lowest, blkno);
+		return es->lowest;
+	}
 
+	eclosest = e = es->lru;
 	*closest = belongs(e, blkno);
 	if(*closest == 0)
-		return es->lru;
+		return eclosest;
 	for(e = e->next; e != es->lru; e = e->next){
 		howclose = belongs(e, blkno);
 		if(abs(howclose) < abs(*closest)){
@@ -67,6 +68,7 @@
 	if(es == nil || es->lowest == nil)
 		panic("searchlrusbysize: should not happen");
 
+	// print("searchlrusbysize len %llud e->len %llud\n", len, e->len);
 	if(es->lru == nil){
 		*closest = len - es->lowest->len;
 		return es->lowest;
@@ -74,9 +76,8 @@
 
 	eclosest = e = es->lru;
 	*closest = len - e->len;
-	// print("searchlrusbysize len %llud e->len %llud\n", len, e->len);
 	if(closest == 0)
-		return es->lru;
+		return eclosest;
 	for(e = e->next; e != es->lru; e = e->next){
 		howclose = len - e->len;
 		if(abs(howclose) < abs(*closest)){