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.
This commit is contained in:
parent
99d54e420e
commit
f63d1d3ced
2 changed files with 8 additions and 5 deletions
|
@ -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 @@ enum {
|
|||
Npackcache = 32,
|
||||
Hashsz = 20,
|
||||
Pktmax = 65536,
|
||||
KiB = 1024,
|
||||
MiB = 1024*KiB,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -241,9 +244,9 @@ struct Delta {
|
|||
|
||||
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
|
||||
|
|
|
@ -65,8 +65,8 @@ static Object *readidxobject(Biobuf *, Hash, int);
|
|||
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 @@ cache(Object *o)
|
|||
if(!(o->flag & Ccache)){
|
||||
o->flag |= Ccache;
|
||||
ref(o);
|
||||
ncache++;
|
||||
ncache += o->size;
|
||||
}
|
||||
while(ncache > cachemax && lrutail != nil){
|
||||
p = lrutail;
|
||||
|
@ -168,8 +168,8 @@ cache(Object *o)
|
|||
p->flag &= ~Ccache;
|
||||
p->prev = nil;
|
||||
p->next = nil;
|
||||
ncache -= p->size;
|
||||
unref(p);
|
||||
ncache--;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue