Skip to content

Commit af96fe3

Browse files
derrickstoleegitster
authored andcommitted
midx: add packs to packed_git linked list
The multi-pack-index allows searching for objects across multiple packs using one object list. The original design gains many of these performance benefits by keeping the packs in the multi-pack-index out of the packed_git list. Unfortunately, this has one major drawback. If the multi-pack-index covers thousands of packs, and a command loads many of those packs, then we can hit the limit for open file descriptors. The close_one_pack() method is used to limit this resource, but it only looks at the packed_git list, and uses an LRU cache to prevent thrashing. Instead of complicating this close_one_pack() logic to include direct references to the multi-pack-index, simply add the packs opened by the multi-pack-index to the packed_git list. This immediately solves the file-descriptor limit problem, but requires some extra steps to avoid performance issues or other problems: 1. Create a multi_pack_index bit in the packed_git struct that is one if and only if the pack was loaded from a multi-pack-index. 2. Skip packs with the multi_pack_index bit when doing object lookups and abbreviations. These algorithms already check the multi-pack-index before the packed_git struct. This has a very small performance hit, as we need to walk more packed_git structs. This is acceptable, since these operations run binary search on the other packs, so this walk-and-ignore logic is very fast by comparison. 3. When closing a multi-pack-index file, do not close its packs, as those packs will be closed using close_all_packs(). In some cases, such as 'git repack', we run 'close_midx()' without also closing the packs, so we need to un-set the multi_pack_index bit in those packs. This is necessary, and caught by running t6501-freshen-objects.sh with GIT_TEST_MULTI_PACK_INDEX=1. To manually test this change, I inserted trace2 logging into close_pack_fd() and set pack_max_fds to 10, then ran 'git rev-list --all --objects' on a copy of the Git repo with 300+ pack-files and a multi-pack-index. The logs verified the packs are closed as we read them beyond the file descriptor limit. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 64404a2 commit af96fe3

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

midx.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ void close_midx(struct multi_pack_index *m)
192192
m->fd = -1;
193193

194194
for (i = 0; i < m->num_packs; i++) {
195-
if (m->packs[i]) {
196-
close_pack(m->packs[i]);
197-
free(m->packs[i]);
198-
}
195+
if (m->packs[i])
196+
m->packs[i]->multi_pack_index = 0;
199197
}
200198
FREE_AND_NULL(m->packs);
201199
FREE_AND_NULL(m->pack_names);
@@ -204,6 +202,7 @@ void close_midx(struct multi_pack_index *m)
204202
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id)
205203
{
206204
struct strbuf pack_name = STRBUF_INIT;
205+
struct packed_git *p;
207206

208207
if (pack_int_id >= m->num_packs)
209208
die(_("bad pack-int-id: %u (%u total packs)"),
@@ -215,9 +214,18 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t
215214
strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
216215
m->pack_names[pack_int_id]);
217216

218-
m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, m->local);
217+
p = add_packed_git(pack_name.buf, pack_name.len, m->local);
219218
strbuf_release(&pack_name);
220-
return !m->packs[pack_int_id];
219+
220+
if (!p)
221+
return 1;
222+
223+
p->multi_pack_index = 1;
224+
m->packs[pack_int_id] = p;
225+
install_packed_git(r, p);
226+
list_add_tail(&p->mru, &r->objects->packed_git_mru);
227+
228+
return 0;
221229
}
222230

223231
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result)

object-store.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct packed_git {
7676
pack_keep_in_core:1,
7777
freshened:1,
7878
do_not_close:1,
79-
pack_promisor:1;
79+
pack_promisor:1,
80+
multi_pack_index:1;
8081
unsigned char hash[GIT_MAX_RAWSZ];
8182
struct revindex_entry *revindex;
8283
/* something like ".git/objects/pack/xxxxx.pack" */
@@ -128,12 +129,6 @@ struct raw_object_store {
128129
/* A most-recently-used ordered version of the packed_git list. */
129130
struct list_head packed_git_mru;
130131

131-
/*
132-
* A linked list containing all packfiles, starting with those
133-
* contained in the multi_pack_index.
134-
*/
135-
struct packed_git *all_packs;
136-
137132
/*
138133
* A fast, rough count of the number of objects in the repository.
139134
* These two fields are not meant for direct access. Use

packfile.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,6 @@ static void prepare_packed_git(struct repository *r)
994994
}
995995
rearrange_packed_git(r);
996996

997-
r->objects->all_packs = NULL;
998-
999997
prepare_packed_git_mru(r);
1000998
r->objects->packed_git_initialized = 1;
1001999
}
@@ -1026,26 +1024,16 @@ struct multi_pack_index *get_multi_pack_index(struct repository *r)
10261024

10271025
struct packed_git *get_all_packs(struct repository *r)
10281026
{
1029-
prepare_packed_git(r);
1030-
1031-
if (!r->objects->all_packs) {
1032-
struct packed_git *p = r->objects->packed_git;
1033-
struct multi_pack_index *m;
1034-
1035-
for (m = r->objects->multi_pack_index; m; m = m->next) {
1036-
uint32_t i;
1037-
for (i = 0; i < m->num_packs; i++) {
1038-
if (!prepare_midx_pack(r, m, i)) {
1039-
m->packs[i]->next = p;
1040-
p = m->packs[i];
1041-
}
1042-
}
1043-
}
1027+
struct multi_pack_index *m;
10441028

1045-
r->objects->all_packs = p;
1029+
prepare_packed_git(r);
1030+
for (m = r->objects->multi_pack_index; m; m = m->next) {
1031+
uint32_t i;
1032+
for (i = 0; i < m->num_packs; i++)
1033+
prepare_midx_pack(r, m, i);
10461034
}
10471035

1048-
return r->objects->all_packs;
1036+
return r->objects->packed_git;
10491037
}
10501038

10511039
struct list_head *get_packed_git_mru(struct repository *r)
@@ -2004,7 +1992,7 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
20041992

20051993
list_for_each(pos, &r->objects->packed_git_mru) {
20061994
struct packed_git *p = list_entry(pos, struct packed_git, mru);
2007-
if (fill_pack_entry(oid, e, p)) {
1995+
if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
20081996
list_move(&p->mru, &r->objects->packed_git_mru);
20091997
return 1;
20101998
}

sha1-name.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ static void unique_in_pack(struct packed_git *p,
157157
uint32_t num, i, first = 0;
158158
const struct object_id *current = NULL;
159159

160+
if (p->multi_pack_index)
161+
return;
162+
160163
if (open_pack_index(p) || !p->num_objects)
161164
return;
162165

@@ -589,6 +592,9 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
589592
struct object_id oid;
590593
const struct object_id *mad_oid;
591594

595+
if (p->multi_pack_index)
596+
return;
597+
592598
if (open_pack_index(p) || !p->num_objects)
593599
return;
594600

0 commit comments

Comments
 (0)