Re: [PATCH 1/2] packfile: close and free packs upon releasing an object store
- From
Jeff King <peff@peff.net>
- Date
- May 10, 2018, 05:12 UTC
- Message-ID
- <20180510051201.GB27259@sigill.intra.peff.net>
- In-Reply-To
- <20180510001211.163692-1-sbeller@google.com>
On Wed, May 09, 2018 at 05:12:10PM -0700, Stefan Beller wrote:
> In d0b59866223 (object-store: close all packs upon clearing the object > store, 2018-03-23), we made sure to close all packfiles on releasing > an object store, but we also have to free the memory of the closed packs.
I know we've assumed in a few places that a "struct packed_git" will never go away. The one that comes to mind is the mru list.
It looks like we'll be OK here:
Show 12 quoted lines
> diff --git a/object.c b/object.c > index 66cffaf6e51..3e64a4a26dd 100644 > --- a/object.c > +++ b/object.c > @@ -485,6 +485,6 @@ void raw_object_store_clear(struct raw_object_store *o) > o->alt_odb_tail = NULL; > > INIT_LIST_HEAD(&o->packed_git_mru); > - close_all_packs(o); > + close_and_free_packs(o); > o->packed_git = NULL; > }
because we clear the list above. But it would be dangerous for anybody else to call close_and_free_packs(). Should that INIT_LIST_HEAD get moved down into that function?
Probably the same applies to setting NULL here; you're left with a dangling pointer if you just call close_and_free_packs(). Should that helper maybe just be a static function in object.c?
Just brainstorming other places where the immutability of "struct packed_git" might be important:
- pack-objects keeps a pointer from each object_entry to its
containing packed_git. That's probably OK, as you wouldn't expect to
be able to close the object store in the middle of that operation. - the reachability bitmap code holds a pointer to the pack that has a
bitmap. Probably that whole "struct bitmap_index" needs to be part
of the object_store (arguably it should all just be _inside_ the
packed_git, but the current implementation avoids complexity by just
having a single bitmap-per-repo).-Peff