From f63d1d3ced81702e0eadf56228a54a467278b0d4 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sun, 2 Jan 2022 03:37:23 +0000 Subject: [PATCH] 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. --- sys/src/cmd/git/git.h | 5 ++++- sys/src/cmd/git/pack.c | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/src/cmd/git/git.h b/sys/src/cmd/git/git.h index 839fcfe60..74617939d 100644 --- a/sys/src/cmd/git/git.h +++ b/sys/src/cmd/git/git.h @@ -4,6 +4,7 @@ #include #include +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 diff --git a/sys/src/cmd/git/pack.c b/sys/src/cmd/git/pack.c index ade8591fa..d5625f48a 100644 --- a/sys/src/cmd/git/pack.c +++ b/sys/src/cmd/git/pack.c @@ -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--; } }