@matheusbsbs / matheus-bagliano / commits / 367f4a4343
Fork 0

threaded delta search: specify number of threads at run time

This adds a --threads=<n> parameter to 'git pack-objects' with documentation. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Sep 10, 2007 at 00:06 UTC 367f4a4343d467ac76641362b102bc86da5cb584
2 files changed +29 -5
Documentation/git-pack-objects.txt
+8
@@ -173,6 +173,14 @@ base-name::
173 length, this option typically shrinks the resulting
174 packfile by 3-5 per-cent.
175
176 +--threads=<n>::
177 + Specifies the number of threads to spawn when searching for best
178 + delta matches. This requires that pack-objects be compiled with
179 + pthreads otherwise this option is ignored with a warning.
180 + This is meant to reduce packing time on multiprocessor machines.
181 + The required amount of memory for the delta search window is
182 + however multiplied by the number of threads.
183 +
184 --index-version=<version>[,<offset>]::
185 This is intended to be used by the test suite only. It allows
186 to force the version for the generated pack index, and to force
builtin-pack-objects.c
+21 -5
@@ -24,7 +24,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \n\
24 [--max-pack-size=N] [--local] [--incremental] \n\
25 [--window=N] [--window-memory=N] [--depth=N] \n\
26 [--no-reuse-delta] [--no-reuse-object] [--delta-base-offset] \n\
27 - [--non-empty] [--revs [--unpacked | --all]*] [--reflog] \n\
27 + [--threads=N] [--non-empty] [--revs [--unpacked | --all]*] [--reflog] \n\
28 [--stdout | base-name] [<ref-list | <object-list]";
29
30 struct object_entry {
@@ -72,6 +72,7 @@ static int progress = 1;
72 static int window = 10;
73 static uint32_t pack_size_limit;
74 static int depth = 50;
75 +static int delta_search_threads = 1;
76 static int pack_to_stdout;
77 static int num_preferred_base;
78 static struct progress progress_state;
@@ -1605,19 +1606,22 @@ static void *threaded_find_deltas(void *arg)
1606 }
1607 }
1608
1608 -#define NR_THREADS 4
1609 -
1609 static void ll_find_deltas(struct object_entry **list, unsigned list_size,
1610 int window, int depth, unsigned *processed)
1611 {
1613 - struct thread_params p[NR_THREADS];
1612 + struct thread_params p[delta_search_threads];
1613 int i, ret;
1614 unsigned chunk_size;
1615
1616 + if (delta_search_threads <= 1) {
1617 + find_deltas(list, list_size, window, depth, processed);
1618 + return;
1619 + }
1620 +
1621 pthread_mutex_lock(&data_provider);
1622 pthread_mutex_lock(&data_ready);
1623
1620 - for (i = 0; i < NR_THREADS; i++) {
1624 + for (i = 0; i < delta_search_threads; i++) {
1625 p[i].window = window;
1626 p[i].depth = depth;
1627 p[i].processed = processed;
@@ -1900,6 +1904,18 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1904 usage(pack_usage);
1905 continue;
1906 }
1907 + if (!prefixcmp(arg, "--threads=")) {
1908 + char *end;
1909 + delta_search_threads = strtoul(arg+10, &end, 0);
1910 + if (!arg[10] || *end || delta_search_threads < 1)
1911 + usage(pack_usage);
1912 +#ifndef THREADED_DELTA_SEARCH
1913 + if (delta_search_threads > 1)
1914 + warning("no threads support, "
1915 + "ignoring %s", arg);
1916 +#endif
1917 + continue;
1918 + }
1919 if (!prefixcmp(arg, "--depth=")) {
1920 char *end;
1921 depth = strtoul(arg+8, &end, 0);