shithub: mc

Download patch

ref: 32f5a7c900bcc3b83d410cdc052c574f32ec349d
parent: 25db385525a84c119a8d8b73f55ce56d8a9c1dc2
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Mar 21 18:33:49 EDT 2017

Merge freed big allocations.

	This should cut the amount of time we spend bouncing
	back and forth into the kernel to tweak vm shit.

--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -194,12 +194,26 @@
 
 const bigfree = {p, sz
 	var minsz, minp, minidx
+	var endp, endcache
 
 	minp = p
 	minidx = -1
 	minsz = align(sz, Align)
+	endp = ((p : intptr) + (sz : intptr) : byte#)
 	lock(memlck)
 	for var i = 0; i < cache.len; i++
+		endcache = ((cache[i].p : intptr) + (sz : intptr) : byte#)
+		if cache[i].p == endp
+			cache[i].sz += sz
+			cache[i].p = p
+			minsz = 0
+			break
+		elif endcache == p
+			cache[i].sz += sz
+			minsz = 0
+			break
+		;;
+		/* check for merges */
 		if cache[i].sz < minsz
 			minsz = cache[i].sz
 			minp = cache[i].p