From: ori@eigenstate.org To: 9front@9front.org Subject: [9front] git: improvements for packfile caching Date: Thu, 25 Nov 2021 19:17:12 -0500 [thread overview] Message-ID: <CCA70C5E32D86D284233DF3314B3322B@eigenstate.org> (raw) currently the packfile caching in git9 is wrong: it should keep the pack open in closepack(), and should use a more comprehensive check when scanning for the best pack to close. diff add3a0a4da2f46f69a87782699e77c794a8b2cb9 uncommitted --- a/sys/src/cmd/git/pack.c +++ b/sys/src/cmd/git/pack.c @@ -253,28 +253,44 @@ vlong t; int i, best; - if(pf->pack == nil){ - if((pf->pack = Bopen(pf->path, OREAD)) == nil) - return nil; - openpacks++; + if(pf->pack != nil){ + pf->refs++; + return pf->pack; } - if(openpacks == Npackcache){ - t = pf->opentm; + /* + * If we've got more packs open + * than we want cached, try to + * free up the oldest ones. + * + * If we can't find a slot, this + * isn't fatal; we can just use + * another fd. + */ + while(openpacks >= Npackcache){ + t = (1ull<<62)-1; best = -1; for(i = 0; i < npackf; i++){ - if(packf[i].opentm < t && packf[i].refs > 0){ + if(&packf[i] != pf + && packf[i].pack != nil + && packf[i].opentm < t + && packf[i].refs == 0){ t = packf[i].opentm; best = i; } } - if(best != -1){ - Bterm(packf[best].pack); - packf[best].pack = nil; - openpacks--; + if(best == -1){ + fprint(2, "no available pack slots\n"); + break; } + Bterm(packf[best].pack); + packf[best].pack = nil; + openpacks--; } + openpacks++; pf->opentm = nsec(); pf->refs++; + if((pf->pack = Bopen(pf->path, OREAD)) == nil) + return nil; return pf->pack; } @@ -281,10 +297,7 @@ static void closepack(Packf *pf) { - if(--pf->refs == 0 && pf->pack != nil){ - Bterm(pf->pack); - pf->pack = nil; - } + pf->refs--; } static u32int
reply other threads:[~2021-11-26 5:52 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=CCA70C5E32D86D284233DF3314B3322B@eigenstate.org \ --to=ori@eigenstate.org \ --cc=9front@9front.org \ --subject='Re: [9front] git: improvements for packfile caching' \ /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).