ref: 6f5cc0d182a57053f04554da393812996b943d85
parent: fe32f6287bca3c70fae7f7469ad9aeb9de9a4e2a
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--;
}
}
--
⑨