shithub: riscv

Download patch

ref: f63d1d3ced81702e0eadf56228a54a467278b0d4
parent: 99d54e420ed021a738d9f835f5949e78202c3b2e
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 1 22:37:23 EST 2022

git: size cache in bytes, not objects

git used to track cache size in object
count, rather than bytes. This had the
unfortunate effect of making memory use
depend on the size of objects -- repos
with lots of large objects could cause
out of memory deaths.

now, we track sizes in bytes, which should
keep our memory usage flatter.

--- a/sys/src/cmd/git/git.h
+++ b/sys/src/cmd/git/git.h
@@ -4,6 +4,7 @@
 #include <flate.h>
 #include <regexp.h>
 
+typedef struct Capset	Capset;
 typedef struct Conn	Conn;
 typedef struct Hash	Hash;
 typedef struct Delta	Delta;
@@ -26,6 +27,8 @@
 	Npackcache	= 32,
 	Hashsz		= 20,
 	Pktmax		= 65536,
+	KiB		= 1024,
+	MiB		= 1024*KiB,
 };
 
 enum {
@@ -241,9 +244,9 @@
 
 extern Reprog	*authorpat;
 extern Objset	objcache;
+extern vlong	cachemax;
 extern Hash	Zhash;
 extern int	chattygit;
-extern int	cachemax;
 extern int	interactive;
 
 #pragma varargck type "H" Hash
--- a/sys/src/cmd/git/pack.c
+++ b/sys/src/cmd/git/pack.c
@@ -65,8 +65,8 @@
 Objset objcache;
 Object *lruhead;
 Object *lrutail;
-int	ncache;
-int	cachemax = 4096;
+vlong	ncache;
+vlong	cachemax = 512*MiB;
 Packf	*packf;
 int	npackf;
 int	openpacks;
@@ -158,7 +158,7 @@
 	if(!(o->flag & Ccache)){
 		o->flag |= Ccache;
 		ref(o);
-		ncache++;
+		ncache += o->size;
 	}
 	while(ncache > cachemax && lrutail != nil){
 		p = lrutail;
@@ -168,8 +168,8 @@
 		p->flag &= ~Ccache;
 		p->prev = nil;
 		p->next = nil;
+		ncache -= p->size;
 		unref(p);
-		ncache--;
 	}		
 }