index-pack: split second pass obj handling into own function
Subsystems (2)
PATCH 1/2 index-pack: split second pass obj handling into own function
--- builtin/index-pack.c | 31 ++++++++++++++++++------------- 1 files changed, 18 insertions(+), 13 deletions(-)
builtin/index-pack.c +18 -13
@@ -682,6 +682,23 @@ static int compare_delta_entry(const void *a, const void *b) objects[delta_b->obj_no].type); } +/* +* Second pass: +* - for all non-delta objects, look if it is used as a base for +* deltas; +* - if used as a base, uncompress the object and apply all deltas, +* recursively checking if the resulting object is used as a base +* for some more deltas. +*/ +static void second_pass (struct object_entry *obj) +{ +struct base_data *base_obj =alloc_base_data (); + base_obj->obj = obj; + base_obj->data =NULL ; +find_unresolved_deltas (base_obj); +display_progress (progress, nr_resolved_deltas); +} +/* Parse all objects and return the pack content SHA1 hash */ static void parse_pack_objects (unsigned char *sha1) {
@@ -736,26 +753,14 @@ static void parse_pack_objects(unsigned char *sha1)qsort (deltas, nr_deltas,sizeof (struct delta_entry ), compare_delta_entry); -/* -* Second pass: -* - for all non-delta objects, look if it is used as a base for -* deltas; -* - if used as a base, uncompress the object and apply all deltas, -* recursively checking if the resulting object is used as a base -* for some more deltas. -*/ if (verbose) progress =start_progress ("Resolving deltas" , nr_deltas);for (i =0 ; i < nr_objects; i++) {struct object_entry *obj = &objects[i]; -struct base_data *base_obj =alloc_base_data ();if (is_delta_type (obj->type))continue ; - base_obj->obj = obj; - base_obj->data =NULL ; -find_unresolved_deltas (base_obj); -display_progress (progress, nr_resolved_deltas); +second_pass (obj); } }
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH 2/2 index-pack: support multithreaded delta resolving
This puts delta resolving on each base on a separate thread, one base cache per thread.
An experiment on a 24 core machine with git.git shows that performance does not increase proportional to the number of cores. So by default, we use maximum 3 cores.
$ /usr/bin/time ~/t/git index-pack --threads=1 -v --stdin < XXX.pack Receiving objects: 100% (146564/146564), 53.99 MiB | 17.47 MiB/s, done. Resolving deltas: 100% (109205/109205), done. pack d5471e8365717a5812cbc81ec7277cb697a80f08 11.58user 0.37system 0:12.04elapsed 99%CPU (0avgtext+0avgdata 375088maxresident)k 0inputs+118592outputs (0major+56894minor)pagefaults 0swaps
$ ... --threads=2 ... 14.58user 0.47system 0:09.99elapsed 150%CPU (0avgtext+0avgdata 411536maxresident)k 0inputs+118592outputs (0major+79961minor)pagefaults 0swaps
$ ... --threads=3 ... 14.36user 0.64system 0:08.12elapsed 184%CPU (0avgtext+0avgdata 393312maxresident)k 0inputs+118592outputs (0major+50998minor)pagefaults 0swaps
$ ... --threads=4 ... 15.81user 0.71system 0:08.17elapsed 202%CPU (0avgtext+0avgdata 419152maxresident)k 0inputs+118592outputs (0major+54907minor)pagefaults 0swaps
$ ... --threads=5 ... 14.76user 0.72system 0:07.06elapsed 219%CPU (0avgtext+0avgdata 414112maxresident)k 0inputs+118592outputs (0major+59547minor)pagefaults 0swaps
$ ... --threads=8 ... 15.98user 0.81system 0:07.71elapsed 217%CPU (0avgtext+0avgdata 429904maxresident)k 0inputs+118592outputs (0major+66221minor)pagefaults 0swaps
$ ... --threads=12 ... 15.81user 0.74system 0:09.60elapsed 172%CPU (0avgtext+0avgdata 442336maxresident)k 0inputs+118592outputs (0major+61353minor)pagefaults 0swaps
$ ... --threads=16 ... 15.41user 0.57system 0:11.62elapsed 137%CPU (0avgtext+0avgdata 451728maxresident)k 0inputs+118592outputs (0major+63569minor)pagefaults 0swaps
$ ... --threads=24 ... 15.84user 0.63system 0:12.83elapsed 128%CPU (0avgtext+0avgdata 475728maxresident)k 0inputs+118592outputs (0major+58013minor)pagefaults 0swaps
---
On linux-2.6.git, 2 cores, real time from 3m18 went down to around 2m.
Documentation/git-index-pack.txt | 10 ++ Makefile | 2 +- builtin/index-pack.c | 188 ++++++++++++++++++++++++++++++++++---- 3 files changed, 180 insertions(+), 20 deletions(-)
Documentation/git-index-pack.txt +10 -0
@@ -74,6 +74,16 @@ OPTIONS --strict:: Die, if the pack contains broken objects or links. +--threads=<n>:: + Specifies the number of threads to spawn when resolving + deltas. This requires that index-pack be compiled with + pthreads otherwise this option is ignored with a warning. + This is meant to reduce packing time on multiprocessor + machines. The required amount of memory for the delta search + window is however multiplied by the number of threads. + Specifying 0 will cause git to auto-detect the number of CPU's + and use maximum 3 threads. + Note ----
Makefile +1 -1
@@ -2159,7 +2159,7 @@ builtin/branch.o builtin/checkout.o builtin/clone.o builtin/reset.o branch.o tra builtin/bundle.o bundle.o transport.o: bundle.h builtin/bisect--helper.o builtin/rev-list.o bisect.o: bisect.h builtin/clone.o builtin/fetch-pack.o transport.o: fetch-pack.h -builtin/grep.o builtin/pack-objects.o transport-helper.o thread-utils.o: thread-utils.h +builtin/index-pack.o builtin/grep.o builtin/pack-objects.o transport-helper.o thread-utils.o: thread-utils.h builtin/send-pack.o transport.o: send-pack.h builtin/log.o builtin/shortlog.o: shortlog.h builtin/prune.o builtin/reflog.o reachable.o: reachable.h
builtin/index-pack.c +169 -19
325 lines not on this page · raw message
Signature · 1 line
1.7.3.1.256.g2539c.dirty
Re: [PATCH 2/2] index-pack: support multithreaded delta resolving
When applied to 25a7850 and then merged to 'pu', the result fails to correctly produce pack .idx file.
I spent an hour or so this afternoon, scratching my head, staring at the output from tests added to t5510 by today's tr/maint-bundle-boundary topic to see where it breaks. Its last test creates a bundle that has three objects, extracts a pack from it, and runs "index-pack --fix-thin" on it.
This topic makes it fail with "fatal: pack has 1 unresolved deltas".
PATCH v2 2/2 index-pack: support multithreaded delta resolving
This puts delta resolving on each base on a separate thread, one base cache per thread.
An experiment on a 24 core machine with git.git shows that performance does not increase proportional to the number of cores. So by default, we use maximum 3 cores.
$ /usr/bin/time ~/t/git index-pack --threads=1 -v --stdin < XXX.pack Receiving objects: 100% (146564/146564), 53.99 MiB | 17.47 MiB/s, done. Resolving deltas: 100% (109205/109205), done. pack d5471e8365717a5812cbc81ec7277cb697a80f08 11.58user 0.37system 0:12.04elapsed 99%CPU (0avgtext+0avgdata 375088maxresident)k 0inputs+118592outputs (0major+56894minor)pagefaults 0swaps
$ ... --threads=2 ... 14.58user 0.47system 0:09.99elapsed 150%CPU (0avgtext+0avgdata 411536maxresident)k 0inputs+118592outputs (0major+79961minor)pagefaults 0swaps
$ ... --threads=3 ... 14.36user 0.64system 0:08.12elapsed 184%CPU (0avgtext+0avgdata 393312maxresident)k 0inputs+118592outputs (0major+50998minor)pagefaults 0swaps
$ ... --threads=4 ... 15.81user 0.71system 0:08.17elapsed 202%CPU (0avgtext+0avgdata 419152maxresident)k 0inputs+118592outputs (0major+54907minor)pagefaults 0swaps
$ ... --threads=5 ... 14.76user 0.72system 0:07.06elapsed 219%CPU (0avgtext+0avgdata 414112maxresident)k 0inputs+118592outputs (0major+59547minor)pagefaults 0swaps
$ ... --threads=8 ... 15.98user 0.81system 0:07.71elapsed 217%CPU (0avgtext+0avgdata 429904maxresident)k 0inputs+118592outputs (0major+66221minor)pagefaults 0swaps
$ ... --threads=12 ... 15.81user 0.74system 0:09.60elapsed 172%CPU (0avgtext+0avgdata 442336maxresident)k 0inputs+118592outputs (0major+61353minor)pagefaults 0swaps
$ ... --threads=16 ... 15.41user 0.57system 0:11.62elapsed 137%CPU (0avgtext+0avgdata 451728maxresident)k 0inputs+118592outputs (0major+63569minor)pagefaults 0swaps
$ ... --threads=24 ... 15.84user 0.63system 0:12.83elapsed 128%CPU (0avgtext+0avgdata 475728maxresident)k 0inputs+118592outputs (0major+58013minor)pagefaults 0swaps
---
2012/3/2 Junio C Hamano <[email protected]>:
Quoted 9 lines
When applied to 25a7850 and then merged to 'pu', the result fails to correctly produce pack .idx file.
I spent an hour or so this afternoon, scratching my head, staring at the output from tests added to t5510 by today's tr/maint-bundle-boundary topic to see where it breaks. Its last test creates a bundle that has three objects, extracts a pack from it, and runs "index-pack --fix-thin" on it.
This topic makes it fail with "fatal: pack has 1 unresolved deltas".
And it thought it was good enough to CC you. Apparently parallel programming is hard. I make two mistakes:
1. I make each thread save resolved delta counter in thread_data[].nr_resolved_deltas, then accumulate all of them to global nr_resolved_deltas later. This plan does not work with fix_unresolved_deltas() because it runs in single thread mode. It stores the counter in thread_data[0], but the counter is never added back to global nr_resolved_deltas. This makes t5510 fail.
2. The reason I put nr_resolved_deltas to thread-local struct is to avoid locking. But I'm wrong. I still have two places where thread_data[].nr_resolved_deltas can be changed: increment in resolve_delta() and and reset in threaded_second_pass().
So locking is required for changing nr_resolved_deltas anyway, I have removed thread_data[].nr_resolved_deltas and do the locking on global nr_resolved_deltas properly. "pu" seems to be happy with the updated series.
One other thing. I did not consider to run fix_unresolved_deltas() in parallel originally because I didn't think it could be done. It can. But I'm not sure it's worth the effort. Anyway we can do that later if it turns out worth it.
Documentation/git-index-pack.txt | 10 ++ Makefile | 2 +- builtin/index-pack.c | 214 ++++++++++++++++++++++++++++++++++---- 3 files changed, 206 insertions(+), 20 deletions(-)
Documentation/git-index-pack.txt +10 -0
@@ -74,6 +74,16 @@ OPTIONS --strict:: Die, if the pack contains broken objects or links. +--threads=<n>:: + Specifies the number of threads to spawn when resolving + deltas. This requires that index-pack be compiled with + pthreads otherwise this option is ignored with a warning. + This is meant to reduce packing time on multiprocessor + machines. The required amount of memory for the delta search + window is however multiplied by the number of threads. + Specifying 0 will cause git to auto-detect the number of CPU's + and use maximum 3 threads. + Note ----
Makefile +1 -1
@@ -2159,7 +2159,7 @@ builtin/branch.o builtin/checkout.o builtin/clone.o builtin/reset.o branch.o tra builtin/bundle.o bundle.o transport.o: bundle.h builtin/bisect--helper.o builtin/rev-list.o bisect.o: bisect.h builtin/clone.o builtin/fetch-pack.o transport.o: fetch-pack.h -builtin/grep.o builtin/pack-objects.o transport-helper.o thread-utils.o: thread-utils.h +builtin/index-pack.o builtin/grep.o builtin/pack-objects.o transport-helper.o thread-utils.o: thread-utils.h builtin/send-pack.o transport.o: send-pack.h builtin/log.o builtin/shortlog.o: shortlog.h builtin/prune.o builtin/reflog.o reachable.o: reachable.h
builtin/index-pack.c +195 -19
351 lines not on this page · raw message
Signature · 1 line
1.7.8.36.g69ee2
Re: [PATCH v2 2/2] index-pack: support multithreaded delta resolving
Quoted 4 lines · Nguyễn Thái Ngọc Duy
One other thing. I did not consider to run
fix_unresolved_deltas()in parallel originally because I didn't think it could be done. It can. But I'm not sure it's worth the effort. Anyway we can do that later if it turns out worth it.
My hunch agrees with your "not sure it's worth", as these are objects at the boundary of --thin transfer, which should only be proportional to the size of a single snapshot, not the depth of history, and I think your "we can do that later" is a sound judgement.
Thanks.