From: Thomas Rast <trast@student.ethz.ch>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>,
Jeff King <peff@peff.net>, Stefan Zager <szager@google.com>
Subject: [PATCH v2] index-pack: guard nr_resolved_deltas reads by lock
Date: Tue, 19 Mar 2013 15:16:41 +0100 [thread overview]
Message-ID: <8ddf4db38f33034b5ebf504a18948bccf841ab72.1363702423.git.trast@student.ethz.ch> (raw)
In-Reply-To: <CACsJy8C0AYvAEm6fJFv+JLWpg3HuFG0erKXnq3NxpkYAy=qb_w@mail.gmail.com>
The threaded parts of index-pack increment the number of resolved
deltas in nr_resolved_deltas guarded by counter_mutex. However, the
per-thread outer loop accessed nr_resolved_deltas without any locks.
This is not wrong as such, since it doesn't matter all that much
whether we get an outdated value. However, unless someone proves that
this one lock makes all the performance difference, it would be much
cleaner to guard _all_ accesses to the variable with the lock.
The only such use is display_progress() in the threaded section (all
others are in the conclude_pack() callchain outside the threaded
part). To make it obvious that it cannot deadlock, move it out of
work_mutex.
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
> The only thing I don't
> like here is the double locking (work_lock then counter_lock) is an
> invitation for potential deadlocks (not now, but who now what can
> change later). I think you could move work_lock(); down after
> counter_unlock() so we hold one lock at a time.
Good point.
builtin/index-pack.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index b3fee45..a481f54 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -967,8 +967,10 @@ static void *threaded_second_pass(void *data)
set_thread_data(data);
for (;;) {
int i;
- work_lock();
+ counter_lock();
display_progress(progress, nr_resolved_deltas);
+ counter_unlock();
+ work_lock();
while (nr_dispatched < nr_objects &&
is_delta_type(objects[nr_dispatched].type))
nr_dispatched++;
--
1.8.2.490.gc3bbe62
next prev parent reply other threads:[~2013-03-19 14:17 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 22:42 regression in multi-threaded git-pack-index Stefan Zager
2013-03-16 11:41 ` Jeff King
2013-03-16 12:38 ` Duy Nguyen
2013-03-19 8:17 ` Thomas Rast
2013-03-19 9:30 ` Jeff King
2013-03-19 9:59 ` Jeff King
2013-03-19 10:08 ` Jeff King
2013-03-19 10:24 ` Jeff King
2013-03-19 10:29 ` Thomas Rast
2013-03-19 10:33 ` Jeff King
2013-03-19 10:45 ` Thomas Rast
2013-03-19 10:47 ` Jeff King
2013-03-19 10:58 ` [PATCH] index-pack: always zero-initialize object_entry list Jeff King
2013-03-19 15:33 ` Thomas Rast
2013-03-19 15:43 ` Jeff King
2013-03-19 15:52 ` Jeff King
2013-03-19 16:17 ` [PATCH v2] " Jeff King
2013-03-19 16:27 ` Thomas Rast
2013-03-19 17:13 ` Junio C Hamano
2013-03-20 19:12 ` Eric Sunshine
2013-03-20 19:13 ` Jeff King
2013-03-20 19:14 ` Eric Sunshine
2013-03-19 12:35 ` regression in multi-threaded git-pack-index Duy Nguyen
2013-03-19 13:01 ` [PATCH] index-pack: protect deepest_delta in multithread code Nguyễn Thái Ngọc Duy
2013-03-19 13:25 ` Jeff King
2013-03-19 13:50 ` Thomas Rast
2013-03-19 14:07 ` Duy Nguyen
2013-03-19 14:16 ` Thomas Rast [this message]
2013-03-19 15:53 ` [PATCH v2] index-pack: guard nr_resolved_deltas reads by lock Junio C Hamano
2013-03-19 15:41 ` regression in multi-threaded git-pack-index Thomas Rast
2013-03-19 15:45 ` Thomas Rast
2013-03-19 16:11 ` Thomas Rast
2013-03-19 17:58 ` Junio C Hamano
2013-03-19 22:08 ` [PATCH] sha1_file: remove recursion in packed_object_info Thomas Rast
2013-03-20 16:47 ` Junio C Hamano
2013-03-25 9:27 ` thomas
2013-03-25 18:07 ` [PATCH v2 0/3] Recursion-free unpack_entry and packed_object_info Thomas Rast
2013-03-25 18:07 ` [PATCH v2 1/3] sha1_file: remove recursion in packed_object_info Thomas Rast
2013-03-25 18:07 ` [PATCH v2 2/3] Refactor parts of in_delta_base_cache/cache_or_unpack_entry Thomas Rast
2013-03-25 23:15 ` Junio C Hamano
2013-03-26 11:09 ` thomas
2013-03-25 18:07 ` [PATCH v2 3/3] sha1_file: remove recursion in unpack_entry Thomas Rast
2013-03-25 23:19 ` Junio C Hamano
2013-03-26 3:37 ` [PATCH v2 0/3] Recursion-free unpack_entry and packed_object_info Nicolas Pitre
2013-03-25 18:17 ` [PATCH] sha1_file: remove recursion in packed_object_info Junio C Hamano
2013-03-27 20:03 ` [PATCH v3 0/3] Recursion-free unpack_entry and packed_object_info Thomas Rast
2013-03-27 20:03 ` [PATCH v3 1/3] sha1_file: remove recursion in packed_object_info Thomas Rast
2013-03-27 20:03 ` [PATCH v3 2/3] Refactor parts of in_delta_base_cache/cache_or_unpack_entry Thomas Rast
2013-03-27 20:03 ` [PATCH v3 3/3] sha1_file: remove recursion in unpack_entry Thomas Rast
2013-03-27 20:29 ` Junio C Hamano
2013-03-20 1:17 ` regression in multi-threaded git-pack-index Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8ddf4db38f33034b5ebf504a18948bccf841ab72.1363702423.git.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=szager@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).