Merge branch 'rs/more-buffered-io'

Use more buffered I/O where we used to call many small write(2)s.

* rs/more-buffered-io:
  upload-pack: use buffered I/O to talk to rev-list
  midx: use buffered I/O to talk to pack-objects
  connected: use buffered I/O to talk to rev-list
This commit is contained in:
Junio C Hamano 2020-08-24 14:54:31 -07:00
commit d8488b9e86
3 changed files with 26 additions and 25 deletions

View File

@ -22,14 +22,13 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
struct check_connected_options *opt) struct check_connected_options *opt)
{ {
struct child_process rev_list = CHILD_PROCESS_INIT; struct child_process rev_list = CHILD_PROCESS_INIT;
FILE *rev_list_in;
struct check_connected_options defaults = CHECK_CONNECTED_INIT; struct check_connected_options defaults = CHECK_CONNECTED_INIT;
char commit[GIT_MAX_HEXSZ + 1];
struct object_id oid; struct object_id oid;
int err = 0; int err = 0;
struct packed_git *new_pack = NULL; struct packed_git *new_pack = NULL;
struct transport *transport; struct transport *transport;
size_t base_len; size_t base_len;
const unsigned hexsz = the_hash_algo->hexsz;
if (!opt) if (!opt)
opt = &defaults; opt = &defaults;
@ -122,7 +121,8 @@ no_promisor_pack_found:
sigchain_push(SIGPIPE, SIG_IGN); sigchain_push(SIGPIPE, SIG_IGN);
commit[hexsz] = '\n'; rev_list_in = xfdopen(rev_list.in, "w");
do { do {
/* /*
* If index-pack already checked that: * If index-pack already checked that:
@ -135,16 +135,17 @@ no_promisor_pack_found:
if (new_pack && find_pack_entry_one(oid.hash, new_pack)) if (new_pack && find_pack_entry_one(oid.hash, new_pack))
continue; continue;
memcpy(commit, oid_to_hex(&oid), hexsz); if (fprintf(rev_list_in, "%s\n", oid_to_hex(&oid)) < 0)
if (write_in_full(rev_list.in, commit, hexsz + 1) < 0) {
if (errno != EPIPE && errno != EINVAL)
error_errno(_("failed write to rev-list"));
err = -1;
break; break;
}
} while (!fn(cb_data, &oid)); } while (!fn(cb_data, &oid));
if (close(rev_list.in)) if (ferror(rev_list_in) || fflush(rev_list_in)) {
if (errno != EPIPE && errno != EINVAL)
error_errno(_("failed write to rev-list"));
err = -1;
}
if (fclose(rev_list_in))
err = error_errno(_("failed to close rev-list's stdin")); err = error_errno(_("failed to close rev-list's stdin"));
sigchain_pop(SIGPIPE); sigchain_pop(SIGPIPE);

8
midx.c
View File

@ -1402,6 +1402,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
uint32_t i; uint32_t i;
unsigned char *include_pack; unsigned char *include_pack;
struct child_process cmd = CHILD_PROCESS_INIT; struct child_process cmd = CHILD_PROCESS_INIT;
FILE *cmd_in;
struct strbuf base_name = STRBUF_INIT; struct strbuf base_name = STRBUF_INIT;
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1); struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
@ -1454,6 +1455,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
goto cleanup; goto cleanup;
} }
cmd_in = xfdopen(cmd.in, "w");
for (i = 0; i < m->num_objects; i++) { for (i = 0; i < m->num_objects; i++) {
struct object_id oid; struct object_id oid;
uint32_t pack_int_id = nth_midxed_pack_int_id(m, i); uint32_t pack_int_id = nth_midxed_pack_int_id(m, i);
@ -1462,10 +1465,9 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
continue; continue;
nth_midxed_object_oid(&oid, m, i); nth_midxed_object_oid(&oid, m, i);
xwrite(cmd.in, oid_to_hex(&oid), the_hash_algo->hexsz); fprintf(cmd_in, "%s\n", oid_to_hex(&oid));
xwrite(cmd.in, "\n", 1);
} }
close(cmd.in); fclose(cmd_in);
if (finish_command(&cmd)) { if (finish_command(&cmd)) {
error(_("could not finish pack-objects")); error(_("could not finish pack-objects"));

View File

@ -603,9 +603,8 @@ static int do_reachable_revlist(struct child_process *cmd,
"rev-list", "--stdin", NULL, "rev-list", "--stdin", NULL,
}; };
struct object *o; struct object *o;
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ FILE *cmd_in = NULL;
int i; int i;
const unsigned hexsz = the_hash_algo->hexsz;
cmd->argv = argv; cmd->argv = argv;
cmd->git_cmd = 1; cmd->git_cmd = 1;
@ -623,8 +622,8 @@ static int do_reachable_revlist(struct child_process *cmd,
if (start_command(cmd)) if (start_command(cmd))
goto error; goto error;
namebuf[0] = '^'; cmd_in = xfdopen(cmd->in, "w");
namebuf[hexsz + 1] = '\n';
for (i = get_max_object_index(); 0 < i; ) { for (i = get_max_object_index(); 0 < i; ) {
o = get_indexed_object(--i); o = get_indexed_object(--i);
if (!o) if (!o)
@ -633,11 +632,9 @@ static int do_reachable_revlist(struct child_process *cmd,
o->flags &= ~TMP_MARK; o->flags &= ~TMP_MARK;
if (!is_our_ref(o, allow_uor)) if (!is_our_ref(o, allow_uor))
continue; continue;
memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz); if (fprintf(cmd_in, "^%s\n", oid_to_hex(&o->oid)) < 0)
if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
goto error; goto error;
} }
namebuf[hexsz] = '\n';
for (i = 0; i < src->nr; i++) { for (i = 0; i < src->nr; i++) {
o = src->objects[i].item; o = src->objects[i].item;
if (is_our_ref(o, allow_uor)) { if (is_our_ref(o, allow_uor)) {
@ -647,11 +644,12 @@ static int do_reachable_revlist(struct child_process *cmd,
} }
if (reachable && o->type == OBJ_COMMIT) if (reachable && o->type == OBJ_COMMIT)
o->flags |= TMP_MARK; o->flags |= TMP_MARK;
memcpy(namebuf, oid_to_hex(&o->oid), hexsz); if (fprintf(cmd_in, "%s\n", oid_to_hex(&o->oid)) < 0)
if (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)
goto error; goto error;
} }
close(cmd->in); if (ferror(cmd_in) || fflush(cmd_in))
goto error;
fclose(cmd_in);
cmd->in = -1; cmd->in = -1;
sigchain_pop(SIGPIPE); sigchain_pop(SIGPIPE);
@ -660,8 +658,8 @@ static int do_reachable_revlist(struct child_process *cmd,
error: error:
sigchain_pop(SIGPIPE); sigchain_pop(SIGPIPE);
if (cmd->in >= 0) if (cmd_in)
close(cmd->in); fclose(cmd_in);
if (cmd->out >= 0) if (cmd->out >= 0)
close(cmd->out); close(cmd->out);
return -1; return -1;