From: Linus Torvalds <torvalds@linux-foundation.org>
To: Jon Smirl <jonsmirl@gmail.com>
Cc: Nicolas Pitre <nico@cam.org>, Junio C Hamano <gitster@pobox.com>,
gcc@gcc.gnu.org, Git Mailing List <git@vger.kernel.org>
Subject: Re: Something is broken in repack
Date: Tue, 11 Dec 2007 17:19:00 -0000 [thread overview]
Message-ID: <alpine.LFD.0.9999.0712110806540.25032@woody.linux-foundation.org> (raw)
In-Reply-To: <9e4733910712102301p5e6c4165v6afb32d157478828@mail.gmail.com>
On Tue, 11 Dec 2007, Jon Smirl wrote:
>
> So why does our threaded code take 20 CPU minutes longer (12%) to run
> than the same code with a single thread?
Threaded code *always* takes more CPU time. The only thing you can hope
for is a wall-clock reduction. You're seeing probably a combination of
(a) more cache misses
(b) bigger dataset active at a time
and a probably fairly miniscule
(c) threading itself tends to have some overheads.
> Q6600 is just two E6600s in the same package, the caches are not shared.
Sure they are shared. They're just not *entirely* shared. But they are
shared between each two cores, so each thread essentially has only half
the cache they had with the non-threaded version.
Threading is *not* a magic solution to all problems. It gives you
potentially twice the CPU power, but there are real downsides that you
should keep in mind.
> Why does the threaded code need 2.24GB (google allocator, 2.85GB gcc)
> with 4 threads? But only need 950MB with one thread? Where's the extra
> gigabyte going?
I suspect that it's really simple: you have a few rather big files in the
gcc history, with deep delta chains. And what happens when you have four
threads running at the same time is that they all need to keep all those
objects that they are working on - and their hash state - in memory at the
same time!
So if you want to use more threads, that _forces_ you to have a bigger
memory footprint, simply because you have more "live" objects that you
work on. Normally, that isn't much of a problem, since most source files
are small, but if you have a few deep delta chains on big files, both the
delta chain itself is going to use memory (you may have limited the size
of the cache, but it's still needed for the actual delta generation, so
it's not like the memory usage went away).
That said, I suspect there are a few things fighting you:
- threading is hard. I haven't looked a lot at the changes Nico did to do
a threaded object packer, but what I've seen does not convince me it is
correct. The "trg_entry" accesses are *mostly* protected with
"cache_lock", but nothing else really seems to be, so quite frankly, I
wouldn't trust the threaded version very much. It's off by default, and
for a good reason, I think.
For example: the packing code does this:
if (!src->data) {
read_lock();
src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz);
read_unlock();
...
and that's racy. If two threads come in at roughly the same time and
see a NULL src->data, theyÍ'll both get the lock, and they'll both
(serially) try to fill it in. It will all *work*, but one of them will
have done unnecessary work, and one of them will have their result
thrown away and leaked.
Are you hitting issues like this? I dunno. The object sorting means
that different threads normally shouldn't look at the same objects (not
even the sources), so probably not, but basically, I wouldn't trust the
threading 100%. It needs work, and it needs to stay off by default.
- you're working on a problem that isn't really even worth optimizing
that much. The *normal* case is to re-use old deltas, which makes all
of the issues you are fighting basically go away (because you only have
a few _incremental_ objects that need deltaing).
In other words: the _real_ optimizations have already been done, and
are done elsewhere, and are much smarter (the best way to optimize X is
not to make X run fast, but to avoid doing X in the first place!). The
thing you are trying to work with is the one-time-only case where you
explicitly disable that big and important optimization, and then you
complain about the end result being slow!
It's like saying that you're compiling with extreme debugging and no
optimizations, and then complaining that the end result doesn't run as
fast as if you used -O2. Except this is a hundred times worse, because
you literally asked git to do the really expensive thing that it really
really doesn't want to do ;)
> Is there another allocator to try? One that combines Google's
> efficiency with gcc's speed?
See above: I'd look around at threading-related bugs and check the way we
lock (or don't) accesses.
Linus
next prev parent reply other threads:[~2007-12-11 16:34 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <9e4733910712071505y6834f040k37261d65a2d445c4@mail.gmail.com>
[not found] ` <9e4733910712101825l33cdc2c0mca2ddbfd5afdb298@mail.gmail.com>
[not found] ` <alpine.LFD.0.99999.0712102231570.555@xanadu.home>
[not found] ` <9e4733910712102125w56c70c0cxb8b00a060b62077@mail.gmail.com>
2007-12-11 7:01 ` Jon Smirl
2007-12-11 7:34 ` Jon Smirl
2007-12-11 11:11 ` Andreas Ericsson
2007-12-11 15:01 ` Nicolas Pitre
2007-12-11 15:36 ` Nicolas Pitre
2007-12-11 16:20 ` Jon Smirl
2007-12-11 16:22 ` Nicolas Pitre
2007-12-11 16:34 ` Jon Smirl
2007-12-12 7:25 ` Nicolas Pitre
2007-12-12 12:02 ` David Kastrup
2007-12-14 16:44 ` Wolfram Gloger
2007-12-12 16:14 ` Nicolas Pitre
2007-12-12 16:37 ` Paolo Bonzini
2007-12-12 16:42 ` Linus Torvalds
2007-12-12 16:54 ` David Miller
2007-12-12 17:12 ` Linus Torvalds
2007-12-12 17:29 ` Jon Smirl
2007-12-14 16:19 ` Wolfram Gloger
2007-12-14 16:59 ` David Kastrup
2007-12-14 18:49 ` Wolfram Gloger
2007-12-13 14:09 ` Nguyen Thai Ngoc Duy
[not found] ` <fjrj9k$n6k$1@ger.gmane.org>
2007-12-13 16:39 ` Paolo Bonzini
2007-12-13 17:40 ` Johannes Sixt
2007-12-14 2:31 ` Jakub Narebski
[not found] ` <fjt6vm$n7d$1@ger.gmane.org>
2007-12-14 6:39 ` Nguyen Thai Ngoc Duy
2007-12-14 9:02 ` Paolo Bonzini
2007-12-14 9:39 ` Harvey Harrison
2007-12-14 10:52 ` Jakub Narebski
2007-12-14 13:25 ` Nguyen Thai Ngoc Duy
2007-12-14 13:53 ` Nicolas Pitre
2007-12-12 16:19 ` Nicolas Pitre
2007-12-13 7:39 ` Andreas Ericsson
2007-12-14 16:12 ` Wolfram Gloger
2007-12-11 17:19 ` Linus Torvalds [this message]
2007-12-11 17:24 ` Nicolas Pitre
2007-12-11 17:28 ` David Miller
2007-12-11 18:43 ` Nicolas Pitre
2007-12-11 20:34 ` Andreas Ericsson
2007-12-11 18:57 ` Jon Smirl
2007-12-11 19:17 ` Nicolas Pitre
2007-12-11 19:40 ` Linus Torvalds
2007-12-11 20:26 ` Junio C Hamano
2007-12-12 5:06 ` Andreas Ericsson
2007-12-11 17:44 ` Daniel Berlin
2007-12-11 13:49 ` Nicolas Pitre
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=alpine.LFD.0.9999.0712110806540.25032@woody.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=gcc@gcc.gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonsmirl@gmail.com \
--cc=nico@cam.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).