On 9/15/2018 6:22 AM, Duy Nguyen wrote:
+index.threads::
+ Specifies the number of threads to spawn when loading the index.
+ This is meant to reduce index load time on multiprocessor machines.
+ Specifying 0 or 'true' will cause Git to auto-detect the number of
+ CPU's and set the number of threads accordingly. Defaults to 'true'.
I'd rather this variable defaults to 0. Spawning threads have
associated cost and most projects out there are small enough that this
multi threading could just add more cost than gain. It only makes
sense to enable this on huge repos.
Wait there's no way to disable this parallel reading? Does not sound
right. And if ordinary numbers mean the number of threads then 0
should mean no threading. Auto detection could have a new keyword,
like 'auto'.
The index.threads setting is patterned after the pack.threads setting
for consistency. Specifying 1 (or 'false') will disable multithreading
but I will call that out explicitly in the documentation to make it more
obvious.
The THREAD_COST logic is designed to ensure small repos don't incur more
cost than gain. If you have data on that logic that shows it isn't
working properly, I'm happy to change the logic as necessary.
--- a/read-cache.c
+++ b/read-cache.c
@@ -23,6 +23,10 @@
#include "split-index.h"
#include "utf8.h"
#include "fsmonitor.h"
+#ifndef NO_PTHREADS
+#include <pthread.h>
+#include <thread-utils.h>
+#endif
I don't think you're supposed to include system header files after
"cache.h". Including thread-utils.h should be enough (and it keeps the
exception of inclduing pthread.h in just one place). Please use
"pthread-utils.h" instead of <pthread-utils.h> which is usually for
system header files. And include ptherad-utils.h unconditionally.
Thanks, I'll fix that.
/* Mask for the name length in ce_flags in the on-disk index */
@@ -1898,6 +1902,46 @@ static unsigned long read_eoie_extension(void *mmap_, size_t mmap_size);
#endif
static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, unsigned long offset);
+struct load_index_extensions
+{
+#ifndef NO_PTHREADS
+ pthread_t pthread;
+#endif
+ struct index_state *istate;
+ void *mmap;
+ size_t mmap_size;
+ unsigned long src_offset;
+};
+
+static void *load_index_extensions(void *_data)
+{
+ struct load_index_extensions *p = _data;
+ unsigned long src_offset = p->src_offset;
+
+ while (src_offset <= p->mmap_size - the_hash_algo->rawsz - 8) {
+ /* After an array of active_nr index entries,
+ * there can be arbitrary number of extended
+ * sections, each of which is prefixed with
+ * extension name (4-byte) and section length
+ * in 4-byte network byte order.
+ */
+ uint32_t extsize;
+ memcpy(&extsize, (char *)p->mmap + src_offset + 4, 4);
+ extsize = ntohl(extsize);
+ if (read_index_extension(p->istate,
+ (const char *)p->mmap + src_offset,
+ (char *)p->mmap + src_offset + 8,
+ extsize) < 0) {
+ munmap(p->mmap, p->mmap_size);
+ die("index file corrupt");
_()
You're feedback style can be a bit abrupt and terse. I _think_ what you
are trying to say here is that the "die" call should use the _() macro
around the string.
This is an edit of the previous code that loaded index extensions and
doesn't change the use of _(). I don't know the rules for when _()
should be used and didn't have any luck finding where it was documented
so left it unchanged.
FWIW, in this file alone there are 20 existing instances of die() or
die_errorno() and only two that use the _() macro. A quick grep through
the source code shows thousands of die() calls the vast majority of
which do not use the _() macro. This appears to be an area that is
unclear and inconsistent and could use some attention in a separate patch.
+ /* if we created a thread, join it otherwise load the extensions on the primary thread */
+#ifndef NO_PTHREADS
+ if (extension_offset && pthread_join(p.pthread, NULL))
+ die(_("unable to join load_index_extensions_thread"));
I guess the last _ is a typo and you wanted "unable to join
load_index_extensions thread". Please use die_errno() instead.
Why should this be die_errorno() here? All other instances of
pthread_join() failing in a fatal way use die(), not die_errorno().
+#endif
+ if (!extension_offset) {
+ p.src_offset = src_offset;
+ load_index_extensions(&p);
}
munmap(mmap, mmap_size);
return istate->cache_nr;
--
2.18.0.windows.1