shithub: git9

Download patch

ref: 718290ffe0bbf965abf0c4e4941fae78e1d1e23f
parent: c9a4dbe9fea3b6328a27628f89d2fc4ca4d1970a
author: Ori Bernstein <[email protected]>
date: Sun Nov 15 23:45:47 EST 2020

packfiles: make cache size tunable.

For serving, the cache is mostly useless, since we
do a walk of all objects, ideally once; we also tend
to hog a bunch of ram and possibly fall over if there
are a bunch of concurrent clones.

To make serving better, allow tuning the cache size
via an environment variable.

--- a/git.h
+++ b/git.h
@@ -20,8 +20,6 @@
 typedef struct Dblock	Dblock;
 
 enum {
-	/* 5k objects should be enough */
-	Cachemax	= 5*1024,
 	Pathmax		= 512,
 	Hashsz		= 20,
 	Pktmax		= 65536,
@@ -227,6 +225,7 @@
 extern Objset	objcache;
 extern Hash	Zhash;
 extern int	chattygit;
+extern int	cachemax;
 
 #pragma varargck type "H" Hash
 #pragma varargck type "T" int
--- a/pack.c
+++ b/pack.c
@@ -49,6 +49,7 @@
 Object *lruhead;
 Object *lrutail;
 int	ncache;
+int	cachemax = 1024;
 
 static void
 clear(Object *o)
@@ -137,7 +138,7 @@
 		ref(o);
 		ncache++;
 	}
-	while(ncache > Cachemax){
+	while(ncache > cachemax){
 		p = lrutail;
 		lrutail = p->prev;
 		lrutail->next = nil;