9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] git: cache size in bytes
Date: Wed, 29 Dec 2021 21:06:41 -0500	[thread overview]
Message-ID: <658A70853A1A4B988B32AA388BCFF55C@eigenstate.org> (raw)

I was looking at syzkaller recently,
and cloning it made git9 unhappy. This
is because our cache size is in object
counts, rather than bytes -- so lots
of large objects can blow away our size.

This change makes git9 track cache sizes
in bytes, which prevents a lot of large
objects from blowing away our memory.

It defaults to 512 MiB, but I'm happy to
tweak that.

diff facb0e757ac63f763bd942a2714f979538b99eb0 uncommitted
--- 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,9 @@
 	Npackcache	= 32,
 	Hashsz		= 20,
 	Pktmax		= 65536,
+	KiB		= 1024,
+	MiB		= 1024*KiB,
+	GiB		= 1024*MiB,
 };
 
 enum {
--- a/sys/src/cmd/git/pack.c
+++ b/sys/src/cmd/git/pack.c
@@ -66,7 +66,7 @@
 Object *lruhead;
 Object *lrutail;
 int	ncache;
-int	cachemax = 4096;
+int	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--;
 	}		
 }
 


                 reply	other threads:[~2021-12-30 10:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=658A70853A1A4B988B32AA388BCFF55C@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    --subject='Re: [9front] git: cache size in bytes' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).