Speed up Counting Objects with bitmap data
Subsystems (2)
cover Speed up Counting Objects with bitmap data
Hello friends and enemies from the lovevely Git Mailing list.
I bring to you a patch series that implement a quite interesting performance
optimization: the removal of the "Counting Objects" phase during pack-objects by using a pre-computed bitmap to find the reachable objects in the packfile.
As you probably know, Shawn Pearce designed this approach a few months ago and implemented it for JGit, with very exciting results.
This is a not-so-straightforward port of his original design: The general approach is the same, but unfortunately we were not able to re-use JGit's original on-disk format for the .bitmap files.
There is a full technical spec for the new format (v2) in patch 09, including benchmarks and rationale for the new design. The gist of it is that JGit's original format is not mmapable (JGit tends to not mmap anything), and that becomes very costly in practice with upload-pack, which spawns a new process for every upload.
The header and metadata for both formats are however compatible, so it should be trivial to update JGit to read/write this format too. I intend to do this on the coming weeks, and I also hope that the v2 implementation will be slightly faster than the actual, even with the shortcomings of the JVM.
The patch series, although massive, is rather straightforward.
Most of the patches are isolated refactorings that enable access to a few functions that were previously hidden (re. packfile data). These functions are needed for reading and writing the bitmap indexes.
Patch 03 is worth noting because it implements a performance optimization for pack-objects which isn't particularly good in normal invocations (~10% speed up) but that will show great benefits in later patches when it comes to writing the bitmap indexes.
Patch 10 is the core of the series, implementing the actual loading of bitmap indexes and optimizing the Counting Objects phase of pack-objects. Like with every other patch that offers performance improvements, sample benchmarks are provided (spoiler:
they are pretty fucking cool).
Patch 11 and 16 are samples of using the new Bitmap traversal API to speed up other parts of Git (rev-list --objects and rev-list --count, respectively).
Patch 12, 13 and 15 implement the actual writing of bitmap indexes. Like JGit, patch 12 enables writing a bitmap index as part of the pack-objects process (and hence as part of a normal gc run). On top of that, I implemented a new plumbing command in patch 15 that allows to write bitmap indexes for already-existing packfiles.
I'd love your feedback on the design and implementation of this feature. I deem it rather stable, as we've been testing it on production on the world's largest Git host (Git Hub Dot Com The Web Site) with good results, so I'd love it to have it upstreamed on Core Git.
Strawberry kisses,
vmg
Jeff King (1):
list-objects: mark tree as unparsed when we free its buffer
Vicent Marti (15):
sha1_file: refactor into find_pack_object_pos
pack-objects: use a faster hash table
pack-objects: make pack_name_hash global
revision: allow setting custom limiter function
sha1_file: export git_open_noatime
compat: add endinanness helpers
ewah: compressed bitmap implementation
documentation: add documentation for the bitmap format
pack-objects: use bitmaps when packing objects
rev-list: add bitmap mode to speed up lists
pack-objects: implement bitmap writing
repack: consider bitmaps when performing repacks
sha1_file: implement nth_packed_object_info
write-bitmap: implement new git command to write bitmaps
rev-list: Optimize --count using bitmaps too
Documentation/technical/bitmap-format.txt | 235 ++++++++ Makefile | 11 + builtin.h | 1 + builtin/pack-objects.c | 362 +++++++----- builtin/pack-objects.h | 33 ++ builtin/rev-list.c | 35 +- builtin/write-bitmap.c | 256 +++++++++ cache.h | 5 + ewah/bitmap.c | 229 ++++++++ ewah/ewah_bitmap.c | 703 ++++++++++++++++++++++++ ewah/ewah_io.c | 199 +++++++ ewah/ewah_rlw.c | 124 +++++ ewah/ewok.h | 194 +++++++ ewah/ewok_rlw.h | 114 ++++ git-compat-util.h | 28 + git-repack.sh | 10 +- git.c | 1 + khash.h | 329 +++++++++++ list-objects.c | 1 + pack-bitmap-write.c | 520 ++++++++++++++++++ pack-bitmap.c | 855 +++++++++++++++++++++++++++++ pack-bitmap.h | 64 +++ pack-write.c | 2 + revision.c | 5 + revision.h | 2 + sha1_file.c | 57 +- 26 files changed, 4212 insertions(+), 163 deletions(-) create mode 100644 Documentation/technical/bitmap-format.txt create mode 100644 builtin/pack-objects.h create mode 100644 builtin/write-bitmap.c create mode 100644 ewah/bitmap.c create mode 100644 ewah/ewah_bitmap.c create mode 100644 ewah/ewah_io.c create mode 100644 ewah/ewah_rlw.c create mode 100644 ewah/ewok.h create mode 100644 ewah/ewok_rlw.h create mode 100644 khash.h create mode 100644 pack-bitmap-write.c create mode 100644 pack-bitmap.c create mode 100644 pack-bitmap.h
Signature · 1 line
1.7.9.5
PATCH 1/16 list-objects: mark tree as unparsed when we free its buffer
From: Jeff King <[email protected]>
We free the tree buffer during traversal to save memory. However, we do not reset the "parsed" flag, which leaves a landmine for the next person to use the tree. When they call parse_tree it will do nothing, and they will segfault when they try to access the buffer.
This hasn't mattered until now because most rev-list traversals would exit the program immediately afterwards, but the bitmap writer wants to access the trees twice.
--- list-objects.c | 1 + 1 file changed, 1 insertion(+)
list-objects.c +1 -0
@@ -125,6 +125,7 @@ static void process_tree(struct rev_info *revs,strbuf_setlen (base, baselen);free (tree->buffer); tree->buffer =NULL ; + tree->object.parsed =0 ; } static void mark_edge_parents_uninteresting(struct commit *commit,
Signature · 1 line
1.7.9.5
PATCH 2/16 sha1_file: refactor into `find_pack_object_pos`
In reply to Vicent MartiLooking up the offset in the packfile for a given SHA1 involves the following:
- Finding the position in the index for the given SHA1
- Accessing the offset cache in the index for the found position
There are cases however where we'd like to find the position of a SHA1 in the index without looking up the packfile offset (e.g. when accessing information that has been indexed based on index offsets).
This refactoring implements find_pack_object_pos, returning the position in the index, and re-implements find_pack_entry_one(returning the actual offset in the packfile) to use the new function.
--- cache.h | 1 + sha1_file.c | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-)
cache.h +1 -0
@@ -1101,6 +1101,7 @@ extern void clear_delta_base_cache(void);extern struct packed_git *add_packed_git (const char *,int ,int );extern const unsigned char *nth_packed_object_sha1 (struct packed_git *,uint32_t );extern off_t nth_packed_object_offset (const struct packed_git *,uint32_t ); +extern int find_pack_entry_pos (const unsigned char *sha1,struct packed_git *p);extern off_t find_pack_entry_one (const unsigned char *,struct packed_git *);extern int is_pack_valid (struct packed_git *);extern void *unpack_entry (struct packed_git *,off_t ,enum object_type *,unsigned long *);
sha1_file.c +17 -10
@@ -2205,8 +2205,7 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n) } } -off_t find_pack_entry_one (const unsigned char *sha1, -struct packed_git *p) +int find_pack_entry_pos (const unsigned char *sha1,struct packed_git *p) {const uint32_t *level1_ofs = p->index_data;const unsigned char *index = p->index_data;
@@ -2219,7 +2218,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,if (!index) {if (open_pack_index (p)) -return 0 ; +return -1 ; level1_ofs = p->index_data; index = p->index_data; }
@@ -2243,12 +2242,9 @@ off_t find_pack_entry_one(const unsigned char *sha1,if (use_lookup <0 ) use_lookup = !!getenv ("GIT_USE_LOOKUP" ); +if (use_lookup) { -int pos =sha1_entry_pos (index, stride,0 , - lo, hi, p->num_objects, sha1); -if (pos <0 ) -return 0 ; -return nth_packed_object_offset (p, pos); +return sha1_entry_pos (index, stride,0 , lo, hi, p->num_objects, sha1); } do {
@@ -2259,13 +2255,24 @@ off_t find_pack_entry_one(const unsigned char *sha1,printf ("lo %u hi %u rg %u mi %u\n" , lo, hi, hi - lo, mi);if (!cmp) -return nth_packed_object_offset (p, mi); +return mi;if (cmp >0 ) hi = mi;else lo = mi+1 ; }while (lo < hi); -return 0 ; + +return -1 ; +} + +off_t find_pack_entry_one (const unsigned char *sha1,struct packed_git *p) +{ +int pos; + +if ((pos =find_pack_entry_pos (sha1, p)) <0 ) +return 0 ; + +return nth_packed_object_offset (p, (uint32_t )pos); }int is_pack_valid (struct packed_git *p)
Signature · 1 line
1.7.9.5
PATCH 3/16 pack-objects: use a faster hash table
In reply to Vicent MartiIn a normal pack-objects invocations runtime is dominated by the counting objects phase and the time spent performing hash operations with the object_entry structs is not particularly relevant.
If the Counting Objects phase however gets optimized to perform batch insertions (like it is the goal of this patch series), the current hash table implementation starts to bottleneck in both insertion times and memory reallocations caused by the fast growth of the hash table.
For instance, these are function timings in a hotspot profiling of a pack-objects run:
locate_object_entry_hash :: 563.935ms hashcmp :: 195.991ms add_object_entry_1 :: 47.962ms
This commit brings khash.h, a header only hash table implementation that while remaining rather simple (uses quadratic probing and a standard hashing scheme) and self-contained, offers a significant performance improvement in both insertion and lookup times.
khash is a generic hash table implementation that can be 'templated' for any given type while maintaining good performance by using preprocessor macros. This specific version has been modified to define by default a khash_sha1 type, a map of SHA1s (const unsigned char[20]) to void * pointers.
When replacing the old hash table implementation in pack-objects with the khash_sha1 table, the insertion time is greatly reduced:
kh_put_sha1 :: 284.011ms add_object_entry_1 : 36.06ms hashcmp :: 24.045ms
This reduction of more than 50% in the insertion and lookup times, although nice, is not particularly noticeable for normal pack-objects
operation: pack-objects performs massive batch insertions and relatively few lookups, so khash doesn't get a chance to shine here.
The big win here, however, is in the massively reduced amount of hash collisions (as you can see from the huge reduction of time spent in hashcmp after the change). These greatly improved lookup times will result critical once we implement the writing algorithm for bitmap indxes in a later patch of this series.
The bitmap writing phase for a repository like linux requires several million table lookups: using the new hash table saves 1min and 20s from a pack-objects invocation that also writes out bitmaps.
--- Makefile | 1 + builtin/pack-objects.c | 210 ++++++++++++++++--------------- khash.h | 329 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 441 insertions(+), 99 deletions(-) create mode 100644 khash.h
Makefile +1 -0
@@ -683,6 +683,7 @@ LIB_H += grep.h LIB_H += hash.h LIB_H += help.h LIB_H += http.h +LIB_H += khash.h LIB_H += kwset.h LIB_H += levenshtein.h LIB_H += line-log.h
builtin/pack-objects.c +111 -99
361 lines not on this page · raw message
khash.h new file +329 -0
329 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 4/16 pack-objects: make `pack_name_hash` global
In reply to Vicent MartiThe hash function used by builtin/pack-objects.c to efficiently find delta bases when packing can be of interest for other parts of Git that also have to deal with delta bases.
--- builtin/pack-objects.c | 24 ++---------------------- cache.h | 2 ++ sha1_file.c | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 22 deletions(-)
builtin/pack-objects.c +2 -22
@@ -854,26 +854,6 @@ static struct object_entry *locate_object_entry(const unsigned char *sha1)return NULL ; } -static unsigned name_hash (const char *name) -{ -unsigned c, hash =0 ; - -if (!name) -return 0 ; - -/* -* This effectively just creates a sortable number from the -* last sixteen non-whitespace characters. Last characters -* count "most", so things that end in ".c" sort together. -*/ -while ((c = *name++) !=0 ) { -if (isspace (c)) -continue ; - hash = (hash >>2 ) + (c <<24 ); - } -return hash; -} -static void setup_delta_attr_check (struct git_attr_check *check) {static struct git_attr *attr_delta;
@@ -977,7 +957,7 @@ static int add_object_entry_1(const unsigned char *sha1, enum object_type type,static int add_object_entry (const unsigned char *sha1,enum object_type type,const char *name,int exclude) { -if (add_object_entry_1 (sha1, type,name_hash (name), exclude,NULL ,0 )) { +if (add_object_entry_1 (sha1, type,pack_name_hash (name), exclude,NULL ,0 )) {struct object_entry *entry = objects[nr_objects -1 ];if (name &&no_try_delta (name))
@@ -1186,7 +1166,7 @@ static void add_preferred_base_object(const char *name) {struct pbase_tree *it;int cmplen; -unsigned hash =name_hash (name); +unsigned hash =pack_name_hash (name);if (!num_preferred_base ||check_pbase_path (hash))return ;
cache.h +2 -0
@@ -653,6 +653,8 @@ extern char *sha1_pack_index_name(const unsigned char *sha1);extern const char *find_unique_abbrev (const unsigned char *sha1,int );extern const unsigned char null_sha1[20 ]; +extern uint32_t pack_name_hash (const char *name); +static inline int hashcmp (const unsigned char *sha1,const unsigned char *sha2) {int i;
sha1_file.c +20 -0
@@ -60,6 +60,26 @@ static struct cached_object empty_tree = { 0 }; +uint32_t pack_name_hash (const char *name) +{ +unsigned c, hash =0 ; + +if (!name) +return 0 ; + +/* +* This effectively just creates a sortable number from the +* last sixteen non-whitespace characters. Last characters +* count "most", so things that end in ".c" sort together. +*/ +while ((c = *name++) !=0 ) { +if (isspace (c)) +continue ; + hash = (hash >>2 ) + (c <<24 ); + } +return hash; +} +static struct packed_git *last_found_pack;static struct cached_object *find_cached_object (const unsigned char *sha1)
Signature · 1 line
1.7.9.5
PATCH 6/16 sha1_file: export `git_open_noatime`
In reply to Vicent MartiThe git_open_noatime helper can be of general interest for other consumers of git's different on-disk formats.
--- cache.h | 1 + sha1_file.c | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-)
cache.h +1 -0
@@ -769,6 +769,7 @@ extern int hash_sha1_file(const void *buf, unsigned long len, const char *type,extern int write_sha1_file (const void *buf,unsigned long len,const char *type,unsigned char *return_sha1);extern int pretend_sha1_file (void *,unsigned long ,enum object_type ,unsigned char *);extern int force_object_loose (const unsigned char *sha1,time_t mtime); +extern int git_open_noatime (const char *name);extern void *map_sha1_file (const unsigned char *sha1,unsigned long *size);extern int unpack_sha1_header (git_zstream *stream,unsigned char *map,unsigned long mapsize,void *buffer,unsigned long bufsiz);extern int parse_sha1_header (const char *hdr,unsigned long *sizep);
sha1_file.c +1 -3
@@ -259,8 +259,6 @@ char *sha1_pack_index_name(const unsigned char *sha1)struct alternate_object_database *alt_odb_list;static struct alternate_object_database **alt_odb_tail; -static int git_open_noatime (const char *name); -/* * Prepare alternate object database registry. *
@@ -1307,7 +1305,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,return hashcmp (sha1, real_sha1) ?-1 :0 ; } -static int git_open_noatime (const char *name) +int git_open_noatime (const char *name) {static int sha1_file_open_flag =O_NOATIME ;
Signature · 1 line
1.7.9.5
PATCH 8/16 ewah: compressed bitmap implementation
In reply to Vicent MartiEWAH is a word-aligned compressed variant of a bitset (i.e. a data structure that acts as a 0-indexed boolean array for many entries).
It uses a 64-bit run-length encoding (RLE) compression scheme, trading some compression for better processing speed.
The goal of this word-aligned implementation is not to achieve the best compression, but rather to improve query processing time. As it stands right now, this EWAH implementation will always be more efficient storage-wise than its uncompressed alternative.
EWAH arrays will be used as the on-disk format to store reachability bitmaps for all objects in a repository while keeping reasonable sizes, in the same way that JGit does.
This EWAH implementation is a mostly straightforward port of the original javaewah library that JGit currently uses. The library is self-contained and has been embedded whole (4 files) inside the ewah folder to ease redistribution.
The library is re-licensed under the GPLv2 with the permission of Daniel Lemire, the original author. The source code for the C version can be found on GitHub:
https://github.com/vmg/libewok
The original Java implementation can also be found on GitHub:
https://github.com/lemire/javaewah
--- Makefile | 6 + ewah/bitmap.c | 229 +++++++++++++++++ ewah/ewah_bitmap.c | 703 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ewah/ewah_io.c | 199 +++++++++++++++ ewah/ewah_rlw.c | 124 +++++++++ ewah/ewok.h | 194 +++++++++++++++ ewah/ewok_rlw.h | 114 +++++++++ 7 files changed, 1569 insertions(+) create mode 100644 ewah/bitmap.c create mode 100644 ewah/ewah_bitmap.c create mode 100644 ewah/ewah_io.c create mode 100644 ewah/ewah_rlw.c create mode 100644 ewah/ewok.h create mode 100644 ewah/ewok_rlw.h
Makefile +6 -0
@@ -672,6 +672,8 @@ LIB_H += diff.h LIB_H += diffcore.h LIB_H += dir.h LIB_H += exec_cmd.h +LIB_H += ewah/ewok.h +LIB_H += ewah/ewok_rlw.h LIB_H += fetch-pack.h LIB_H += fmt-merge-msg.h LIB_H += fsck.h
@@ -802,6 +804,10 @@ LIB_OBJS += dir.o LIB_OBJS += editor.o LIB_OBJS += entry.o LIB_OBJS += environment.o +LIB_OBJS += ewah/bitmap.o +LIB_OBJS += ewah/ewah_bitmap.o +LIB_OBJS += ewah/ewah_io.o +LIB_OBJS += ewah/ewah_rlw.o LIB_OBJS += exec_cmd.o LIB_OBJS += fetch-pack.o LIB_OBJS += fsck.o
ewah/bitmap.c new file +229 -0
229 lines not on this page · raw message
ewah/ewah_bitmap.c new file +703 -0
703 lines not on this page · raw message
ewah/ewah_io.c new file +199 -0
199 lines not on this page · raw message
ewah/ewah_rlw.c new file +124 -0
124 lines not on this page · raw message
ewah/ewok.h new file +194 -0
194 lines not on this page · raw message
ewah/ewok_rlw.h new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 02/16] sha1_file: refactor into `find_pack_object_pos`
In reply to Vicent Martisha1_file.c off_t find_pack_entry_one(const unsigned char *sha1, · line 2248
Quoted 8 lines · Vicent Marti
sha1_file.c +1
-5if (use_lookup) { -int pos =sha1_entry_pos (index, stride,0 , - lo, hi, p->num_objects, sha1); -if (pos <0 ) -return 0 ; -return nth_packed_object_offset (p, pos); +return sha1_entry_pos (index, stride,0 , lo, hi, p->num_objects, sha1); }
Our house style prefers not having the braces in a single-line conditional.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 03/16] pack-objects: use a faster hash table
In reply to Vicent MartiQuoted 19 lines · Vicent Marti
builtin/pack-objects.c +6
-6@@ -901,19 +896,19 @@ static int no_try_delta(const char *path)return 0 ; } -static int add_object_entry (const unsigned char *sha1,enum object_type type, -const char *name,int exclude) +static int add_object_entry_1 (const unsigned char *sha1,enum object_type type, +uint32_t hash,int exclude,struct packed_git *found_pack, +off_t found_offset) {struct object_entry *entry; -struct packed_git *p, *found_pack =NULL ; -off_t found_offset =0 ; -int ix; -unsigned hash =name_hash (name); +struct packed_git *p; +khiter_t ix; +int hash_ret;
builtin/pack-objects.c static int no_try_delta(const char *path) · line 914
Quoted 10 lines
builtin/pack-objects.c +3
-3- ix = nr_objects ?locate_object_entry_hash (sha1) :-1 ; -if (ix >=0 ) { + ix =kh_put_sha1 (packed_objects, sha1, &hash_ret); +if (hash_ret ==0 ) {if (exclude) { - entry = objects + object_ix[ix] -1 ; + entry =kh_value (packed_objects, ix);if (!entry->preferred_base) nr_result--; entry->preferred_base =1 ;
After this, the function returns. The original did not add to the table the object name we are looking at, but the new code first adds it to the table with the unconditional kh_put_sha1() above. Is a call to kh_del_sha1() missing here ...
builtin/pack-objects.c static int add_object_entry(const unsigned char *sha1, enum object_type type, · line 921
Quoted 8 lines
builtin/pack-objects.c +2
-1@@ -921,38 +916,42 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,return 0 ; } -if (!exclude && local &&has_loose_object_nonlocal (sha1)) +if (!exclude && local &&has_loose_object_nonlocal (sha1)) { +kh_del_sha1 (packed_objects, ix);return 0 ;
... like this one, which seems to compensate for "ahh, after all we realize we do not want to add this one to the table"?
Quoted 24 lines
builtin/pack-objects.c +7
-7@@ -966,19 +965,30 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type, entry->in_pack_offset = found_offset; } -if (object_ix_hashsz *3 <= nr_objects *4 ) -rehash_objects (); -else - object_ix[-1 - ix] = nr_objects; +kh_value (packed_objects, ix) = entry; +kh_key (packed_objects, ix) = entry->idx.sha1; + objects[nr_objects++] = entry;display_progress (progress_state, nr_objects); -if (name &&no_try_delta (name)) - entry->no_try_delta =1 ; -return 1 ; } +static int add_object_entry (const unsigned char *sha1,enum object_type type, +const char *name,int exclude) +{ +if (add_object_entry_1 (sha1, type,name_hash (name), exclude,NULL ,0 )) {
builtin/pack-objects.c static int add_object_entry(const unsigned char *sha1, enum object_type type, · line 990
Quoted 10 lines
builtin/pack-objects.c +10
-0+struct object_entry *entry = objects[nr_objects -1 ]; + +if (name &&no_try_delta (name)) + entry->no_try_delta =1 ; + +return 1 ; + } + +return 0 ; +}
It is somewhat unclear what we are getting from the split of the main part of this function into *_1(), other than the *_1() function now has a very deep indentation inside "if (!found_pack)", which is always true because the caller always passes NULL to found_pack. Perhaps this is an unrelated refactoring that is needed for later steps and does not have anything to do with the use of new hash function?
Re: [PATCH 03/16] pack-objects: use a faster hash table
Quoted 4 lines · Junio C Hamano
After this, the function returns. The original did not add to the table the object name we are looking at, but the new code first adds it to the table with the unconditional
kh_put_sha1()above. Is a call tokh_del_sha1()missing here ...
No, this is not the case. That's the return case for when *the object was found because it already existed in the hash table* (hence we access it if we're excluding it, to tag it as excluded). We don't want to remove it from the hash table because we're not the ones we inserted it.
We only call kh_del_sha1 in the cases where:
1. The object wasn't found.
2. We inserted its key on the hash table.
3. We later learnt that we don't really want to pack this object.
Quoted 48 lines
builtin/pack-objects.c static int add_object_entry(const unsigned char *sha1, enum object_type type, · line 921
Quoted 9 lines
builtin/pack-objects.c +2
-1@@ -921,38 +916,42 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,return 0 ; } -if (!exclude && local &&has_loose_object_nonlocal (sha1)) +if (!exclude && local &&has_loose_object_nonlocal (sha1)) { +kh_del_sha1 (packed_objects, ix);return 0 ;... like this one, which seems to compensate for "ahh, after all we realize we do not want to add this one to the table"?
Quoted 24 lines
builtin/pack-objects.c +7
-7@@ -966,19 +965,30 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type, entry->in_pack_offset = found_offset; } -if (object_ix_hashsz *3 <= nr_objects *4 ) -rehash_objects (); -else - object_ix[-1 - ix] = nr_objects; +kh_value (packed_objects, ix) = entry; +kh_key (packed_objects, ix) = entry->idx.sha1; + objects[nr_objects++] = entry;display_progress (progress_state, nr_objects); -if (name &&no_try_delta (name)) - entry->no_try_delta =1 ; -return 1 ; } +static int add_object_entry (const unsigned char *sha1,enum object_type type, +const char *name,int exclude) +{ +if (add_object_entry_1 (sha1, type,name_hash (name), exclude,NULL ,0 )) {builtin/pack-objects.c static int add_object_entry(const unsigned char *sha1, enum object_type type, · line 990
Quoted 10 lines
builtin/pack-objects.c +10
-0+struct object_entry *entry = objects[nr_objects -1 ]; + +if (name &&no_try_delta (name)) + entry->no_try_delta =1 ; + +return 1 ; + } + +return 0 ; +}
Quoted 7 lines
It is somewhat unclear what we are getting from the split of the main part of this function into
*_1(), other than the*_1()function now has a very deep indentation inside "if (!found_pack)", which is always true because the caller always passes NULL tofound_pack. Perhaps this is an unrelated refactoring that is needed for later steps and does not have anything to do with the use of new hash function?
Yes, apologies for not making this clear. By refactoring into _1, you can see how traverse_bitmap_commit_list can use the _1 version directly as a callback, to insert objects straight into the packing list without looking them up. This is very efficient because we can pass the whole API straight from the bitmap code:
1. The SHA1: we find it by simply looking up the nth sha1 on the pack index (if we are yielding bit n)
2. The object type: we find it because we have type indexes that let us know the type of any given bit in the bitmap by and-ing it with the index.
3. The hash for its name: we can look it up from the name hash cache in the new bitmap format.
4. Exclude flag: we never exclude when working with bitmaps
5. found_pack: all the bitmapped objects come from the same pack!
6. found_offset: we find it by simply looking up the nth offset on the pack index (if we are yielding bit n)
Boom! We filled the callback just from the data in a bitmap. Ain't that nice?
Let me amend the commit message.
Re: [PATCH 03/16] pack-objects: use a faster hash table
In reply to Vicent MartiQuoted 23 lines · Vicent Marti
This commit brings
khash.h, a header only hash table implementation that while remaining rather simple (uses quadratic probing and a standard hashing scheme) and self-contained, offers a significant performance improvement in both insertion and lookup times.
khashis a generic hash table implementation that can be 'templated' for any given type while maintaining good performance by using preprocessor macros. This specific version has been modified to define by default akhash_sha1type, a map of SHA1s (const unsigned char[20]) to void * pointers.When replacing the old hash table implementation in
pack-objectswith thekhash_sha1table, the insertion time is greatly reduced:kh_put_sha1 :: 284.011ms add_object_entry_1 : 36.06ms hashcmp :: 24.045msThis reduction of more than 50% in the insertion and lookup times, although nice, is not particularly noticeable for normal
pack-objects
operation:pack-objectsperforms massive batch insertions and relatively few lookups, sokhashdoesn't get a chance to shine here.
Quoted 5 lines
The big win here, however, is in the massively reduced amount of hash collisions (as you can see from the huge reduction of time spent in
hashcmpafter the change). These greatly improved lookup times will result critical once we implement the writing algorithm for bitmap indxes in a later patch of this series.
Is that reduction in collisions purely because it uses quadratic probing, or is there some other magic trick involved? Is the same also applicable to the other users of the "big" object hash table? (I assume Peff has already tried applying it there, but I'm still curious...)
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 03/16] pack-objects: use a faster hash table
Quoted 10 lines · Thomas Rast
Quoted 5 lines
The big win here, however, is in the massively reduced amount of hash collisions (as you can see from the huge reduction of time spent in
hashcmpafter the change). These greatly improved lookup times will result critical once we implement the writing algorithm for bitmap indxes in a later patch of this series.Is that reduction in collisions purely because it uses quadratic probing, or is there some other magic trick involved? Is the same also applicable to the other users of the "big" object hash table? (I assume Peff has already tried applying it there, but I'm still curious...)
I haven't done any actual timings yet.
The general code is quite similar to our object.c hash table, with the exception that it does quadratic probing. I did try quadratic probing on our object.c hash once and didn't see much improvement (similarly, Junio tried cuckoo hashing, but the numbers were not that exciting).
It's possible that the hash table in pack-objects did not behave as well as the one in object.c. It looks like we grow it when the table is 3/4 full, which is a little high (we grow at 1/2 in object.c). Quadratic probing should help when the hash table is close to full, so it would probably help. However, I also note that khash keeps its hash tables only half full, so that may be the real source of the performance improvement.
So I suspect two things (but as I said, haven't verified):
1. You could speed up pack-objects just by keeping the table half full rather than 3/4 full.
2. You would see little to no speedup by moving object.c to khash, as it is adding only quadratic probing. With quadratic probing, you could potentially tweak the kh_put_* to resize less aggressively (say, 2/3) and save some memory without loss of performance.
-Peff
Re: [PATCH 03/16] pack-objects: use a faster hash table
Quoted 4 lines · Jeff King
So I suspect two things (but as I said, haven't verified):
1. You could speed up pack-objects just by keeping the table half full rather than 3/4 full.
I wasn't able to show any measurable speedup with this. I tried to make as specific a measurement as I could, by adding a "counting only" option like this:
builtin/pack-objects.c +5 -0
@@ -2452,6 +2452,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)const char *rp_av[6 ];int rp_ac =0 ;int rev_list_unpacked =0 , rev_list_all =0 , rev_list_reflog =0 ; +int counting_only =0 ;struct option pack_objects_options[] = {OPT_SET_INT ('q' ,"quiet" , &progress,N_ ("do not show progress meter" ),0 ),
@@ -2515,6 +2516,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) N_("pack compression level")),OPT_SET_INT (0 ,"keep-true-parents" , &grafts_replace_parents,N_ ("do not hide commits by grafts" ),0 ), +OPT_BOOL (0 ,"counting-only" , &counting_only, +N_ ("exit after counting objects phase" )), OPT_END(), };
@@ -2600,6 +2603,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)for_each_ref (add_ref_tag,NULL );stop_progress (&progress_state); +if (counting_only) +return 0 ;if (non_empty && !nr_result)return 0 ;if (nr_result)
and even doing the whole object traversal ahead of time to just focus on the object-entry hash, like this:
git rev-list --objects --all >objects.out time git pack-objects --counting-only --stdout <objects.out
Tweaking the hash size didn't have any effect, but using Vicent's khash patch actually made it about 5% slower. So I wonder if I'm even measuring the right thing. Vicent, how did you get the timings you showed in the commit message?
-Peff
Re: [PATCH 03/16] pack-objects: use a faster hash table
In reply to Vicent MartiQuoted 2 lines · Vicent Marti
When replacing the old hash table implementation in
pack-objectswith thekhash_sha1table, the insertion time is greatly reduced:
Why? What is the exact change?
Quoted 2 lines
The big win here, however, is in the massively reduced amount of hash collisions
Okay, so there seems to be some problem with how collisions are handled in the hashtable.
Quoted 4 lines
builtin/pack-objects.c +0
-4-static int locate_object_entry_hash (const unsigned char *sha1) -{ -int i; -unsigned int ui;
builtin/pack-objects.c static void write_pack_file(void) · line 828
Quoted 10 lines
builtin/pack-objects.c +0
-10-memcpy (&ui, sha1,sizeof (unsigned int )); - i = ui % object_ix_hashsz; -while (0 < object_ix[i]) { -if (!hashcmp (sha1, objects[object_ix[i] -1 ].idx.sha1)) -return i; -if (++i == object_ix_hashsz) - i =0 ; - } -return -1 - i; -}
Classical chaining to handle collisions: very naive. Deserves to be thrown out.
Quoted 8 lines
builtin/pack-objects.c +0
-8-static void rehash_objects (void ) -{ -uint32_t i; -struct object_entry *oe; - - object_ix_hashsz = nr_objects *3 ; -if (object_ix_hashsz <1024 ) - object_ix_hashsz =1024 ;
builtin/pack-objects.c static void write_pack_file(void) · line 860
Quoted 10 lines
builtin/pack-objects.c +0
-10- object_ix =xrealloc (object_ix,sizeof (int ) * object_ix_hashsz); -memset (object_ix,0 ,sizeof (int ) * object_ix_hashsz); -for (i =0 , oe = objects; i < nr_objects; i++, oe++) { -int ix =locate_object_entry_hash (oe->idx.sha1); -if (0 <= ix) -continue ; - ix =-1 - ix; - object_ix[ix] = i +1 ; - } -}
This is called when the hashtable runs out of space. It didn't appear in your profiler because it doesn't appear to be a bottleneck, right? Growing aggressively to 3x times the number of objects probably explains it. Just for comparison, how does khash grow?
builtin/pack-objects.c static void write_pack_file(void) · line 850
Quoted 8 lines
static struct
object_entry*locate_object_entry(const unsigned char *sha1) {builtin/pack-objects.c +2
-3-int i; +khiter_t pos =kh_get_sha1 (packed_objects, sha1); -if (!object_ix_hashsz) -return NULL ; +if (pos <kh_end (packed_objects)) {
Wait, why is this required? When will kh_get_sha1() return a position beyond kh_end()? What does that mean?
builtin/pack-objects.c static void write_pack_file(void) · line 855
Quoted 8 lines
builtin/pack-objects.c +2
-3+return kh_value (packed_objects, pos); + } - i =locate_object_entry_hash (sha1); -if (0 <= i) -return &objects[object_ix[i]-1 ];return NULL ; }
Overall, replaced call to locate_object_entry_hash() with a call to kh_get_sha1(). Okay.
Quoted 8 lines
builtin/pack-objects.c +3
-3-static int add_object_entry (const unsigned char *sha1,enum object_type type, -const char *name,int exclude) +static int add_object_entry_1 (const unsigned char *sha1,enum object_type type, +uint32_t hash,int exclude,struct packed_git *found_pack, +off_t found_offset) {struct object_entry *entry; -struct packed_git *p, *found_pack =NULL ;
builtin/pack-objects.c static int no_try_delta(const char *path) · line 908
Quoted 10 lines
builtin/pack-objects.c +4
-5-off_t found_offset =0 ; -int ix; -unsigned hash =name_hash (name); +struct packed_git *p; +khiter_t ix; +int hash_ret; - ix = nr_objects ?locate_object_entry_hash (sha1) :-1 ; -if (ix >=0 ) { + ix =kh_put_sha1 (packed_objects, sha1, &hash_ret);
You don't need to call locate_object_entry() to check for collisions because kh_put_sha1() takes care of that?
builtin/pack-objects.c static int no_try_delta(const char *path) · line 911
Quoted 4 lines
builtin/pack-objects.c +2
-1+if (hash_ret ==0 ) {if (exclude) { - entry = objects + object_ix[ix] -1 ; + entry =kh_value (packed_objects, ix);
Superficial change: using kh_value(), because we stripped out the chaining logic.
builtin/pack-objects.c static int add_object_entry(const unsigned char *sha1, enum object_type type, · line 970
Quoted 11 lines
builtin/pack-objects.c +3
-4@@ -966,19 +965,30 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type, entry->in_pack_offset = found_offset; } -if (object_ix_hashsz *3 <= nr_objects *4 ) -rehash_objects (); -else - object_ix[-1 - ix] = nr_objects; +kh_value (packed_objects, ix) = entry; +kh_key (packed_objects, ix) = entry->idx.sha1; + objects[nr_objects++] = entry;
Wait, what? Why didn't you use kh_put_sha1()?
I didn't look very carefully, but the patch seems to be okay overall. On the issue of which hashtable replacement to use (why khash, and not something else?), I briefly looked at linux.git's linux/hashtable.h and git.git's hash.h; both of them are chaining hashes. From a brief look at khash.h, it seems to be somewhat less naive and sane: my only concern is that it is written entirely in using CPP macros which is a great for syntax/performance, but not-so-great for debugging. I don't know if there's a better off-the-shelf implementation out there, but I haven't been looking for one either. By the way, it's MIT license authored by an anonymous person (sources at:
https://github.com/attractivechaos/klib/blob/master/khash.h), but I don't know if that's a problem.
Thanks.
PATCH 5/16 revision: allow setting custom limiter function
In reply to Vicent MartiThis commit enables users of struct rev_info to peform custom limiting during a revision walk (i.e. get_revision).
If the field include_check has been set to a callback, this callback will be issued once for each commit before it is added to the "pending" list of the revwalk. If the include check returns 0, the commit will be marked as added but won't be pushed to the pending list, effectively limiting the walk.
--- revision.c | 5 +++++ revision.h | 2 ++ 2 files changed, 7 insertions(+)
revision.c +5 -0
@@ -777,8 +777,13 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,if (commit->object.flags &ADDED )return 0 ; + commit->object.flags |=ADDED ; +if (revs->include_check && + !revs->include_check (commit, revs->include_check_data)) +return 0 ; +/* * If the commit is uninteresting, don't try to * prune parents - we want the maximal uninteresting
revision.h +2 -0
@@ -162,6 +162,8 @@ struct rev_info {unsigned long min_age;int min_parents;int max_parents; +int (*include_check)(struct commit *,void *); +void *include_check_data;/* diff info for patches and for paths limiting */ struct diff_options diffopt;
Signature · 1 line
1.7.9.5
PATCH 7/16 compat: add endinanness helpers
In reply to Vicent MartiThe POSIX standard doesn't currently define a nothll/htonll function pair to perform network-to-host and host-to-network swaps of 64-bit data. These 64-bit swaps are necessary for the on-disk storage of EWAH bitmaps if they are not in native byte order.
--- git-compat-util.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
git-compat-util.h +28 -0
@@ -710,4 +710,32 @@ void warn_on_inaccessible(const char *path);/* Get the passwd entry for the UID of the current process. */ struct passwd *xgetpwuid_self (void ); +#include <endian.h> + +#ifndef __BYTE_ORDER +# if defined(BYTE_ORDER ) && defined(LITTLE_ENDIAN ) && defined(BIG_ENDIAN ) +# define __BYTE_ORDER BYTE_ORDER +# define __LITTLE_ENDIAN LITTLE_ENDIAN +# define __BIG_ENDIAN BIG_ENDIAN +# else +# error "Cannot determine endianness" +# endif +#endif + +#if __BYTE_ORDER == __BIG_ENDIAN +# define ntohll (n) (n) +# define htonll (n) (n) +#elif __BYTE_ORDER == __LITTLE_ENDIAN +# if defined(__GNUC__) && defined(__GLIBC__) +# include <byteswap.h> +# define ntohll (n) bswap_64(n) +# define htonll (n) bswap_64(n) +# else /* GNUC & GLIBC */ +# define ntohll (n) ( (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32) ) +# define htonll (n) ( (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32) ) +# endif /* GNUC & GLIBC */ +#else /* __BYTE_ORDER */ +# error "Can't define htonll or ntohll!" +#endif +#endif
Signature · 1 line
1.7.9.5
Re: [PATCH 07/16] compat: add endinanness helpers
Vicent Marti:
Quoted 1 line
The POSIX standard doesn't currently define a
nothll/htonllfunction pair to perform network-to-host and host-to-network swaps of 64-bit data. These 64-bit swaps are necessary for the on-disk storage of EWAH bitmaps if they are not in native byte order.
endian(3) claims that glibc 2.9+ define be64toh() and htobe64() which should do what you are looking for. The manual page does mention them being named differently across OSes, though, so you may need to be careful with that.
Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
Re: [PATCH 07/16] compat: add endinanness helpers
Quoted 3 lines · Peter Krefting
endian(3) claims that glibc 2.9+ define
be64toh()andhtobe64()which should do what you are looking for. The manual page does mention them being named differently across OSes, though, so you may need to be careful with that.
I'm aware of that, but Git needs to build with glibc 2.7+ (or was it 2.6?), hence the need for this compat layer.
Re: [PATCH 08/16] ewah: compressed bitmap implementation
In reply to Vicent MartiQuoted 10 lines · Vicent Marti
The library is re-licensed under the GPLv2 with the permission of Daniel Lemire, the original author. The source code for the C version can be found on GitHub:
https://github.com/vmg/libewok
The original Java implementation can also be found on GitHub:
Please make sure that all patches are properly signed off.
Quoted 7 lines
Makefile | 6 + ewah/bitmap.c | 229 +++++++++++++++++ ewah/ewah_bitmap.c | 703 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ewah/ewah_io.c | 199 +++++++++++++++ ewah/ewah_rlw.c | 124 +++++++++ ewah/ewok.h | 194 +++++++++++++++ ewah/ewok_rlw.h | 114 +++++++++
This is lovely. A few comments after an initial quick scan-through.
- The code and the headers are well commented, which is good.
- What's __builtin_popcountll() doing there in a presumably generic codepath?
- Two variants of "bitmap" are given different and easy to understand type names (vanilla one is "bitmap", the clever one is "ewah_bitmap"), but at many places, a pointer to ewah_bitmap is simply called "bitmap" or "bitmap_i" without "ewah" anywhere, which waas confusing to read. Especially, the "NAND" operation for bitmap takes two bitmaps, while "OR" takes one bitmap and ewah_bitmap. That is fine as long as the combination is convenient for callers, but I wished the ewah variables be called with "ewah" somewhere in their names.
- I compile with "-Werror -Wdeclaration-after-statement"; some places seem to trigger it.
- Some "extern" declarations in *.c sources were irritating; shouldn't they be declared in *.h file and included?
- There are some instances of "if (condition) stmt;" on a single line; looked irritating.
- "bool" is not a C type we use (and not a particularly good type in C++, either).
That is it for now. I am looking forward to read through the users of the library ;-)
Thanks for working on this.
Re: [PATCH 08/16] ewah: compressed bitmap implementation
Quoted 43 lines · Junio C Hamano
Quoted 10 lines · Vicent Marti
The library is re-licensed under the GPLv2 with the permission of Daniel Lemire, the original author. The source code for the C version can be found on GitHub:
https://github.com/vmg/libewok
The original Java implementation can also be found on GitHub:
Please make sure that all patches are properly signed off.
Quoted 7 lines
Makefile | 6 + ewah/bitmap.c | 229 +++++++++++++++++ ewah/ewah_bitmap.c | 703 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ewah/ewah_io.c | 199 +++++++++++++++ ewah/ewah_rlw.c | 124 +++++++++ ewah/ewok.h | 194 +++++++++++++++ ewah/ewok_rlw.h | 114 +++++++++This is lovely. A few comments after an initial quick scan-through.
- The code and the headers are well commented, which is good.
- What's
__builtin_popcountll()doing there in a presumably generic codepath?- Two variants of "bitmap" are given different and easy to understand type names (vanilla one is "bitmap", the clever one is "
ewah_bitmap"), but at many places, a pointer toewah_bitmapis simply called "bitmap" or "bitmap_i" without "ewah" anywhere, which waas confusing to read. Especially, the "NAND" operation for bitmap takes two bitmaps, while "OR" takes one bitmap andewah_bitmap. That is fine as long as the combination is convenient for callers, but I wished the ewah variables be called with "ewah" somewhere in their names.- I compile with "-Werror -Wdeclaration-after-statement"; some places seem to trigger it.
Quoted 8 lines
- Some "extern" declarations in *.c sources were irritating; shouldn't they be declared in *.h file and included?
- There are some instances of "if (condition) stmt;" on a single line; looked irritating.
- "bool" is not a C type we use (and not a particularly good type in C++, either).
One more.
- Use of unnecessary float (e.g. "oldval *= 1.5") were moderately annoying.
Quoted 4 lines
That is it for now. I am looking forward to read through the users of the library ;-)
Thanks for working on this.
Re: [PATCH 08/16] ewah: compressed bitmap implementation
In reply to Vicent MartiQuoted 2 lines · Vicent Marti
The library is re-licensed under the GPLv2 with the permission of Daniel Lemire, the original author.
This says "GPLv2", but the license blurbs all say "or (at your option) any later version". IANAL, does this cause any problems? If so, can they be GPLv2-only instead?
Quoted 7 lines
Makefile | 6 + ewah/bitmap.c | 229 +++++++++++++++++ ewah/ewah_bitmap.c | 703 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ewah/ewah_io.c | 199 +++++++++++++++ ewah/ewah_rlw.c | 124 +++++++++ ewah/ewok.h | 194 +++++++++++++++ ewah/ewok_rlw.h | 114 +++++++++
Can we have a Documentation/technical/api-ewah.txt?
(Maybe if you insert all the comments I ask for in the below, it's not necessary, but it would still be nice to have some central place where the formats are documented.)
[...]
Quoted 5 lines
ewah/bitmap.c new file +5
-0+struct ewah_bitmap *bitmap_to_ewah (struct bitmap *bitmap) +{ +struct ewah_bitmap *ewah =ewah_new (); +size_t i, running_empty_words =0 ; +eword_t last_word =0 ;
ewah/bitmap.c line 84
Quoted 10 lines
ewah/bitmap.c new file +10
-0+ +for (i =0 ; i < bitmap->word_alloc; ++i) { +if (bitmap->words[i] ==0 ) { + running_empty_words++; +continue ; + } + +if (last_word !=0 ) { +ewah_add (ewah, last_word); + }
There are a lot of "noisy" braces -- like in this instance -- if you apply the git style to the files in ewah/. I assume we'll give the directory its own style, so that it should always use braces even on one-line blocks.
[...]
Quoted 6 lines
ewah/bitmap.c new file +6
-0+ewah_add (ewah, last_word); +return ewah; +} + +struct bitmap *ewah_to_bitmap (struct ewah_bitmap *ewah) +{
ewah/bitmap.c line 109
Quoted 10 lines
ewah/bitmap.c new file +10
-0+struct bitmap *bitmap =bitmap_new (); +struct ewah_iterator it; +eword_t blowup; +size_t i =0 ; + +ewah_iterator_init (&it, ewah); + +while (ewah_iterator_next (&blowup, &it)) { +if (i >= bitmap->word_alloc) { + bitmap->word_alloc *=1.5 ;
Any reason that this uses a scale factor of 1.5, while the bitmap_set operation above uses 2?
Quoted 3 lines
ewah/bitmap.c new file +3
-0+ bitmap->words =ewah_realloc ( + bitmap->words, bitmap->word_alloc *sizeof (eword_t)); + }
[...]
Quoted 3 lines
ewah/bitmap.c new file +3
-0+ +void bitmap_each_bit (struct bitmap *self,ewah_callback callback,void *data) +{
[...]
ewah/bitmap.c line 172
Quoted 5 lines
ewah/bitmap.c new file +5
-0+for (offset =0 ; offset <BITS_IN_WORD ; ++offset) { +if ((word >> offset) ==0 ) +break ; + + offset +=__builtin_ctzll (word >> offset);
Here and in the rest, you use __builtin_* within the code. This needs to be either in a separate helper that reimplements the function in terms of C if it is not available (i.e. you don't use GCC). (Alternatively, the whole series could be conditional on some HAVE_GCC_BUILTINS macro. I'd think that would be a bad tradeoff though.)
Quoted 6 lines
ewah/bitmap.c new file +6
-0+callback (pos + offset, data); + } + pos +=BITS_IN_WORD ; + } + } +}
[...]
Quoted 1 line
ewah/ewah_bitmap.c +0
-0
[...]
ewah/ewah_bitmap.c line 317
Quoted 7 lines
ewah/ewah_bitmap.c +7
-0+void ewah_free (struct ewah_bitmap *bitmap) +{ +if (bitmap->alloc_size) +free (bitmap->buffer); + +free (bitmap); +}
Maybe first if (!bitmap) return, so that it behaves like other free()s?
Quoted 1 line
ewah/ewah_io.c +0
-0
[...]
ewah/ewah_io.c line 32
Quoted 6 lines
ewah/ewah_io.c +6
-0+int ewah_serialize_native (struct ewah_bitmap *self,int fd) +{ +uint32_t write32; +size_t to_write = self->buffer_size *8 ; + +/* 32 bit -- bit size fr the map */
You cut&pasted the typo ("for") throughout the file :-)
[...]
ewah/ewah_io.c line 43
Quoted 7 lines
ewah/ewah_io.c +7
-0+/** 32 bit -- number of compressed 64-bit words */ + write32 = (uint32_t )self->buffer_size; +if (write (fd, &write32,4 ) !=4 ) +return -1 ; + +if (write (fd, self->buffer, to_write) != to_write) +return -1 ;
Shouldn't you use our neat write_in_full() and read_in_full() helpers, throughout the file?
[...]
Quoted 1 line
ewah/ewok.h +0
-0
[...]
ewah/ewok.h line 21
Quoted 2 lines
ewah/ewok.h +2
-0+#ifndef __EWOK_BITMAP_C__ +#define __EWOK_BITMAP_C__
_H_?
ewah/ewok.h line 34
Quoted 9 lines
ewah/ewok.h +9
-0+#ifndef ewah_malloc +# define ewah_malloc malloc +#endif +#ifndef ewah_realloc +# define ewah_realloc realloc +#endif +#ifndef ewah_calloc +# define ewah_calloc calloc +#endif
I see you later #define them to the corresponding x*alloc version in pack-bitmap.h. Good.
ewah/ewok.h line 36
Quoted 2 lines
ewah/ewok.h +2
-0+ +typedef uint64_t eword_t ;
I assume this isn't ifdef'd to help 32bit platforms because the on-disk format depends on it?
Quoted 4 lines
ewah/ewok.h +4
-0+#define BITS_IN_WORD (sizeof(eword_t) * 8) + +struct ewah_bitmap { +eword_t *buffer;
ewah/ewok.h line 50
Quoted 10 lines
ewah/ewok.h +10
-0+size_t buffer_size; +size_t alloc_size; +size_t bit_size; +eword_t *rlw; +}; + +typedef void (*ewah_callback )(size_t pos,void *); + +struct ewah_bitmap *ewah_pool_new (void ); +void ewah_pool_free (struct ewah_bitmap *bitmap);
How do the pool versions differ from the non-pool versions below? I would have expected a memory pool argument somewhere.
Quoted 13 lines
ewah/ewok.h +13
-0+ +/** +* Allocate a new EWAH Compressed bitmap +*/ +struct ewah_bitmap *ewah_new (void ); + +/** +* Clear all the bits in the bitmap. Does not free or resize +* memory. +*/ +void ewah_clear (struct ewah_bitmap *bitmap); + +/**
ewah/ewok.h line 73
Quoted 10 lines
ewah/ewok.h +10
-0+* Free all the memory of the bitmap +*/ +void ewah_free (struct ewah_bitmap *bitmap); + +int ewah_serialize (struct ewah_bitmap *self,int fd); +int ewah_serialize_native (struct ewah_bitmap *self,int fd); + +int ewah_deserialize (struct ewah_bitmap *self,int fd); +int ewah_read_mmap (struct ewah_bitmap *self,void *map,size_t len); +int ewah_read_mmap_native (struct ewah_bitmap *self,void *map,size_t len);
The whole file is so neatly commented, and then you skimp on these? :-)
In particular, it would be nice to have a comment here on what the _native distinction means, and what (if any) the constraints are if you want to use _mmap. Also, if you read or deserialize, does the 'self' have to be initialized first?
[...]
Quoted 9 lines
+/**
+ * Set a given bit on the bitmap.
+ *
+ * The bit at positionposwill be set to true. Because of the
+ * way that the bitmap is compressed, a set bit cannot be unset
+ * later on.
+ *
+ * Furthermore, since the bitmap uses streaming compression, bits
+ * can only set incrementally.
I'm not a native speaker, but does 'incrementally' also mean 'in order of increasing indexes'? That's what the example seems to say.
Quoted 10 lines
+ *
+ * E.g.
+ *ewah_set(bitmap, 1); // ok
+ *ewah_set(bitmap, 76); // ok
+ *ewah_set(bitmap, 77); // ok
+ *ewah_set(bitmap, 8712800127); // ok
+ *ewah_set(bitmap, 25); // failed, assert raised
+ */ewah/ewok.h +2
-0+void ewah_set (struct ewah_bitmap *self,size_t i); +
[...]
Quoted 1 line
+struct
ewah_bitmap*bitmap_to_ewah(struct bitmap *bitmap);
Style (around the *).
ewah/ewok.h line 189
Quoted 4 lines
ewah/ewok.h +4
-0+struct bitmap *ewah_to_bitmap (struct ewah_bitmap *ewah); + +void bitmap_and_not_inplace (struct bitmap *self,struct bitmap *other); +void bitmap_or_inplace (struct bitmap *self,struct ewah_bitmap *other);
Why does one of them take an ewah_bitmap for 'other', but the other takes a straight 'bitmap'?
Quoted 11 lines
ewah/ewok.h +5
-0+ +void bitmap_each_bit (struct bitmap *self,ewah_callback callback,void *data); +size_t bitmap_popcount (struct bitmap *self); + +#endif ewah/ewok_rlw.h new file +0
-0@@ -0,0 +1,114 @@
[...]
ewah/ewok_rlw.h line 24
Quoted 2 lines
ewah/ewok_rlw.h new file +2
-0+#define RLW_RUNNING_BITS (sizeof(eword_t) * 4) +#define RLW_LITERAL_BITS (sizeof(eword_t) * 8 - 1 - RLW_RUNNING_BITS)
It would be nice to have some minimal documentation of the word format here (or in ewok.h), in particular because you snip off 1 bit here for a reason that is not immediately obvious.
ewah/ewok_rlw.h line 31
Quoted 6 lines
ewah/ewok_rlw.h new file +6
-0+#define RLW_LARGEST_RUNNING_COUNT (((eword_t)1 << RLW_RUNNING_BITS) - 1) +#define RLW_LARGEST_LITERAL_COUNT (((eword_t)1 << RLW_LITERAL_BITS) - 1) + +#define RLW_LARGEST_RUNNING_COUNT_SHIFT (RLW_LARGEST_RUNNING_COUNT << 1) + +#define RLW_RUNNING_LEN_PLUS_BIT (((eword_t)1 << (RLW_RUNNING_BITS + 1)) - 1)
This one is doubly strange. The name claims it's a bit(?), but the definition (if you expand the preceding macros) effectively makes it 0x1ffffffff, i.e., a mask for RLW_RUNNING_BITS+1 number of bits.
ewah/ewok_rlw.h line 54
Quoted 8 lines
ewah/ewok_rlw.h new file +8
-0+static inline void rlw_xor_run_bit (eword_t *word) +{ +if (*word &1 ) { + *word &= (eword_t)(~1 ); + }else { + *word |= (eword_t )1 ; + } +}
Why is this called xor? Looks a lot like a negation to me.
Quoted 4 lines
ewah/ewok_rlw.h new file +4
-0+static bool rlw_get_run_bit (const eword_t *word) +{ +return *word & (eword_t )1 ; +}
[...]
Quoted 12 lines
ewah/ewok_rlw.h new file +11
-0+static inline void rlw_set_running_len (eword_t *word,eword_t l) +{ + *word |=RLW_LARGEST_RUNNING_COUNT_SHIFT ; + *word &= (l <<1 ) | (~RLW_LARGEST_RUNNING_COUNT_SHIFT ); +} + +static inline void rlw_set_literal_words (eword_t *word,eword_t l) +{ + *word |= ~RLW_RUNNING_LEN_PLUS_BIT ; + *word &= (l << (RLW_RUNNING_BITS +1 )) |RLW_RUNNING_LEN_PLUS_BIT ; +}
Quoted 1 line
From these I gather that the layout is, LSB first:
1 bit: bit that will be repeated
32 bits: length of the run
31 bits: number of literal words to be read after the run
Is that correct? This took some figuring out for me, please add a comment.
And then from there I would extrapolate that the data format requires one such "specifier" word in between of chunks of stuff, but it's not clear how exactly.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chPATCH 9/16 documentation: add documentation for the bitmap format
In reply to Vicent MartiThis is the technical documentation and design rationale for the new Bitmap v2 on-disk format.
--- Documentation/technical/bitmap-format.txt | 235 +++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 Documentation/technical/bitmap-format.txt
Documentation/technical/bitmap-format.txt new file +235 -0
@@ -0,0 +1,235 @@ +GIT bitmap v2 format & rationale +================================ + + - A header appears at the beginning, using the same format + as JGit's original bitmap indexes. + + 4-byte signature: {'B', 'I', 'T', 'M'} + + 2-byte version number (network byte order) + The current implementation only supports version 2 + of the bitmap index. The rationale for this is explained + in this document. + + 2-byte flags (network byte order) + + The folowing flags are supported: + + - BITMAP_OPT_FULL_DAG (0x1) REQUIRED + This flag must always be present. It implies that the bitmap + index has been generated for a packfile with full closure + (i.e. where every single object in the packfile can find + its parent links inside the same packfile). This is a + requirement for the bitmap index format, also present in JGit, + that greatly reduces the complexity of the implementation. + + - BITMAP_OPT_LE_BITMAPS (0x2) + If present, this implies that that the EWAH bitmaps in this + index has been serialized to disk in little-endian byte order. + Note that this only applies to the actual bitmaps, not to the + Git data structures in the index, which are always in Network + Byte order as it's costumary. + + - BITMAP_OPT_BE_BITMAPS (0x4) + If present, this implies that the EWAH bitmaps have been serialized + using big-endian byte order (NWO). If the flag is missing, **the + default is to assume that the bitmaps are in big-endian**. + + - BITMAP_OPT_HASH_CACHE (0x8) + If present, a hash cache for finding delta bases will be available + right after the header block in this index. See the following + section for details. + + 4-byte entry count (network byte order) + + The total count of entries (bitmapped commits) in this bitmap index. + + 20-byte checksum + + The SHA1 checksum of the pack this bitmap index belongs to. + + - An OPTIONAL delta cache follows the header. + + The cache is formed by `n` 4-byte hashes in a row, where `n` is + the amount of objects in the indexed packfile. Note that this amount + is the **total number of objects** and is not related to the + number of commits that have been selected and indexed in the + bitmap index. + + The hashes are stored in Network Byte Order and they are the same + values generated by a normal revision walk during the `pack-objects` + phase. + + The `n`nth hash in the cache is the name hash for the `n`th object + in the index for the indexed packfile. + + [RATIONALE]: + + The bitmap index allows us to skip the Counting Objects phase + during `pack-objects` and yield all the OIDs that would be reachable + ("WANTS") when generating the pack. + + This optimization, however, means that we're adding objects to the + packfile straight from the packfile index, and hence we are lacking + path information for the objects that would normally be generated + during the "Counting Objects" phase. + + This path information for each object is hashed and used as a very + effective way to find good delta bases when compressing the packfile; + without these hashes, the resulting packfiles are much less optimal. + + By storing all the hashes in a cache together with the bitmapsin + the bitmap index, we can yield not only the SHA1 of all the reachable + objects, but also their hashes, and allow Git to be much smarter when + finding delta bases for packing. + + If the delta cache is not available, the bitmap index will obviously + be smaller in disk, but the packfiles generated using this index will + be between 20% and 30% bigger, because of the lack of name/path + information when finding delta bases. + + - 4 EWAH bitmaps that act as type indexes + + Type indexes are serialized after the hash cache in the shape + of four EWAH bitmaps stored consecutively (see Appendix A for + the serialization format of an EWAH bitmap). + + There is a bitmap for each Git object type, stored in the following + order: + + - Commits + - Trees + - Blobs + - Tags + + In each bitmap, the `n`th bit is set to true if the `n`th object + in the packfile index is of that type. + + The obvious consequence is that the XOR of all 4 bitmaps will result + in a full set (all bits sets), and the AND of all 4 bitmaps will + result in an empty bitmap (no bits set). + + - N EWAH bitmaps, one for each indexed commit + + Where `N` is the total amount of entries in this bitmap index. + See Appendix A for the serialization format of an EWAH bitmap. + + - An entry index with `N` entries for the indexed commits + + Index entries are stored consecutively, and each entry has the + following format: + + - 20-byte SHA1 + The SHA1 of the commit that this bitmap indexes + + - 4-byte offset (Network Byte Order) + The offset **from the beginning of the file** where the + bitmap for this commit is stored. + + - 1-byte XOR-offset + The xor offset used to compress this bitmap. For an entry + in position `x`, a XOR offset of `y` means that the actual + bitmap representing for this commit is composed by XORing the + bitmap for this entry with the bitmap in entry `x-y` (i.e. + the bitmap `y` entries before this one). + + Note that this compression can be recursive. In order to + XOR this entry with a previous one, the previous entry needs + to be decompressed first, and so on. + + The hard-limit for this offset is 160 (an entry can only be + xor'ed against one of the 160 entries preceding it). This + number is always positivea, and hence entries are always xor'ed + with **previous** bitmaps, not bitmaps that will come afterwards + in the index. + + - 1-byte flags for this bitmap + At the moment the only available flag is `0x1`, which hints + that this bitmap can be re-used when rebuilding bitmap indexes + for the repository. + + - 2 bytes of RESERVED data (used right now for better packing). + +== Rationale for changes from the Bitmap Format v1 + +- Serialized EWAH bitmaps can be stored in Little-Endian byte order, + if defined by the BITMAP_OPT_LE_BITMAPS flag in the header. + + The original JGit implementation stored bitmaps in Big-Endian byte + order (NWO) because it was unable to `mmap` the serialized format, + and hence always required a full parse of the bitmap index to memory, + where the BE->LE conversion could be performed. + + This full parse, however, requires prohibitive loading times in LE + machines (i.e. all modern server hardware): a repository like + `torvalds/linux` can have about 8mb of bitmap indexes, resulting + in roughly 400ms of parse time. + + This is not an issue in JGit, which is capable of serving repositories + from a single-process daemon running on the JVM, but `git-daemon` in + git has been implemented with a process-based design (a new + `pack-objects` is spawned for each request), and the boot times + of parsing the bitmap index every time `pack-objects` is spawned can + seriously slow down requests (particularly for small fetches, where we'd + spend about 1.5s booting up and 300ms performing the Counting Objects + phase). + + By storing the bitmaps in Little-Endian, we're able to `mmap` their + compressed data straight in memory without parsing it beforehand, and + since most queries don't require accessing all the serialized bitmaps, + we'll only page in the minimal amount of bitmaps necessary to perform + the reachability analysis as they are accessed. + +- An index of all the bitmapped commits is written at the end of the packfile, + instead of interpersed with the serialized bitmaps in the middle of the + file. + + Again, the old design implied a full parse of the whole bitmap index + (which JGit can afford because its daemon is single-process), but it made + impossible `mmaping` the bitmap index file and accessing only the parts + required to actually solve the query. + + With an index at the end of the file, we can load only this index in memory, + allowing for very efficient access to all the available bitmaps lazily (we + have their offsets in the mmaped file). + +- The ordering of the objects in each bitmap has changed from + packfile-order (the nth bit in the bitmap is the nth object in the + packfile) to index-order (the nth bit in the bitmap is the nth object + in the INDEX of the packfile). + + There is not a noticeable performance difference when actually converting + from bitmap position to SHA1 and from SHA1 to bitmap position, but when + using packfile ordering like JGit does, queries need to go through the + reverse index (pack-revindex.c). + + Generating this reverse index at runtime is **not** free (around 900ms + generation time for a repository like `torvalds/linux`), and once again, + this generation time needs to happen every time `pack-objects` is + spawned. + + With index-ordering, the only requirement for SHA1 -> Bitmap conversions + is the packfile index, which we essentially load for free. + + +== Appendix A: Serialization format for an EWAH bitmap + +Ewah bitmaps are serialized in the protocol as the JAVAEWAH +library, making them backwards compatible with the JGit +implementation: + + - 4-byte number of bits of the resulting UNCOMPRESSED bitmap + + - 4-byte number of words of the COMPRESSED bitmap, when stored + + - N x 8-byte words, as specified by the previous field + + This is the actual content of the compressed bitmap. + + - 4-byte position of the current RLW for the compressed + bitmap + +Note that the byte order for this serialization is not defined by +default. The byte order for all the content in a serialized EWAH +bitmap can be known by the byte order flags in the header of the +bitmap index file.
Signature · 1 line
1.7.9.5
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 2 lines · Vicent Marti
This is the technical documentation and design rationale for the new Bitmap v2 on-disk format.
Hrmpf, that's what I get for reading the series in order...
Documentation/technical/bitmap-format.txt line 16
Quoted 1 line
Documentation/technical/bitmap-format.txt new file +1
-0+ The folowing flags are supported:
^^
typos marked by ^
Documentation/technical/bitmap-format.txt line 81
Quoted 1 line
Documentation/technical/bitmap-format.txt new file +1
-0+ By storing all the hashes in a cache together with the bitmapsin
^^
Documentation/technical/bitmap-format.txt line 109
Quoted 2 lines
Documentation/technical/bitmap-format.txt new file +2
-0+ The obvious consequence is that the XOR of all 4 bitmaps will result + in a full set (all bits sets), and the AND of all 4 bitmaps will
^
Quoted 4 lines
Documentation/technical/bitmap-format.txt new file +4
-0+ - 1-byte XOR-offset + The xor offset used to compress this bitmap. For an entry + in position `x`, a XOR offset of `y` means that the actual + bitmap representing for this commit is composed by XORing the
Documentation/technical/bitmap-format.txt line 142
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ bitmap for this entry with the bitmap in entry `x-y` (i.e. + the bitmap `y` entries before this one). + + Note that this compression can be recursive. In order to + XOR this entry with a previous one, the previous entry needs + to be decompressed first, and so on. + + The hard-limit for this offset is 160 (an entry can only be + xor'ed against one of the 160 entries preceding it). This + number is always positivea, and hence entries are always xor'ed
^
Documentation/technical/bitmap-format.txt line 144
Quoted 2 lines
Documentation/technical/bitmap-format.txt new file +2
-0+ with **previous** bitmaps, not bitmaps that will come afterwards + in the index.
Clever. Why 160 though?
Documentation/technical/bitmap-format.txt line 151
Quoted 1 line
Documentation/technical/bitmap-format.txt new file +1
-0+ - 2 bytes of RESERVED data (used right now for better packing).
What do they mean?
Documentation/technical/bitmap-format.txt line 194
Quoted 3 lines
Documentation/technical/bitmap-format.txt new file +3
-0+ With an index at the end of the file, we can load only this index in memory, + allowing for very efficient access to all the available bitmaps lazily (we + have their offsets in the mmaped file).
Is there anything preventing you from mmap()ing the index also?
Quoted 11 lines
+== Appendix A: Serialization format for an EWAH bitmap
Documentation/technical/bitmap-format.txt new file +10
-0+ +Ewah bitmaps are serialized in the protocol as the JAVAEWAH +library, making them backwards compatible with the JGit +implementation: + + - 4-byte number of bits of the resulting UNCOMPRESSED bitmap + + - 4-byte number of words of the COMPRESSED bitmap, when stored + + - N x 8-byte words, as specified by the previous field
Documentation/technical/bitmap-format.txt line 235
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ + This is the actual content of the compressed bitmap. + + - 4-byte position of the current RLW for the compressed + bitmap + +Note that the byte order for this serialization is not defined by +default. The byte order for all the content in a serialized EWAH +bitmap can be known by the byte order flags in the header of the +bitmap index file.
Please document the RLW format here.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 34 lines · Thomas Rast
Quoted 3 lines
This is the technical documentation and design rationale for the new Bitmap v2 on-disk format.
Hrmpf, that's what I get for reading the series in order...
Quoted 1 line
+ The folowing flags are supported:
^^typos marked by ^
Quoted 1 line
+ By storing all the hashes in a cache together with the bitmapsin
^^Documentation/technical/bitmap-format.txt line 109
Quoted 2 lines
Documentation/technical/bitmap-format.txt new file +2
-0+ The obvious consequence is that the XOR of all 4 bitmaps will result + in a full set (all bits sets), and the AND of all 4 bitmaps will^Quoted 4 lines
Documentation/technical/bitmap-format.txt new file +4
-0+ - 1-byte XOR-offset + The xor offset used to compress this bitmap. For an entry + in position `x`, a XOR offset of `y` means that the actual + bitmap representing for this commit is composed by XORing theDocumentation/technical/bitmap-format.txt line 142
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ bitmap for this entry with the bitmap in entry `x-y` (i.e. + the bitmap `y` entries before this one). + + Note that this compression can be recursive. In order to + XOR this entry with a previous one, the previous entry needs + to be decompressed first, and so on. + + The hard-limit for this offset is 160 (an entry can only be + xor'ed against one of the 160 entries preceding it). This + number is always positivea, and hence entries are always xor'ed^
Quoted 4 lines
Documentation/technical/bitmap-format.txt line 144
Quoted 2 lines
Documentation/technical/bitmap-format.txt new file +2
-0+ with **previous** bitmaps, not bitmaps that will come afterwards + in the index.Clever. Why 160 though?
JGit implementation detail. It's the equivalent of the delta-window in pack-objects for example.
HINT HINT: in practice, JGit only looks 16 positions behind to find deltas, and we do the same. So the practical limit is 16. harhar
Quoted 10 lines
Quoted 2 lines
+ - 2 bytes of RESERVED data (used right now for better packing).
What do they mean?
Documentation/technical/bitmap-format.txt line 194
Quoted 3 lines
Documentation/technical/bitmap-format.txt new file +3
-0+ With an index at the end of the file, we can load only this index in memory, + allowing for very efficient access to all the available bitmaps lazily (we + have their offsets in the mmaped file).Is there anything preventing you from mmap()ing the index also?
Yeah, this format allows you to easily do a SHA1 bsearch with custom step to lookup entries on the bitmap index, except for the fact that the index is not sorted by SHA1, so you'd need a linear search instead. :)
I decided against it because during most complex invocations of pack-objects, we perform a couple thousand commit lookups to see if they have a bitmap in the index, so it makes a lot of sense to load the index tightly in a hash table before hand (which takes very little time, to be fair). We more-than-make up for the loading time by having much much faster lookups. I felt it was the right tradeoff (JGit does the same, but in their case, because they cannot mmap. :p)
Quoted 15 lines
Quoted 15 lines
+== Appendix A: Serialization format for an EWAH bitmap
Documentation/technical/bitmap-format.txt new file +14
-0+ +Ewah bitmaps are serialized in the protocol as the JAVAEWAH +library, making them backwards compatible with the JGit +implementation: + + - 4-byte number of bits of the resulting UNCOMPRESSED bitmap + + - 4-byte number of words of the COMPRESSED bitmap, when stored + + - N x 8-byte words, as specified by the previous field + + This is the actual content of the compressed bitmap. + + - 4-byte position of the current RLW for the compressed
Quoted 8 lines
Documentation/technical/bitmap-format.txt line 235
Quoted 6 lines
Documentation/technical/bitmap-format.txt new file +6
-0+ bitmap + +Note that the byte order for this serialization is not defined by +default. The byte order for all the content in a serialized EWAH +bitmap can be known by the byte order flags in the header of the +bitmap index file.Please document the RLW format here.
Har har. I was going to comment on your review of the Ewah patchset, but might as well do it here: the only thing I know about Ewah bitmaps is that they work. And I know this because I did extensive fuzz testing of my C port. Unfortunately, the original Java code I ported from has 0 comments, so any documentation here would have to be reverse-engineered.
Personally, I'd lean towards considering Ewah an external dependency (black box); the headers for the library are commented accordingly, clearly explaining the interfaces while hiding implementation details. Of course, you're welcome to help me reverse engineer the implementation, but I'm not sure this would be of much value. It'd be better to make sure it passes the extensive test suite of the Java version, and assume that Mr Lemire designed a sound format for the bitmaps.
Swiss kisses,
vmg
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Vicent MartiQuoted 39 lines · Vicent Marti
This is the technical documentation and design rationale for the new Bitmap v2 on-disk format.
--- Documentation/technical/bitmap-format.txt | 235 +++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 Documentation/technical/bitmap-format.txtDocumentation/technical/bitmap-format.txt new file +26
-0@@ -0,0 +1,235 @@ +GIT bitmap v2 format & rationale +================================ + + - A header appears at the beginning, using the same format + as JGit's original bitmap indexes. + + 4-byte signature: {'B', 'I', 'T', 'M'} + + 2-byte version number (network byte order) + The current implementation only supports version 2 + of the bitmap index. The rationale for this is explained + in this document. + + 2-byte flags (network byte order) + + The folowing flags are supported: + + - BITMAP_OPT_FULL_DAG (0x1) REQUIRED + This flag must always be present. It implies that the bitmap + index has been generated for a packfile with full closure + (i.e. where every single object in the packfile can find + its parent links inside the same packfile). This is a + requirement for the bitmap index format, also present in JGit, + that greatly reduces the complexity of the implementation. + + - BITMAP_OPT_LE_BITMAPS (0x2)
Documentation/technical/bitmap-format.txt line 36
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ If present, this implies that that the EWAH bitmaps in this + index has been serialized to disk in little-endian byte order. + Note that this only applies to the actual bitmaps, not to the + Git data structures in the index, which are always in Network + Byte order as it's costumary. + + - BITMAP_OPT_BE_BITMAPS (0x4) + If present, this implies that the EWAH bitmaps have been serialized + using big-endian byte order (NWO). If the flag is missing, **the + default is to assume that the bitmaps are in big-endian**.
I very much hate seeing a file format that is supposed to be portable that supports both big-endian and little-endian encoding. Such a specification forces everyone to implement two code paths to handle reading data from the file, on the off-chance they are on the wrong platform. Or it forces one platform to be unable to use the file. In which case a repository may want to build two files, one for each platform, but you blocked that off by allowing only one file.
What is wrong with picking one encoding and sticking to it? The .idx file and the dircache use big-endian format. Why not just use big-endian here too and convert words on demand as they are accessed from the mmap region? That is what the .idx format does when accessing an offset.
Quoted 4 lines
Documentation/technical/bitmap-format.txt new file +4
-0+ - BITMAP_OPT_HASH_CACHE (0x8) + If present, a hash cache for finding delta bases will be available + right after the header block in this index. See the following + section for details.
Documentation/technical/bitmap-format.txt line 51
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ + 4-byte entry count (network byte order) + + The total count of entries (bitmapped commits) in this bitmap index. + + 20-byte checksum + + The SHA1 checksum of the pack this bitmap index belongs to. + + - An OPTIONAL delta cache follows the header.
Some may find the name "delta cache" confusing as it does not cache deltas of objects. May I suggest "path hash cache" as an alternative name?
Documentation/technical/bitmap-format.txt line 61
Quoted 9 lines
Documentation/technical/bitmap-format.txt new file +9
-0+ The cache is formed by `n` 4-byte hashes in a row, where `n` is + the amount of objects in the indexed packfile. Note that this amount + is the **total number of objects** and is not related to the + number of commits that have been selected and indexed in the + bitmap index. + + The hashes are stored in Network Byte Order and they are the same + values generated by a normal revision walk during the `pack-objects` + phase.
I find it interesting this is network byte order and not big-endian or little-endian based on the flag in the header.
Quoted 17 lines
Documentation/technical/bitmap-format.txt new file +17
-0+ The `n`nth hash in the cache is the name hash for the `n`th object + in the index for the indexed packfile. + + [RATIONALE]: + + The bitmap index allows us to skip the Counting Objects phase + during `pack-objects` and yield all the OIDs that would be reachable + ("WANTS") when generating the pack. + + This optimization, however, means that we're adding objects to the + packfile straight from the packfile index, and hence we are lacking + path information for the objects that would normally be generated + during the "Counting Objects" phase. + + This path information for each object is hashed and used as a very + effective way to find good delta bases when compressing the packfile; + without these hashes, the resulting packfiles are much less optimal.
Documentation/technical/bitmap-format.txt line 89
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ + By storing all the hashes in a cache together with the bitmapsin + the bitmap index, we can yield not only the SHA1 of all the reachable + objects, but also their hashes, and allow Git to be much smarter when + finding delta bases for packing. + + If the delta cache is not available, the bitmap index will obviously + be smaller in disk, but the packfiles generated using this index will + be between 20% and 30% bigger, because of the lack of name/path + information when finding delta bases.
JGit does not encode this because we were afraid of freezing the hash function into the file format. Indeed we are not certain JGit even uses the same path hash function as C Git does, because C Git's implementation is covered by the GPL and JGit prefers to license its work under BSD.
If the path hash is going to become part of the format, the algorithm for computing the hash should also be specified in the format so that non-GPL implementations have an opportunity to be compatible.
One way we side-stepped the size inflation problem in JGit was to only use the bitmap index information when sending data on the wire to a client. Here delta reuse plays a significant factor in building the pack, and we don't have to be as accurate on matching deltas. During the equivalent of git repack bitmaps are not used, allowing the traditional graph enumeration algorithm to generate path hash information.
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ - 4 EWAH bitmaps that act as type indexes + + Type indexes are serialized after the hash cache in the shape + of four EWAH bitmaps stored consecutively (see Appendix A for + the serialization format of an EWAH bitmap). + + There is a bitmap for each Git object type, stored in the following + order: + + - Commits
Documentation/technical/bitmap-format.txt line 110
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ - Trees + - Blobs + - Tags + + In each bitmap, the `n`th bit is set to true if the `n`th object + in the packfile index is of that type. + + The obvious consequence is that the XOR of all 4 bitmaps will result + in a full set (all bits sets), and the AND of all 4 bitmaps will + result in an empty bitmap (no bits set).
Instead of XOR did you mean OR here?
Quoted 6 lines
Documentation/technical/bitmap-format.txt new file +6
-0+ - N EWAH bitmaps, one for each indexed commit + + Where `N` is the total amount of entries in this bitmap index. + See Appendix A for the serialization format of an EWAH bitmap. + + - An entry index with `N` entries for the indexed commits
Documentation/technical/bitmap-format.txt line 127
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ + Index entries are stored consecutively, and each entry has the + following format: + + - 20-byte SHA1 + The SHA1 of the commit that this bitmap indexes + + - 4-byte offset (Network Byte Order) + The offset **from the beginning of the file** where the + bitmap for this commit is stored.
Eh, another network byte order field in a file that also has selective ordering. *sigh*
Quoted 6 lines
Documentation/technical/bitmap-format.txt new file +6
-0+ - 1-byte XOR-offset + The xor offset used to compress this bitmap. For an entry + in position `x`, a XOR offset of `y` means that the actual + bitmap representing for this commit is composed by XORing the + bitmap for this entry with the bitmap in entry `x-y` (i.e. + the bitmap `y` entries before this one).
Documentation/technical/bitmap-format.txt line 144
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ + Note that this compression can be recursive. In order to + XOR this entry with a previous one, the previous entry needs + to be decompressed first, and so on. + + The hard-limit for this offset is 160 (an entry can only be + xor'ed against one of the 160 entries preceding it). This + number is always positivea, and hence entries are always xor'ed + with **previous** bitmaps, not bitmaps that will come afterwards + in the index.
What order are these entries in? Sorted by SHA-1 or random?
Colby found that doing an XOR against the descendant commit yielded very small bitmaps, so JGit tries to XOR-compress bitmaps along common linear slices of history. This is trivial in Linus' kernel tree where there is effectively only one history, but its more relevant with long-running side branches that have release tags that may not have fully merged into "master".
Quoted 6 lines
Documentation/technical/bitmap-format.txt new file +6
-0+ - 1-byte flags for this bitmap + At the moment the only available flag is `0x1`, which hints + that this bitmap can be re-used when rebuilding bitmap indexes + for the repository. + + - 2 bytes of RESERVED data (used right now for better packing).
Documentation/technical/bitmap-format.txt line 161
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ +== Rationale for changes from the Bitmap Format v1 + +- Serialized EWAH bitmaps can be stored in Little-Endian byte order, + if defined by the BITMAP_OPT_LE_BITMAPS flag in the header. + + The original JGit implementation stored bitmaps in Big-Endian byte + order (NWO) because it was unable to `mmap` the serialized format, + and hence always required a full parse of the bitmap index to memory, + where the BE->LE conversion could be performed.
You can mmap a file and convert each word on access if your machine is not using the same byte order. It is not necessary to convert the entire file before using it through a mmap region.
Documentation/technical/bitmap-format.txt line 166
Quoted 4 lines
Documentation/technical/bitmap-format.txt new file +4
-0+ This full parse, however, requires prohibitive loading times in LE + machines (i.e. all modern server hardware): a repository like + `torvalds/linux` can have about 8mb of bitmap indexes, resulting + in roughly 400ms of parse time.
This makes me wonder what the JGit parse time is. It is ugly if we are spending 400ms to load the bitmap index for the kernel repository.
Documentation/technical/bitmap-format.txt line 175
Quoted 8 lines
Documentation/technical/bitmap-format.txt new file +8
-0+ This is not an issue in JGit, which is capable of serving repositories + from a single-process daemon running on the JVM, but `git-daemon` in + git has been implemented with a process-based design (a new + `pack-objects` is spawned for each request), and the boot times + of parsing the bitmap index every time `pack-objects` is spawned can + seriously slow down requests (particularly for small fetches, where we'd + spend about 1.5s booting up and 300ms performing the Counting Objects + phase).
There are other strategies that Git could use to handle request processing at scale. But I guess its reasonable to assume these aren't viable for Git for a number of reasons. E.g. "long tail" access effect that many servers have, where most requests are to a large number of repositories that themselves receive very few requests, an environment that does not lend itself to caching.
Documentation/technical/bitmap-format.txt line 181
Quoted 5 lines
Documentation/technical/bitmap-format.txt new file +5
-0+ By storing the bitmaps in Little-Endian, we're able to `mmap` their + compressed data straight in memory without parsing it beforehand, and + since most queries don't require accessing all the serialized bitmaps, + we'll only page in the minimal amount of bitmaps necessary to perform + the reachability analysis as they are accessed.
FWIW the .idx and .pack file formats mmap the compressed data straight into memory without parsing it beforehand, and do not use little-endian byte order. It is possible to have a single compressed file format definition that is portable to all architectures, and is accessed by mmap, at scale, with reasonable efficiency.
Documentation/technical/bitmap-format.txt line 185
Quoted 3 lines
Documentation/technical/bitmap-format.txt new file +3
-0+- An index of all the bitmapped commits is written at the end of the packfile, + instead of interpersed with the serialized bitmaps in the middle of the + file.
This is probably a mistake in the JGit design. Your approach is slightly more complex, but in general I agree with having a table of the SHA-1s isolated from the bitmaps themselves so that a reader can access specific bitmaps at random without needing to wade through all compressed bitmaps.
I would have proposed putting the table at the start of the file, not the end. The writer making the file can completely serialize the bitmaps into memory before writing them to disk, and thus knows the full layout of the resulting file. If the bitmaps don't fit in RAM at writing time, game over, the optimization of having a very compact representation of the graph is no longer helping you.
Documentation/technical/bitmap-format.txt line 199
Quoted 13 lines
Documentation/technical/bitmap-format.txt new file +13
-0+ Again, the old design implied a full parse of the whole bitmap index + (which JGit can afford because its daemon is single-process), but it made + impossible `mmaping` the bitmap index file and accessing only the parts + required to actually solve the query. + + With an index at the end of the file, we can load only this index in memory, + allowing for very efficient access to all the available bitmaps lazily (we + have their offsets in the mmaped file). + +- The ordering of the objects in each bitmap has changed from + packfile-order (the nth bit in the bitmap is the nth object in the + packfile) to index-order (the nth bit in the bitmap is the nth object + in the INDEX of the packfile).
Did you notice an increase in bitmap size when you did this? Colby tested both orderings and we observed the bitmaps were quantifiably smaller when using the pack file ordering, due to the pack file locality rules and the EWAH compression. Using the pack file ordering was a very conscious design decision.
Documentation/technical/bitmap-format.txt line 209
Quoted 9 lines
Documentation/technical/bitmap-format.txt new file +9
-0+ There is not a noticeable performance difference when actually converting + from bitmap position to SHA1 and from SHA1 to bitmap position, but when + using packfile ordering like JGit does, queries need to go through the + reverse index (pack-revindex.c). + + Generating this reverse index at runtime is **not** free (around 900ms + generation time for a repository like `torvalds/linux`), and once again, + this generation time needs to happen every time `pack-objects` is + spawned.
Did you know the packer needs the reverse index in order to compute the end offset of an object it will copy as-is during delta reuse? How have you avoided making the reverse index?
Again this is why we chose to pin the JGit bitmap on the reverse index being present. It already had to be present to support as-is reuse. Once we knew we had to have that reverse index it was OK to rely on it to get better compression on the bitmaps, and thus make them take up less memory when loaded into a server. Even if you mmap a file you want it to be small so it is more likely to retain in the kernel buffer cache across process invocations.
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 2 lines · Shawn Pearce
I very much hate seeing a file format that is supposed to be portable that supports both big-endian and little-endian encoding.
Well, the bitmap index is not supposed to be portable, as it doesn't get sent over the wire in any situation. Regardless, the format is portable because it supports both encodings and clearly defines which one the current file is using. I think that's a good tradeoff!
Quoted 3 lines
Such a specification forces everyone to implement two code paths to handle reading data from the file, on the off-chance they are on the wrong platform.
Extra code paths have never been an issue in the JGitAbstractFactoryGeneratorOfGit, har har har. Ah. I'm such a funny guy when it comes to Java.
Anyway, I designed this keeping JGit in mind. In this specific case, it doesn't force you to add any new code paths. The endianness changes only affect the serialization format of the bitmaps, which is not part of Git or JGit itself but of the Javaewah/libewok library. The interface for reading on that library has already been wisely abstracted on JGit
(https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexV1.java#L133),
so changing the byte order simply means changing the SimpleDataInput to a LE one.
I agree this is not ideal, or elegant, but I'm having a hard time making an argument for sacrificing objective speed for the sake of subjective "simplicity".
Quoted 1 line
What is wrong with picking one encoding and sticking to it?
It prevents us from making this optimally fast on the machines where it needs to be.
Regardless, I must admit I haven't generated numbers for this in a while (the BE->LE switch is one of the first optimizations I did). I'm going to try to re-implement full NWO loading and see how much slower it is, before I continue arguing for/against it.
If I can get it within a reasonable margin (say, 15%) of the current implementation, I'd definitely be in favor of sticking to only NWO on the whole file. If it's slower than that, well, Git has never compromised on speed, and I don't think there's a point to be made for starting to do that now.
Quoted 10 lines
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ - BITMAP_OPT_HASH_CACHE (0x8) + If present, a hash cache for finding delta bases will be available + right after the header block in this index. See the following + section for details. + + 4-byte entry count (network byte order) + + The total count of entries (bitmapped commits) in this bitmap index. + + 20-byte checksum
Quoted 8 lines
Documentation/technical/bitmap-format.txt line 51
Quoted 4 lines
Documentation/technical/bitmap-format.txt new file +4
-0+ + The SHA1 checksum of the pack this bitmap index belongs to. + + - An OPTIONAL delta cache follows the header.Some may find the name "delta cache" confusing as it does not cache deltas of objects. May I suggest "path hash cache" as an alternative name?
Definitely, this is a typo.
Quoted 10 lines
Documentation/technical/bitmap-format.txt line 61
Quoted 9 lines
Documentation/technical/bitmap-format.txt new file +9
-0+ The cache is formed by `n` 4-byte hashes in a row, where `n` is + the amount of objects in the indexed packfile. Note that this amount + is the **total number of objects** and is not related to the + number of commits that have been selected and indexed in the + bitmap index. + + The hashes are stored in Network Byte Order and they are the same + values generated by a normal revision walk during the `pack-objects` + phase.
Quoted 2 lines
I find it interesting this is network byte order and not big-endian or little-endian based on the flag in the header.
As stated before, the flag in the header only affects the Javaewah/libewok interface. Everything Git-related in the bitmap index is in NWO, like it is customary in Git.
Quoted 35 lines
Quoted 18 lines
Documentation/technical/bitmap-format.txt new file +17
-0+ The `n`nth hash in the cache is the name hash for the `n`th object + in the index for the indexed packfile. + + [RATIONALE]: + + The bitmap index allows us to skip the Counting Objects phase + during `pack-objects` and yield all the OIDs that would be reachable + ("WANTS") when generating the pack. + + This optimization, however, means that we're adding objects to the + packfile straight from the packfile index, and hence we are lacking + path information for the objects that would normally be generated + during the "Counting Objects" phase. + + This path information for each object is hashed and used as a very + effective way to find good delta bases when compressing the packfile; + without these hashes, the resulting packfiles are much less optimal.Documentation/technical/bitmap-format.txt line 89
Quoted 10 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ + By storing all the hashes in a cache together with the bitmapsin + the bitmap index, we can yield not only the SHA1 of all the reachable + objects, but also their hashes, and allow Git to be much smarter when + finding delta bases for packing. + + If the delta cache is not available, the bitmap index will obviously + be smaller in disk, but the packfiles generated using this index will + be between 20% and 30% bigger, because of the lack of name/path + information when finding delta bases.JGit does not encode this because we were afraid of freezing the hash function into the file format. Indeed we are not certain JGit even uses the same path hash function as C Git does, because C Git's implementation is covered by the GPL and JGit prefers to license its work under BSD.
Quoted 3 lines
If the path hash is going to become part of the format, the algorithm for computing the hash should also be specified in the format so that non-GPL implementations have an opportunity to be compatible.
Very valid point. I would hope that whoever wrote the original hash will let us re-license it under BSD. It would be nice to define this hash function as part of the format.
Quoted 7 lines
One way we side-stepped the size inflation problem in JGit was to only use the bitmap index information when sending data on the wire to a client. Here delta reuse plays a significant factor in building the pack, and we don't have to be as accurate on matching deltas. During the equivalent of
git repackbitmaps are not used, allowing the traditional graph enumeration algorithm to generate path hash information.
OH BOY HERE WE GO. This is worth its own thread, lots to discuss here. I think peff will have a patchset regarding this to upstream soon, we'll get back to it later.
Quoted 15 lines
Quoted 15 lines
Documentation/technical/bitmap-format.txt new file +14
-0+ - 4 EWAH bitmaps that act as type indexes + + Type indexes are serialized after the hash cache in the shape + of four EWAH bitmaps stored consecutively (see Appendix A for + the serialization format of an EWAH bitmap). + + There is a bitmap for each Git object type, stored in the following + order: + + - Commits + - Trees + - Blobs + - Tags +
Quoted 8 lines
Documentation/technical/bitmap-format.txt line 110
Quoted 6 lines
Documentation/technical/bitmap-format.txt new file +6
-0+ In each bitmap, the `n`th bit is set to true if the `n`th object + in the packfile index is of that type. + + The obvious consequence is that the XOR of all 4 bitmaps will result + in a full set (all bits sets), and the AND of all 4 bitmaps will + result in an empty bitmap (no bits set).Instead of XOR did you mean OR here?
Nope, I think XOR makes it more obvious: if the same bit is set on two bitmaps, it would be cleared when XORed together, and hence all the bits wouldn't be set. An OR would hide this case.
Quoted 12 lines
Quoted 12 lines
Documentation/technical/bitmap-format.txt new file +11
-0+ - N EWAH bitmaps, one for each indexed commit + + Where `N` is the total amount of entries in this bitmap index. + See Appendix A for the serialization format of an EWAH bitmap. + + - An entry index with `N` entries for the indexed commits + + Index entries are stored consecutively, and each entry has the + following format: + + - 20-byte SHA1
Quoted 8 lines
Documentation/technical/bitmap-format.txt line 127
Quoted 5 lines
Documentation/technical/bitmap-format.txt new file +5
-0+ The SHA1 of the commit that this bitmap indexes + + - 4-byte offset (Network Byte Order) + The offset **from the beginning of the file** where the + bitmap for this commit is stored.Eh, another network byte order field in a file that also has selective ordering. *sigh*
:D :D :D again only the Javaewah interface.
Quoted 11 lines
Quoted 11 lines
Documentation/technical/bitmap-format.txt new file +10
-0+ - 1-byte XOR-offset + The xor offset used to compress this bitmap. For an entry + in position `x`, a XOR offset of `y` means that the actual + bitmap representing for this commit is composed by XORing the + bitmap for this entry with the bitmap in entry `x-y` (i.e. + the bitmap `y` entries before this one). + + Note that this compression can be recursive. In order to + XOR this entry with a previous one, the previous entry needs + to be decompressed first, and so on.
Quoted 8 lines
Documentation/technical/bitmap-format.txt line 144
Quoted 6 lines
Documentation/technical/bitmap-format.txt new file +6
-0+ + The hard-limit for this offset is 160 (an entry can only be + xor'ed against one of the 160 entries preceding it). This + number is always positivea, and hence entries are always xor'ed + with **previous** bitmaps, not bitmaps that will come afterwards + in the index.What order are these entries in? Sorted by SHA-1 or random?
Not-specified, since the whole index will be loaded in a hash table like JGit does. In practice, it's toposorted because that makes for better XOR bases.
Quoted 6 lines
Colby found that doing an XOR against the descendant commit yielded very small bitmaps, so JGit tries to XOR-compress bitmaps along common linear slices of history. This is trivial in Linus' kernel tree where there is effectively only one history, but its more relevant with long-running side branches that have release tags that may not have fully merged into "master".
Indeed, indeed. We try to do the same.
Quoted 7 lines
Documentation/technical/bitmap-format.txt line 166
Quoted 4 lines
Documentation/technical/bitmap-format.txt new file +4
-0+ This full parse, however, requires prohibitive loading times in LE + machines (i.e. all modern server hardware): a repository like + `torvalds/linux` can have about 8mb of bitmap indexes, resulting + in roughly 400ms of parse time.This makes me wonder what the JGit parse time is. It is ugly if we are spending 400ms to load the bitmap index for the kernel repository.
It's very bad. Of course you don't notice it because you're running in daemon mode. It takes about 3s to load indexes for the torvalds/linux network in my machine.
Quoted 76 lines
Documentation/technical/bitmap-format.txt line 175
Quoted 9 lines
Documentation/technical/bitmap-format.txt new file +8
-0+ This is not an issue in JGit, which is capable of serving repositories + from a single-process daemon running on the JVM, but `git-daemon` in + git has been implemented with a process-based design (a new + `pack-objects` is spawned for each request), and the boot times + of parsing the bitmap index every time `pack-objects` is spawned can + seriously slow down requests (particularly for small fetches, where we'd + spend about 1.5s booting up and 300ms performing the Counting Objects + phase).There are other strategies that Git could use to handle request processing at scale. But I guess its reasonable to assume these aren't viable for Git for a number of reasons. E.g. "long tail" access effect that many servers have, where most requests are to a large number of repositories that themselves receive very few requests, an environment that does not lend itself to caching.
Documentation/technical/bitmap-format.txt line 181
Quoted 5 lines
Documentation/technical/bitmap-format.txt new file +5
-0+ By storing the bitmaps in Little-Endian, we're able to `mmap` their + compressed data straight in memory without parsing it beforehand, and + since most queries don't require accessing all the serialized bitmaps, + we'll only page in the minimal amount of bitmaps necessary to perform + the reachability analysis as they are accessed.FWIW the .idx and .pack file formats
mmapthe compressed data straight into memory without parsing it beforehand, and do not use little-endian byte order. It is possible to have a single compressed file format definition that is portable to all architectures, and is accessed by mmap, at scale, with reasonable efficiency.Documentation/technical/bitmap-format.txt line 185
Quoted 3 lines
+- An index of all the bitmapped commits is written at the end of the packfile,
Documentation/technical/bitmap-format.txt new file +2
-0+ instead of interpersed with the serialized bitmaps in the middle of the + file.This is probably a mistake in the JGit design. Your approach is slightly more complex, but in general I agree with having a table of the SHA-1s isolated from the bitmaps themselves so that a reader can access specific bitmaps at random without needing to wade through all compressed bitmaps.
I would have proposed putting the table at the start of the file, not the end. The writer making the file can completely serialize the bitmaps into memory before writing them to disk, and thus knows the full layout of the resulting file. If the bitmaps don't fit in RAM at writing time, game over, the optimization of having a very compact representation of the graph is no longer helping you.
Documentation/technical/bitmap-format.txt line 199
Quoted 13 lines
Documentation/technical/bitmap-format.txt new file +13
-0+ Again, the old design implied a full parse of the whole bitmap index + (which JGit can afford because its daemon is single-process), but it made + impossible `mmaping` the bitmap index file and accessing only the parts + required to actually solve the query. + + With an index at the end of the file, we can load only this index in memory, + allowing for very efficient access to all the available bitmaps lazily (we + have their offsets in the mmaped file). + +- The ordering of the objects in each bitmap has changed from + packfile-order (the nth bit in the bitmap is the nth object in the + packfile) to index-order (the nth bit in the bitmap is the nth object + in the INDEX of the packfile).Did you notice an increase in bitmap size when you did this? Colby tested both orderings and we observed the bitmaps were quantifiably smaller when using the pack file ordering, due to the pack file locality rules and the EWAH compression. Using the pack file ordering was a very conscious design decision.
Documentation/technical/bitmap-format.txt line 209
Quoted 9 lines
Documentation/technical/bitmap-format.txt new file +9
-0+ There is not a noticeable performance difference when actually converting + from bitmap position to SHA1 and from SHA1 to bitmap position, but when + using packfile ordering like JGit does, queries need to go through the + reverse index (pack-revindex.c). + + Generating this reverse index at runtime is **not** free (around 900ms + generation time for a repository like `torvalds/linux`), and once again, + this generation time needs to happen every time `pack-objects` is + spawned.
Quoted 3 lines
Did you know the packer needs the reverse index in order to compute the end offset of an object it will copy as-is during delta reuse? How have you avoided making the reverse index?
I'm aware of that, but there are lots of other operations that can be optimized with bitmaps that don't require a reverse index.
Quoted 7 lines
Again this is why we chose to pin the JGit bitmap on the reverse index being present. It already had to be present to support as-is reuse. Once we knew we had to have that reverse index it was OK to rely on it to get better compression on the bitmaps, and thus make them take up less memory when loaded into a server. Even if you mmap a file you want it to be small so it is more likely to retain in the kernel buffer cache across process invocations.
Maybe this applies to the JVM (where you have to load the whole index), but bitmap indexes are consistently one order of magnitude smaller than packfile indexes (regardless of whether they use index ordering or packfile ordering), and the packfile indexes are always mapped on memory: This has never been an issue in Git, and I don't see why it would become an issue now.
Pinning the bitmap index on the reverse index adds complexity (lookups are two-step: first find the entry in the reverse index, and then find the SHA1 in the index) and is measurably slower, in both loading and lookup times. Since Git doesn't have a memory problem, it's very hard to make an argument for design that is more complex and runs slower to save memory.
To sum it up: I'd like to see this format be strictly in Network Byte Order, and I'm going to try to make it run fast enough in that encoding. Having the entry index at the end of the file and having the bitmaps in index-order are Good Ideas (TM) because they are measurably simpler and faster than their counterpoints. Do show code & benchmarks if you think otherwise, though.
strawberry and watermelon kisses,
vmg
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 17 lines · Vicent Martí
Quoted 8 lines
Quoted 8 lines
Documentation/technical/bitmap-format.txt new file +8
-0+ There is a bitmap for each Git object type, stored in the following + order: + + - Commits + - Trees + - Blobs + - Tags +Quoted 8 lines
Documentation/technical/bitmap-format.txt line 110
Quoted 6 lines
Documentation/technical/bitmap-format.txt new file +6
-0+ In each bitmap, the `n`th bit is set to true if the `n`th object + in the packfile index is of that type. + + The obvious consequence is that the XOR of all 4 bitmaps will result + in a full set (all bits sets), and the AND of all 4 bitmaps will + result in an empty bitmap (no bits set).Instead of XOR did you mean OR here?
Quoted 3 lines
Nope, I think XOR makes it more obvious: if the same bit is set on two bitmaps, it would be cleared when XORed together, and hence all the bits wouldn't be set. An OR would hide this case.
What case are you talking about?
The n-th object must be one of these four types and can never be of more than one type at the same time, so a natural expectation from the reader is "If you OR them together, you will get the same set". If you say "If you XOR them", that forces the reader to wonder when these bitmaps ever can overlap at the same bit position.
Quoted 2 lines
To sum it up: I'd like to see this format be strictly in Network Byte Order,
Good.
I've been wondering what you meant by "cannot be mmap-ed" from the very beginning. We mmapped the index for a long time, and it is defined in terms of network byte order. Of course, pack .idx files are in network byte order, too, and we mmap them without problems. It seems that it primarily came from your fear that using network byte order may be unnecessarily hard to perform well, and it would be a good thing to do to try to do so first instead of punting from the beginning.
Quoted 2 lines
and I'm going to try to make it run fast enough in that encoding.
Hmph. Is it an option to start from what JGit does, so that people can use both JGit and your code on the same repository? And then if you do not succeed, after trying to optimize in-core processing using that on-disk format to make it fast enough, start thinking about tweaking the on-disk format?
Thanks.
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 7 lines · Junio C Hamano
What case are you talking about?
The n-th object must be one of these four types and can never be of more than one type at the same time, so a natural expectation from the reader is "If you OR them together, you will get the same set". If you say "If you XOR them", that forces the reader to wonder when these bitmaps ever can overlap at the same bit position.
I guess this is just wording. I don't particularly care about the distinction, but I'll change it to OR.
Quoted 6 lines
Quoted 3 lines
To sum it up: I'd like to see this format be strictly in Network Byte Order,
Good.
Quoted 8 lines
I've been wondering what you meant by "cannot be mmap-ed" from the very beginning. We mmapped the index for a long time, and it is defined in terms of network byte order. Of course, pack .idx files are in network byte order, too, and we mmap them without problems. It seems that it primarily came from your fear that using network byte order may be unnecessarily hard to perform well, and it would be a good thing to do to try to do so first instead of punting from the beginning.
It cannot be mmapped not particularly because of endianness issues, but because the original format is not indexed and requires a full parse of the whole index before it can be accessed programatically. The wrong endianness just increases the parse time.
Quoted 9 lines
Quoted 3 lines
and I'm going to try to make it run fast enough in that encoding.
Hmph. Is it an option to start from what JGit does, so that people can use both JGit and your code on the same repository? And then if you do not succeed, after trying to optimize in-core processing using that on-disk format to make it fast enough, start thinking about tweaking the on-disk format?
I'm afraid this is not an option. I have an old patchset that implements JGit v1 bitmap loading (and in fact that's how I initially developed these series -- by loading the bitmaps from JGit for debugging), but I discarded it because it simply doesn't pan out in production. ~3 seconds time to spawn upload-pack is not an option for us. I did not develop a tweaked on-disk format out of boredom.
I could dig up the patch if you're particularly interested in backwards compatibility, but since it was several times slower than the current iteration, I have no interest (time, actually) to maintain it, brush it up, and so on. I have already offered myself to port the v2 format to JGit as soon as it's settled. It sounds like a better investment of all our times.
Following up on Shawn's comments, I removed the little-endian support from the on-disk format and implemented lazy loading of the bitmaps to make up for it. The result is decent (slowed down from 250ms to 300ms) and it lets us keep the whole format as NWO on disk. I think it's a good tradeback.
The relevant commits are available on my fork of Git (I'll be sending v2 of the patchset once I finish tackling the other reviews):
https://github.com/vmg/git/commit/d6cdd4329a547580bbc0143764c726c48b887271 https://github.com/vmg/git/commit/d8ec342fee87425e05c0db1e1630db8424612c71
As it stands right now, the only two changes from v1 of the on-disk format are:
- There is an index at the end. This is a good idea.
- The bitmaps are sorted in packfile-index order, not in packfile order. This is a good idea.
As always, all your feedback is appreciated, but please keep in mind I have strict performance concerns.
German kisses,
vmg
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Vicent MartíQuoted 11 lines · Vicent Martí
Quoted 7 lines
One way we side-stepped the size inflation problem in JGit was to only use the bitmap index information when sending data on the wire to a client. Here delta reuse plays a significant factor in building the pack, and we don't have to be as accurate on matching deltas. During the equivalent of
git repackbitmaps are not used, allowing the traditional graph enumeration algorithm to generate path hash information.OH BOY HERE WE GO. This is worth its own thread, lots to discuss here. I think peff will have a patchset regarding this to upstream soon, we'll get back to it later.
We do the same thing (only use bitmaps during on-the-wire fetches). But there a few problems with assuming delta reuse.
For us (GitHub), the foremost one is that we pack many "forks" of a repository together into a single packfile. That means when you clone torvalds/linux, an object you want may be stored in the on-disk pack with a delta against an object that you are not going to get. So we have to throw out that delta and find a new one.
I'm dealing with that by adding an option to respect "islands" during packing, where an island is a set of common objects (we split it by fork, since we expect those objects to be fetched together, but you could use other criteria). The rule is that an object cannot delta against another object that is not in all of its islands. So everybody can delta against shared history, but objects in your fork can only delta against other objects in the fork. You are guaranteed to be able to reuse such deltas during a full clone of a fork, and the on-disk pack size does not suffer all that much (because there is usually a good alternate delta base within your reachable history).
So with that series, we can get good reuse for clones. But there are still two cases worth considering:
1. When you fetch a subset of the commits, git marks only the edges as preferred bases, and does not walk the full object graph down to the roots. So any object you want that is delta'd against something older will not get reused. If you have reachability bitmaps, I don't think there is any reason that we cannot use the entire object graph (starting at the "have" tips, of course) as preferred bases.
2. The server is not necessarily fully packed. In an active repo, you may have a large "base" pack with bitmaps, with several recently pushed packs on top. You still need to delta the recently pushed objects against the base objects.
I don't have measurements on how much the deltas suffer in those two cases. I know they suffered quite badly for clones without the name hashes in our alternates repos, but that part should go away with my patch series.
-Peff
PATCH 10/16 pack-objects: use bitmaps when packing objects
In reply to Vicent MartiA bitmap index is used, if available, to speed up the Counting Objects phase during pack-objects.
The bitmap index is a .bitmap file that can be found inside $GIT_DIR/objects/pack/, next to its corresponding packfile, and contains precalculated reachability information for selected commits. The full specification of the format for these bitmap indexes can be found in Documentation/technical/bitmap-format.txt.
For a given commit SHA1, if it happens to be available in the bitmap index, its bitmap will represent every single object that is reachable from the commit itself. The nth bit in the bitmap is the nth object in the index of the packfile; if it's set to 1, the object is reachable.
By using the bitmaps available in the index, this commit implements a new pair of functions:
- prepare_bitmap_walk
- traverse_bitmap_commit_list
This first function tries to build a bitmap of all the objects that can be reached from the commit roots of a given rev_info struct by using the following algorithm:
- If all the interesting commits for a revision walk are available in the index, the resulting reachability bitmap is the bitwise OR of all the individual bitmaps.
- When the full set of WANTs is not available in the index, we perform a partial revision walk using the commits that don't have bitmaps as roots, and limiting the revision walk as soon as we reach a commit that has a corresponding bitmap. The earlier OR'ed bitmap with all the indexed commits can now be completed as this walk progresses, so the end result is the full reachability list.
- For revision walks with a HAVEs set (a set of commits that are deemed uninteresting), first we perform the same method as for the WANTs, but using our HAVEs as roots, in order to obtain a full reachability bitmap of all the uninteresting commits. This bitmap then can be used to:
a) limit the subsequent walk when building the WANTs bitmap
b) finding the final set of interesting commits by performing an AND-NOT of the WANTs and the HAVEs.
If prepare_bitmap_walk runs successfully, the resulting bitmap is stored and the equivalent of a traverse_commit_list call can be performed by using traverse_bitmap_commit_list; the bitmap version of this call yields the objects straight from the packfile index (without having to look them up or parse them) and hence is several orders of magnitude faster.
If the prepare_bitmap_walk call fails (e.g. because no bitmap files are available), the rev_info struct is left untouched, and can be used to perform a manual rev-walk using traverse_commit_list.
Hence, this new pair of functions are a generic API that allows to perform the equivalent of
git rev-list --objects [roots...] [^uninteresting...]
for any set of commits, even if they don't have specific bitmaps generated for them.
In this specific commit, we use the API to perform the Counting Objects phase in builtin/pack-objects.c, although it could be used to speed up other parts of Git that use the same mechanism.
If the pack-objects invocation is being piped to stdout (like a normal pack-objects from upload-pack would be used) and bitmaps are enabled, the new bitmap_walk API will be used instead of traverse_commit_list.
There are two ways to enable bitmaps for pack-objecs:
- Pass the --use-bitmaps flag when calling pack-objects
- Set pack.usebitmaps to true in the git config for the repository.
Of course, simply enabling the bitmaps is not enought to perform the
optimization: a bitmap index must be available on disk. If no bitmap index can be found, we'll silently fall back to the slow counting objects phase.
The point of speeding up the Counting Objects phase of pack-objects is to reduce fetch and clone times for big repositories, which right now are definitely dominated by the rev-walk algorithm during the Counting Objects phase.
Here are some sample timings from a full pack of torvalds/linux (i.e. something very similar to what would be generated for a clone of the repository):
$ time ../git/git pack-objects --all --stdout Counting objects: 3053537, done. Compressing objects: 100% (495706/495706), done. Total 3053537 (delta 2529614), reused 3053537 (delta 2529614)
real 0m36.686s user 0m34.440s sys 0m2.184s
$ time ../git/git pack-objects --all --stdout Counting objects: 3053537, done. Compressing objects: 100% (495706/495706), done. Total 3053537 (delta 2529614), reused 3053537 (delta 2529614)
real 0m7.255s user 0m6.892s sys 0m0.444s
Quoted 1 line
From a hotspot profiling run, we can see how the counting
objects phase has been reduced to about 400ms (down from 28s). The remaining time is spent finding deltas and writing the packfile, the optimization of which is out of the scope of this topic.
--- Makefile | 2 + builtin/pack-objects.c | 31 ++ pack-bitmap.c | 818 ++++++++++++++++++++++++++++++++++++++++++++++++ pack-bitmap.h | 53 ++++ 4 files changed, 904 insertions(+) create mode 100644 pack-bitmap.c create mode 100644 pack-bitmap.h
Makefile +2 -0
@@ -703,6 +703,7 @@ LIB_H += notes.h LIB_H += object.h LIB_H += pack-revindex.h LIB_H += pack.h +LIB_H += pack-bitmap.h LIB_H += parse-options.h LIB_H += patch-ids.h LIB_H += pathspec.h
@@ -838,6 +839,7 @@ LIB_OBJS += notes.o LIB_OBJS += notes-cache.o LIB_OBJS += notes-merge.o LIB_OBJS += object.o +LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-check.o LIB_OBJS += pack-revindex.o LIB_OBJS += pack-write.o
builtin/pack-objects.c +31 -0
@@ -19,6 +19,7 @@#include "streaming.h" #include "thread-utils.h" #include "khash.h" +#include "pack-bitmap.h" static const char *pack_usage[] = {N_ ("git pack-objects --stdout [options...] [< ref-list | < object-list]" ),
@@ -83,6 +84,9 @@ static struct progress *progress_state;static int pack_compression_level =Z_DEFAULT_COMPRESSION ;static int pack_compression_seen; +static int bitmap_support; +static int use_bitmap_index; +static unsigned long delta_cache_size =0 ;static unsigned long max_delta_cache_size =256 *1024 *1024 ;static unsigned long cache_max_small_delta_size =1000 ;
@@ -2131,6 +2135,10 @@ static int git_pack_config(const char *k, const char *v, void *cb) cache_max_small_delta_size =git_config_int (k, v);return 0 ; } +if (!strcmp (k,"pack.usebitmaps" )) { + bitmap_support =git_config_bool (k, v); +return 0 ; + }if (!strcmp (k,"pack.threads" )) { delta_search_threads =git_config_int (k, v);if (delta_search_threads <0 )
@@ -2366,8 +2374,24 @@ static void get_object_list(int ac, const char **av)die ("bad revision '%s'" , line); } +if (use_bitmap_index) { +uint32_t size_hint; + +if (!prepare_bitmap_walk (&revs, &size_hint)) { +khint_t new_hash_size = (size_hint * (1.0 / __ac_HASH_UPPER)) +0.5 ; +kh_resize_sha1 (packed_objects, new_hash_size); + + nr_alloc = (size_hint +63 ) & ~63 ; + objects =xrealloc (objects, nr_alloc *sizeof (struct object_entry *)); + +traverse_bitmap_commit_list (&add_object_entry_1); +return ; + } + } +if (prepare_revision_walk (&revs))die ("revision walk setup failed" ); +mark_edges_uninteresting (revs.commits, &revs, show_edge);traverse_commit_list (&revs, show_commit, show_object,NULL );
@@ -2495,6 +2519,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) N_("pack compression level")),OPT_SET_INT (0 ,"keep-true-parents" , &grafts_replace_parents,N_ ("do not hide commits by grafts" ),0 ), +OPT_BOOL (0 ,"bitmaps" , &bitmap_support, +N_ ("enable support for bitmap optimizations" )), OPT_END(), };
@@ -2561,6 +2587,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)if (keep_unreachable && unpack_unreachable)die ("--keep-unreachable and --unpack-unreachable are incompatible." ); +if (bitmap_support) { +if (use_internal_rev_list && pack_to_stdout) + use_bitmap_index =1 ; + } +if (progress && all_progress_implied) progress =2 ;
pack-bitmap.c new file +818 -0
818 lines not on this page · raw message
pack-bitmap.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 10/16] pack-objects: use bitmaps when packing objects
builtin/pack-objects.c static struct progress *progress_state; · line 88
Quoted 6 lines · Vicent Marti
builtin/pack-objects.c +2
-0@@ -83,6 +84,9 @@ static struct progress *progress_state;static int pack_compression_level =Z_DEFAULT_COMPRESSION ;static int pack_compression_seen; +static int bitmap_support; +static int use_bitmap_index;
OK.
builtin/pack-objects.c static int git_pack_config(const char *k, const char *v, void *cb) · line 2141
Quoted 8 lines
builtin/pack-objects.c +4
-0@@ -2131,6 +2135,10 @@ static int git_pack_config(const char *k, const char *v, void *cb) cache_max_small_delta_size =git_config_int (k, v);return 0 ; } +if (!strcmp (k,"pack.usebitmaps" )) { + bitmap_support =git_config_bool (k, v); +return 0 ; + }
Hmph, so bitmap_support, not use_bitmap_index, keeps track of the user request? Somewhat confusing.
builtin/pack-objects.c static void get_object_list(int ac, const char **av) · line 2381
Quoted 12 lines
builtin/pack-objects.c +5
-0if (!strcmp (k,"pack.threads" )) { delta_search_threads =git_config_int (k, v);if (delta_search_threads <0 )@@ -2366,8 +2374,24 @@ static void get_object_list(int ac, const char **av)die ("bad revision '%s'" , line); } +if (use_bitmap_index) { +uint32_t size_hint; + +if (!prepare_bitmap_walk (&revs, &size_hint)) { +khint_t new_hash_size = (size_hint * (1.0 / __ac_HASH_UPPER)) +0.5 ;
What is __ac_HASH_UPPER? That is a very unusual name for a variable or a constant. Also it is mildly annoying to see unnecessary use of float like this.
Quoted 17 lines
builtin/pack-objects.c +11
-0+kh_resize_sha1 (packed_objects, new_hash_size); + + nr_alloc = (size_hint +63 ) & ~63 ; + objects =xrealloc (objects, nr_alloc *sizeof (struct object_entry *)); + +traverse_bitmap_commit_list (&add_object_entry_1); +return ; + } + } +if (prepare_revision_walk (&revs))die ("revision walk setup failed" ); +mark_edges_uninteresting (revs.commits, &revs, show_edge);traverse_commit_list (&revs, show_commit, show_object,NULL );
builtin/pack-objects.c int cmd_pack_objects(int argc, const char **argv, const char *prefix) · line 2523
Quoted 5 lines
builtin/pack-objects.c +2
-0@@ -2495,6 +2519,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) N_("pack compression level")),OPT_SET_INT (0 ,"keep-true-parents" , &grafts_replace_parents,N_ ("do not hide commits by grafts" ),0 ), +OPT_BOOL (0 ,"bitmaps" , &bitmap_support, + N_("enable support for bitmap optimizations")),
Please match this with the name of configuration variable, i.e. --use-bitmaps
builtin/pack-objects.c int cmd_pack_objects(int argc, const char **argv, const char *prefix) · line 2592
Quoted 10 lines
builtin/pack-objects.c +3
-0OPT_END(), };@@ -2561,6 +2587,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)if (keep_unreachable && unpack_unreachable)die ("--keep-unreachable and --unpack-unreachable are incompatible." ); +if (bitmap_support) { +if (use_internal_rev_list && pack_to_stdout) + use_bitmap_index =1 ;
OK, so only when some internal condition is met, the user request to use bitmap is honored and the deision is kept in use_bitmap_index.
It may be easier to read if you get rid of bitmap_support, set user_bitmap_index directly from the command line and config, and did this here instead:
if (!(use_internal_rev_list && pack_to_stdout)) use_bitmap_index = 0;
Re: [PATCH 10/16] pack-objects: use bitmaps when packing objects
Quoted 28 lines · Junio C Hamano
builtin/pack-objects.c static struct progress *progress_state; · line 88
Quoted 6 lines
builtin/pack-objects.c +2
-0@@ -83,6 +84,9 @@ static struct progress *progress_state;static int pack_compression_level =Z_DEFAULT_COMPRESSION ;static int pack_compression_seen; +static int bitmap_support; +static int use_bitmap_index;OK.
builtin/pack-objects.c static int git_pack_config(const char *k, const char *v, void *cb) · line 2141
Quoted 8 lines
builtin/pack-objects.c +4
-0@@ -2131,6 +2135,10 @@ static int git_pack_config(const char *k, const char *v, void *cb) cache_max_small_delta_size =git_config_int (k, v);return 0 ; } +if (!strcmp (k,"pack.usebitmaps" )) { + bitmap_support =git_config_bool (k, v); +return 0 ; + }Hmph, so
bitmap_support, notuse_bitmap_index, keeps track of the user request? Somewhat confusing.Quoted 7 lines
builtin/pack-objects.c +0
-0if (!strcmp (k,"pack.threads" )) { delta_search_threads =git_config_int (k, v);if (delta_search_threads <0 )@@ -2366,8 +2374,24 @@ static void get_object_list(int ac, const char **av)die ("bad revision '%s'" , line); }
Quoted 9 lines
builtin/pack-objects.c static void get_object_list(int ac, const char **av) · line 2381
Quoted 5 lines
builtin/pack-objects.c +5
-0+if (use_bitmap_index) { +uint32_t size_hint; + +if (!prepare_bitmap_walk (&revs, &size_hint)) { +khint_t new_hash_size = (size_hint * (1.0 / __ac_HASH_UPPER)) +0.5 ;What is
__ac_HASH_UPPER? That is a very unusual name for a variable or a constant. Also it is mildly annoying to see unnecessary use of float like this.
See the updated patch at:
https://github.com/vmg/git/blob/vmg/bitmaps-master/builtin/pack-objects.c#L2422
Quoted 40 lines
Quoted 18 lines
builtin/pack-objects.c +11
-0+kh_resize_sha1 (packed_objects, new_hash_size); + + nr_alloc = (size_hint +63 ) & ~63 ; + objects =xrealloc (objects, nr_alloc *sizeof (struct object_entry *)); + +traverse_bitmap_commit_list (&add_object_entry_1); +return ; + } + } +if (prepare_revision_walk (&revs))die ("revision walk setup failed" ); +mark_edges_uninteresting (revs.commits, &revs, show_edge);traverse_commit_list (&revs, show_commit, show_object,NULL );builtin/pack-objects.c int cmd_pack_objects(int argc, const char **argv, const char *prefix) · line 2523
Quoted 5 lines
builtin/pack-objects.c +2
-0@@ -2495,6 +2519,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) N_("pack compression level")),OPT_SET_INT (0 ,"keep-true-parents" , &grafts_replace_parents,N_ ("do not hide commits by grafts" ),0 ), +OPT_BOOL (0 ,"bitmaps" , &bitmap_support, + N_("enable support for bitmap optimizations")),Please match this with the name of configuration variable, i.e. --use-bitmaps
builtin/pack-objects.c int cmd_pack_objects(int argc, const char **argv, const char *prefix) · line 2592
Quoted 10 lines
builtin/pack-objects.c +3
-0OPT_END(), };@@ -2561,6 +2587,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)if (keep_unreachable && unpack_unreachable)die ("--keep-unreachable and --unpack-unreachable are incompatible." ); +if (bitmap_support) { +if (use_internal_rev_list && pack_to_stdout) + use_bitmap_index =1 ;OK, so only when some internal condition is met, the user request to use bitmap is honored and the deision is kept in
use_bitmap_index.
Quoted 6 lines
It may be easier to read if you get rid of
bitmap_support, setuser_bitmap_indexdirectly from the command line and config, and did this here instead:if (!(use_internal_rev_list && pack_to_stdout)) use_bitmap_index = 0;
Yeah, I'm not particularly happy with the way these flags are implemented. I'll update this.
Re: [PATCH 10/16] pack-objects: use bitmaps when packing objects
In reply to Vicent MartiQuoted 13 lines · Vicent Marti
Makefile +1
-0@@ -703,6 +703,7 @@ LIB_H += notes.h LIB_H += object.h LIB_H += pack-revindex.h LIB_H += pack.h +LIB_H += pack-bitmap.h LIB_H += parse-options.h LIB_H += patch-ids.h LIB_H += pathspec.h
Makefile LIB_OBJS += notes.o · line 845
Quoted 7 lines
Makefile +1
-0@@ -838,6 +839,7 @@ LIB_OBJS += notes.o LIB_OBJS += notes-cache.o LIB_OBJS += notes-merge.o LIB_OBJS += object.o +LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-check.o LIB_OBJS += pack-revindex.o LIB_OBJS += pack-write.o
What does this apply on? When starting with the series from origin/master, git-am fails, and 'git am -3' tells me I don't have the necessary blobs (from the 'index' line above).
Not that it's super hard to fix this up as long as it's in the Makefile only, but still.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 10/16] pack-objects: use bitmaps when packing objects
In reply to Vicent MartiQuoted 9 lines · Vicent Marti
$ time ../git/git pack-objects --all --stdout Counting objects: 3053537, done. Compressing objects: 100% (495706/495706), done. Total 3053537 (delta 2529614), reused 3053537 (delta 2529614)real 0m36.686s user 0m34.440s sys 0m2.184s
Quoted 8 lines
$ time ../git/git pack-objects --all --stdout Counting objects: 3053537, done. Compressing objects: 100% (495706/495706), done. Total 3053537 (delta 2529614), reused 3053537 (delta 2529614)real 0m7.255s user 0m6.892s sys 0m0.444s
Awesome work! Can you put up this series on gh:vmg so I can try it out for myself?
builtin/pack-objects.c static int git_pack_config(const char *k, const char *v, void *cb) · line 2141
Quoted 8 lines
builtin/pack-objects.c +4
-0+if (!strcmp (k,"pack.usebitmaps" )) { + bitmap_support =git_config_bool (k, v); +return 0 ; + }
Not using config_error_nonbool() to indicate an error?
builtin/pack-objects.c static void get_object_list(int ac, const char **av) · line 2381
Quoted 5 lines
builtin/pack-objects.c +5
-0+if (use_bitmap_index) { +uint32_t size_hint; + +if (!prepare_bitmap_walk (&revs, &size_hint)) { +khint_t new_hash_size = (size_hint * (1.0 / __ac_HASH_UPPER)) +0.5 ;
How does this work? You've taken the inverse of __ac_HASH_UPPER, multiplied it by the size_hint you get from prepare_bitmap_walk(), and add 0.5?
Quoted 1 line
+
kh_resize_sha1(packed_objects, new_hash_size);
So packed_objects is a hashtable of type kh_sha1_t * (you introduced in [03/16]) that you're now resizing to new_hash_size. To find out what the significance of this new_hash_size is, it looks like I have to read prepare_bitmap_walk().
builtin/pack-objects.c static void get_object_list(int ac, const char **av) · line 2385
Quoted 2 lines
builtin/pack-objects.c +2
-0+ nr_alloc = (size_hint +63 ) & ~63 ; + objects =xrealloc (objects, nr_alloc *sizeof (struct object_entry *));
Interesting. The only other place where we realloc the objects in this file is in pack-objects.c:949, and we do that because nr_object
Quoted 5 lines
=
nr_alloc. What is this 63 magic?if (prepare_revision_walk(&revs)) die("revision walk setup failed");+
Stray newline.
builtin/pack-objects.c int cmd_pack_objects(int argc, const char **argv, const char *prefix) · line 2594
Quoted 5 lines
builtin/pack-objects.c +5
-0+if (bitmap_support) { +if (use_internal_rev_list && pack_to_stdout) + use_bitmap_index =1 ; + } +
Wait, what does pack_to_stdout have to do with deciding whether or not to walk the bitmap?
pack-bitmap.c line 18
Quoted 11 lines
pack-bitmap.c new file +6
-0+struct stored_bitmap { +unsigned char sha1[20 ]; +struct ewah_bitmap *root; +struct stored_bitmap *xor; +int flags; +};
What exactly is this? What is stored_bitmap *xor? It looks like some sort of next-pointer, but why is it named xor?
Quoted 1 line
+struct
bitmap_index{
Okay, the bitmap index.
pack-bitmap.c line 24
Quoted 4 lines
pack-bitmap.c new file +4
-0+struct ewah_bitmap *commits; +struct ewah_bitmap *trees; +struct ewah_bitmap *blobs; +struct ewah_bitmap *tags;
I might be asking a really stupid question here, but why do you have different bitmaps for different object types? Unless I'm mistaken, the packfile index doesn't make this differentiation: it sorts and stores the SHA-1s of the various objects; you request a SHA-1, it does a binary search and returns the object.
Quoted 1 line
+
khash_sha1*bitmaps;
A hashmap keyed with the SHA-1, I presume.
Quoted 1 line
+ struct
packed_git*pack;
You're defining which pack this bitmap index is for, right?
pack-bitmap.c line 33
Quoted 4 lines
pack-bitmap.c new file +4
-0+struct { +struct object_array entries; +khash_sha1 *map; + } fake_index;
What is this?
Quoted 1 line
+ struct bitmap *result;
No clue what this is about.
Quoted 1 line
+ int
entry_count;
No clue what this is, but I'm assuming it can't be important because it's an int.
pack-bitmap.c line 40
Quoted 3 lines
pack-bitmap.c new file +3
-0+char pack_checksum[20 ]; + +int version;
Use something invariant like uint32_t? Also, there is no clear indication about where this information is going to go (header, presumably?). Look at pack.h:
struct pack_idx_header {
uint32_t idx_signature;
uint32_t idx_version;
};pack-bitmap.c line 43
Quoted 3 lines
pack-bitmap.c new file +3
-0+ unsigned loaded : 1, + native_bitmaps : 1, + has_hash_cache : 1;
Booleans, but I don't know what they're doing here even after reading your bitmap-format.txt.
Quoted 1 line
+ struct
ewah_bitmap*(*read_bitmap)(structbitmap_index*index);
I'm very confused now. Each bitmap_index has a specialized read_bitmap()?
pack-bitmap.c line 50
Quoted 4 lines
pack-bitmap.c new file +4
-0+void *map; +size_t map_size, map_pos; + +uint32_t *delta_hashes;
I'll give up on the rest.
Quoted 1 line
+static struct
bitmap_indexbitmap_git;
You could have made the struct static to begin with and ended it with a } bitmap_git;
pack-bitmap.c line 56
Quoted 2 lines
pack-bitmap.c new file +2
-0+static struct ewah_bitmap * +lookup_stored_bitmap (struct stored_bitmap *st)
Please conform to Linux style and make it easier for us to grep by putting this in one line?
pack-bitmap.c line 61
Quoted 5 lines
pack-bitmap.c new file +5
-0+{ +struct ewah_bitmap *parent; +struct ewah_bitmap *composed; + +if (st->xor ==NULL )
if (!st->xor)
Quoted 1 line
+ return
st->root;
Okay, st->xor needs to be set to something for lookup_stored_bitmap() to do something useful.
pack-bitmap.c line 65
Quoted 2 lines
pack-bitmap.c new file +2
-0+ composed =ewah_pool_new (); + parent =lookup_stored_bitmap (st->xor);
So st->xor is a parent-pointer? Still doesn't answer my question about why it is named xor.
Quoted 1 line
+
ewah_xor(st->root, parent, composed);
I would have loved it if the prototype of this function made it clear what it was writing like: ewah_xor(st->root, parent, &composed); but then it expects the caller to do memory allocation, so never mind.
pack-bitmap.c line 72
Quoted 5 lines
pack-bitmap.c new file +5
-0+ewah_pool_free (st->root); + st->root = composed; + st->xor =NULL ; + +return composed;
So lookup_stored_bitmap() just xors st->root with parent (determined by recursively looking up st->xor)?
pack-bitmap.c line 76
Quoted 4 lines
pack-bitmap.c new file +4
-0+} + +static struct ewah_bitmap * +_read_bitmap (struct bitmap_index *index)
We usually use the _1 suffix convention for internal functions, not _ prefix.
pack-bitmap.c line 83
Quoted 5 lines
pack-bitmap.c new file +5
-0+int bitmap_size; + + bitmap_size =ewah_read_mmap (b, + index->map + index->map_pos, + index->map_size - index->map_pos);
Make this a single statement. Also, why can't I see this on gh:vmg/libework? Your [08/16] has diverged from there :/
Quoted 1 line
+ return b;
So _read_bitmap() mmaps the bitmap and returns it.
pack-bitmap.c
Quoted 2 lines
pack-bitmap.c new file +2
-0+static struct ewah_bitmap * +_read_bitmap_native (struct bitmap_index *index)
The counterpart that calls *_mmap_native() in ewah. Have to look at the difference. In any case, I hope you've used xmmap().
pack-bitmap.c
Quoted 2 lines
pack-bitmap.c new file +2
-0+static int load_bitmap_header (struct bitmap_index *index) +{
I'm going to compare this to sha1_file.c:check_packed_git_idx().
pack-bitmap.c line 120
Quoted 4 lines
pack-bitmap.c new file +4
-0+struct bitmap_disk_header *header = (void *)index->map; + +if (index->map_size <sizeof (*header)) +return error ("Corrupted bitmap index (missing header data)" );
No munmap()? Was abstracting out the mmap detail a good idea?
pack-bitmap.c line 123
Quoted 2 lines
pack-bitmap.c new file +2
-0+if (memcmp (header->magic,BITMAP_MAGIC_PREFIX ,sizeof (BITMAP_MAGIC_PREFIX )) !=0 ) +return error ("Corrupted bitmap index file (wrong header)" );
PACK_SIGNATURE, PACK_IDX_SIGNATURE. Name this BITMAP_IDX_SIGNATURE?
Quoted 1 line
+
index->version= (int)ntohs(header->version);
You wouldn't have to coerce to int if version were a uint32_t in the first place.
pack-bitmap.c line 131
Quoted 3 lines
pack-bitmap.c new file +3
-0+/* Parse known bitmap format options */ + { +uint32_t flags =ntohs (header->options);
Okay.
pack-bitmap.c line 136
Quoted 4 lines
pack-bitmap.c new file +4
-0+if ((flags &BITMAP_OPT_FULL_DAG ) ==0 ) { +return error ("Unsupported options for bitmap index file " +"(Git requires BITMAP_OPT_FULL_DAG)" ); + }
Unnecessary braces for single statement.
pack-bitmap.c line 141
Quoted 4 lines
pack-bitmap.c new file +4
-0+if (flags &BITMAP_OPT_HASH_CACHE ) + index->has_hash_cache =1 ; + + index->read_bitmap = &_read_bitmap;
So you've set the read_bitmap() function to _read_bitmap(). Let's see why.
Quoted 6 lines
pack-bitmap.c new file +6
-0+/* +* If we are in a little endian machine and the bitmap +* was written in LE, we can mmap it straight into memory +* without having to parse it +*/ +if ((flags &BITMAP_OPT_LE_BITMAPS )) {
pack-bitmap.c line 158
Quoted 10 lines
pack-bitmap.c new file +10
-0+#if __BYTE_ORDER == __LITTLE_ENDIAN + index->native_bitmaps =1 ; + index->read_bitmap = &_read_bitmap_native; +#else +die ("The existing bitmap index is written in little-endian " +"byte order and cannot be read in this machine.\n" +"Please re-build the bitmap indexes locally." ); +#endif + } + }
Okay.
pack-bitmap.c line 161
Quoted 2 lines
pack-bitmap.c new file +2
-0+ index->entry_count =ntohl (header->entry_count); +memcpy (index->pack_checksum, header->checksum,sizeof (header->checksum));
I might be asking (yet another) really stupid question here, but why isn't the checksum an unsigned char[20] (i.e. a simple 20-byte SHA-1)?
We already have infrastructure to deal with SHA-1s, so might as well
reuse it, right?
Quoted 1 line
+
index->map_pos+=sizeof(*header);
You've read the header successfully, and incremented map_pos for other callers.
pack-bitmap.c line 171
Quoted 5 lines
pack-bitmap.c new file +5
-0+static struct stored_bitmap * +store_bitmap (struct bitmap_index *index, +const unsigned char *sha1, +struct ewah_bitmap *bitmap, +struct stored_bitmap *xor_with,int flags)
Why don't you just prepare a struct and send it to this function to write instead of so many arguments?
pack-bitmap.c line 181
Quoted 5 lines
pack-bitmap.c new file +5
-0+ stored =xmalloc (sizeof (struct stored_bitmap )); + stored->root = bitmap; + stored->xor = xor_with; + stored->flags = flags; +memcpy (stored->sha1, sha1,20 );
Use hashcpy(). You would have had to do none of this if the caller had passed a readymade struct, no?
Quoted 1 line
+
hash_pos=kh_put_sha1(index->bitmaps, stored->sha1, &ret);
Okay, you store a SHA-1.
pack-bitmap.c line 187
Quoted 4 lines
pack-bitmap.c new file +4
-0+if (ret ==0 ) { +error ("Duplicate entry in bitmap index: %s" ,sha1_to_hex (sha1)); +return NULL ; + }
0 is success by convention!
Quoted 1 line
+
kh_value(index->bitmaps, hash_pos)= stored;
Okay.
Quoted 1 line
+ return stored;
You're returning allocated memory, that the caller must remember to free.
pack-bitmap.c line 194
Quoted 2 lines
pack-bitmap.c new file +2
-0+static int +load_bitmap_entries_v2 (struct bitmap_index *index)
I'm not sure it's a great idea to put a volatile version number in the function name.
pack-bitmap.c line 199
Quoted 5 lines
pack-bitmap.c new file +5
-0+{ +static const int MAX_XOR_OFFSET =16 ; + +int i; +struct stored_bitmap *recent_bitmaps[16 ];
Does this 16 have anything to do with MAX_XOR_OFFSET?
pack-bitmap.c line 203
Quoted 4 lines
pack-bitmap.c new file +4
-0+struct bitmap_disk_entry_v2 *entry; + +void *index_pos = index->map + index->map_size - + (index->entry_count *sizeof (struct bitmap_disk_entry_v2 ));
Wait, why did we set map_pos earlier if you're recomputing it here? And why is this a void *?
pack-bitmap.c line 212
Quoted 8 lines
pack-bitmap.c new file +8
-0+for (i =0 ; i < index->entry_count; ++i) { +int xor_offset, flags, ret; +struct stored_bitmap *xor_bitmap =NULL ; +struct ewah_bitmap *bitmap =NULL ; +uint32_t bitmap_pos; + + entry = index_pos; + index_pos +=sizeof (struct bitmap_disk_entry_v2 );
Okay, so I understand that you're parsing one bitmap_disk_entry_v2 struct at a time.
pack-bitmap.c line 216
Quoted 3 lines
pack-bitmap.c new file +3
-0+ bitmap_pos =ntohl (entry->bitmap_pos); + xor_offset = (int )entry->xor_offset; + flags = (int )entry->flags;
I have no clue why you're casting like this.
Quoted 1 line
+ if (
index->native_bitmaps) {
What is this native versus non-native bitmaps? Your bitmap-formats.txt has nothing to say on the matter.
pack-bitmap.c line 222
Quoted 4 lines
pack-bitmap.c new file +4
-0+ bitmap =calloc (1 ,sizeof (struct ewah_bitmap )); + ret =ewah_read_mmap_native (bitmap, + index->map + bitmap_pos, + index->map_size - bitmap_pos);
Wait a minute. Isn't this what you wrapped in _read_bitmap_native()? Totally confused.
pack-bitmap.c line 227
Quoted 5 lines
pack-bitmap.c new file +5
-0+ }else { + bitmap =ewah_pool_new (); + ret =ewah_read_mmap (bitmap, + index->map + bitmap_pos, + index->map_size - bitmap_pos);
Did you forget about _read_bitmap()?
pack-bitmap.c line 232
Quoted 3 lines
pack-bitmap.c new file +3
-0+if (ret <0 || xor_offset >MAX_XOR_OFFSET || xor_offset > i) { +return error ("Corrupted bitmap pack index" ); + }
Unnecessary braces.
pack-bitmap.c line 237
Quoted 4 lines
pack-bitmap.c new file +4
-0+if (xor_offset >0 ) { + xor_bitmap = recent_bitmaps[(i - xor_offset) %MAX_XOR_OFFSET ]; + +if (xor_bitmap ==NULL )
if (!xor_bitmap)
Quoted 1 line
+ return
error("Invalid XOR offset in bitmap pack index");
I haven't seen a single die() until now, and that's a Good sign.
pack-bitmap.c line 242
Quoted 2 lines
pack-bitmap.c new file +2
-0+ recent_bitmaps[i %MAX_XOR_OFFSET ] =store_bitmap ( + index, entry->sha1, bitmap, xor_bitmap, flags);
So you fill in the 16 recent bitmaps in this function?
pack-bitmap.c line 253
Quoted 6 lines
pack-bitmap.c new file +6
-0+static int load_bitmap_index ( +struct bitmap_index *index, +const char *path, +struct packed_git *packfile) +{ +int fd =git_open_noatime (path);
I assume you exposed this static defined in sha1_file.c in an earlier patch, but I didn't check.
pack-bitmap.c line 258
Quoted 5 lines
pack-bitmap.c new file +5
-0+struct stat st; + +if (fd <0 ) { +return -1 ; + }
Unnecessary braces.
pack-bitmap.c line 267
Quoted 3 lines
pack-bitmap.c new file +3
-0+ index->map_size =xsize_t (st.st_size); + index->map =xmmap (NULL , index->map_size,PROT_READ ,MAP_PRIVATE , fd,0 ); +close (fd);
I like how similar this is to check_packed_git_idx(). What happened to your ewah mapping abstractions though?
pack-bitmap.c line 271
Quoted 3 lines
pack-bitmap.c new file +3
-0+ index->bitmaps =kh_init_sha1 (); + index->pack = packfile; + index->fake_index.map =kh_init_sha1 ();
I'll hopefully get to find out what fake_index is here.
pack-bitmap.c
Quoted 2 lines
pack-bitmap.c new file +2
-0+if (load_bitmap_header (index) <0 ) +return -1 ;
Okay. Notice how the format we're parsing is documented tersely as inline comments in sha1_name.c: you might like to do that too.
pack-bitmap.c line 279
Quoted 4 lines
pack-bitmap.c new file +4
-0+if (index->has_hash_cache) { + index->delta_hashes = index->map + index->map_pos; + index->map_pos += (packfile->num_objects *sizeof (uint32_t )); + }
Okay.
pack-bitmap.c line 285
Quoted 5 lines
pack-bitmap.c new file +5
-0+if ((index->commits = index->read_bitmap (index)) ==NULL || + (index->trees = index->read_bitmap (index)) ==NULL || + (index->blobs = index->read_bitmap (index)) ==NULL || + (index->tags = index->read_bitmap (index)) ==NULL ) +return -1 ;
As usual, please use !() instead of explicitly comparing with NULL. It looks like I'll get to find out why you have four different bitmaps set to the same thing (?) soon; exciting!
pack-bitmap.c line 290
Quoted 4 lines
pack-bitmap.c new file +4
-0+if (load_bitmap_entries_v2 (index) <0 ) +return -1 ; + + index->loaded = true;
Fine. This function calls out to various little parsing functions and sets index->loaded. It returns -1 instead of error(), because those little functions report the errors.
Quoted 1 line
+char *pack_bitmap_filename(struct
packed_git*p)
Compare with sha1_name.c:open_pack_index().
Quoted 1 line
+int
open_pack_bitmap(struct packed_git *p)
Okay.
Quoted 1 line
+void
prepare_bitmap_git(void)
Okay.
pack-bitmap.c line 339
Quoted 4 lines
pack-bitmap.c new file +4
-0+struct include_data { +struct bitmap *base; +struct bitmap *seen; +};
I wonder what this is.
Quoted 1 line
+static inline int
bitmap_position_extended(const unsigned char *sha1)
Sorry, I'm stopping here. It's impossible to review this gigantic patch in one sitting.
Thanks.
PATCH 11/16 rev-list: add bitmap mode to speed up lists
In reply to Vicent MartiThe bitmap reachability index used to speed up the counting objects phase during pack-objects can also be used to optimize a normal rev-list if the only thing required are the SHA1s of the objects during the list.
Calling git rev-list --use-bitmaps [committish] is the equivalent of git rev-list --objects, but the rev list is performed based on a bitmap result instead of using a manual counting objects phase.
These are some example timings for torvalds/linux:
$ time ../git/git rev-list --objects master > /dev/null
real 0m25.567s user 0m25.148s sys 0m0.384s
$ time ../git/git rev-list --use-bitmaps master > /dev/null
real 0m0.393s user 0m0.356s sys 0m0.036s
Additionally, a --test-bitmap flag has been added that will perform the same rev-list manually (i.e. using a normal revwalk) and using bitmaps, and verify that the results are the same.
--- builtin/rev-list.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
builtin/rev-list.c +27 -1
@@ -3,6 +3,8 @@#include "diff.h" #include "revision.h" #include "list-objects.h" +#include "pack.h" +#include "pack-bitmap.h" #include "builtin.h" #include "log-tree.h" #include "graph.h"
@@ -256,6 +258,17 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)return 0 ; } +static int show_object_fast ( +const unsigned char *sha1, +enum object_type type, +uint32_t hash,int exclude, +struct packed_git *found_pack, +off_t found_offset) +{ +fprintf (stdout,"%ss\n" ,sha1_to_hex (sha1)); +return 1 ; +} +int cmd_rev_list (int argc,const char **argv,const char *prefix) {struct rev_info revs;
@@ -264,6 +277,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)int bisect_list =0 ;int bisect_show_vars =0 ;int bisect_find_all =0 ; +int use_bitmaps =0 ;git_config (git_default_config,NULL );init_revisions (&revs, prefix);
@@ -305,8 +319,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) bisect_show_vars =1 ;continue ; } +if (!strcmp (arg,"--use-bitmaps" )) { + use_bitmaps =1 ; +continue ; + } +if (!strcmp (arg,"--test-bitmap" )) { +test_bitmap_walk (&revs); +return 0 ; + }usage (rev_list_usage); - }if (revs.commit_format !=CMIT_FMT_UNSPECIFIED ) {/* The command line has a --pretty */
@@ -332,6 +353,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)if (bisect_list) revs.limited =1 ; +if (use_bitmaps && !prepare_bitmap_walk (&revs,NULL )) { +traverse_bitmap_commit_list (&show_object_fast); +return 0 ; + } +if (prepare_revision_walk (&revs))die ("revision walk setup failed" );if (revs.tree_objects)
Signature · 1 line
1.7.9.5
Re: [PATCH 11/16] rev-list: add bitmap mode to speed up lists
Quoted 3 lines · Vicent Marti
Calling
git rev-list --use-bitmaps [committish]is the equivalent ofgit rev-list --objects, but the rev list is performed based on a bitmap result instead of using a manual counting objects phase.
Why would we ever want to not --use-bitmaps, once it actually works? I.e., shouldn't this be the default if pack.usebitmaps is set (or possibly even core.usebitmaps for these things)?
Quoted 8 lines
These are some example timings for
torvalds/linux:$ time ../git/git rev-list --objects master > /dev/nullreal 0m25.567s user 0m25.148s sys 0m0.384s
Quoted 5 lines
$ time ../git/git rev-list --use-bitmaps master > /dev/nullreal 0m0.393s user 0m0.356s sys 0m0.036s
I see your badass numbers, and raise you a critical issue:
$ time git rev-list --use-bitmaps --count --left-right origin/pu...origin/next Segmentation fault
real 0m0.408s user 0m0.383s sys 0m0.022s
It actually seems to be related solely to having negated commits in the walk:
thomas@linux-k42r:~/g(next u+65)$ time git rev-list --use-bitmaps --count origin/pu 32315 real 0m0.041s user 0m0.034s sys 0m0.006s thomas@linux-k42r:~/g(next u+65)$ time git rev-list --use-bitmaps --count origin/pu ^origin/next Segmentation fault
real 0m0.460s user 0m0.214s sys 0m0.244s
I also can't help noticing that the time spent generating the segfault would have sufficed to generate the answer "the old way" as well:
$ time git rev-list --count --left-right origin/pu...origin/next 189 125
real 0m0.409s user 0m0.386s sys 0m0.022s
Can we use the same trick to speed up merge base computation and then --left-right? The latter is a component of __git_ps1 and can get somewhat slow in some cases, so it would be nice to make it really fast, too.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 11/16] rev-list: add bitmap mode to speed up lists
I'm afraid I cannot reproduce the segfault locally (assuming you're performing the rev-list on the git/git repository). Could you please send me more information, and a core dump if possible?
Quoted 67 lines · Thomas Rast
Quoted 3 lines · Vicent Marti
Calling
git rev-list --use-bitmaps [committish]is the equivalent ofgit rev-list --objects, but the rev list is performed based on a bitmap result instead of using a manual counting objects phase.Why would we ever want to not --use-bitmaps, once it actually works? I.e., shouldn't this be the default if pack.usebitmaps is set (or possibly even core.usebitmaps for these things)?
Quoted 8 lines
These are some example timings for
torvalds/linux:$ time ../git/git rev-list --objects master > /dev/nullreal 0m25.567s user 0m25.148s sys 0m0.384sQuoted 5 lines
$ time ../git/git rev-list --use-bitmaps master > /dev/nullreal 0m0.393s user 0m0.356s sys 0m0.036sI see your badass numbers, and raise you a critical issue:
$ time git rev-list --use-bitmaps --count --left-right origin/pu...origin/next Segmentation faultreal 0m0.408s user 0m0.383s sys 0m0.022sIt actually seems to be related solely to having negated commits in the walk:
thomas@linux-k42r:~/g(next u+65)$ time git rev-list --use-bitmaps --count origin/pu 32315 real 0m0.041s user 0m0.034s sys 0m0.006s thomas@linux-k42r:~/g(next u+65)$ time git rev-list --use-bitmaps --count origin/pu ^origin/next Segmentation faultreal 0m0.460s user 0m0.214s sys 0m0.244sI also can't help noticing that the time spent generating the segfault would have sufficed to generate the answer "the old way" as well:
$ time git rev-list --count --left-right origin/pu...origin/next 189 125real 0m0.409s user 0m0.386s sys 0m0.022sCan we use the same trick to speed up merge base computation and then --left-right? The latter is a component of
__git_ps1and can get somewhat slow in some cases, so it would be nice to make it really fast, too.--
Thomas Rast
trast@{inf,student}.ethz.ch
Re: [PATCH 11/16] rev-list: add bitmap mode to speed up lists
In reply to Thomas RastQuoted 9 lines · Thomas Rast
Quoted 3 lines · Vicent Marti
Calling
git rev-list --use-bitmaps [committish]is the equivalent ofgit rev-list --objects, but the rev list is performed based on a bitmap result instead of using a manual counting objects phase.Why would we ever want to not --use-bitmaps, once it actually works? I.e., shouldn't this be the default if pack.usebitmaps is set (or possibly even core.usebitmaps for these things)?
If you are using bitmaps, you cannot produce the same output as "--objects"; the latter prints the path at which each object is found. In the JGit bitmap format, we have no information at all; in Vicent's "v2", we have only a hash of that pathname.
-Peff
PATCH 12/16 pack-objects: implement bitmap writing
In reply to Vicent MartiThis commit extends more the functionality of pack-objects by allowing it to write out a .bitmap index next to any written packs, together with the .idx index that currently gets written.
If bitmaps are enabled for a given repository (either by calling pack-objects with the --use-bitmaps flag or by having pack.usebitmaps set to true in the config) and pack-objects is writing a packfile that would normally be indexed (i.e. not piping to stdout), we will attempt to write the corresponding bitmap index for the packfile.
Bitmap index writing happens after the packfile and its index has been successfully written to disk (finish_tmp_packfile). The process is performed in several steps:
1. bitmap_writer_build_type_index: this call uses the array of struct object_entryes that has just been sorted when writing out the actual packfile index to disk to generate 4 type-index bitmaps (one for each object type).
These bitmaps have their nth bit set if the given object is of the bitmap's type. E.g. the nth bit of the Commits bitmap will be 1 if the nth object in the packfile index is a commit.
This is a very cheap operation because the bitmap writing code has access to the metadata stored in the struct object_entry array, and hence the real type for each object in the packfile.
2. bitmap_writer_select_commits: if bitmap writing is enabled for a given pack-objects run, the sequence of commits generated during the Counting Objects phase will be stored in an array.
We then use that array to build up the list of selected commits. Writing a bitmap in the index for each object in the repository would be cost-prohibitive, so we use a simple heuristic to pick the commits that will be indexed with bitmaps.
The current heuristics are a simplified version of JGit's original implementation. We select a higher density of commits depending on their age: the 100 most recent commits are always selected, after that we pick 1 commit of each 100, and the gap increases as the commits grow older. On top of that, we make sure that every single branch that has not been merged (all the tips that would be required from a clone) gets their own bitmap, and when selecting commits between a gap, we tend to prioritize the commit with the most parents.
Do note that there is no right/wrong way to perform commit selection; different selection algorithms will result in different commits being selected, but there's no such thing as "missing a commit". The bitmap walker algorithm implemented in prepare_bitmap_walk is able to adapt to missing bitmaps by performing manual walks that complete the bitmap: the ideal selection algorithm, however, would select the commits that are more likely to be used as roots for a walk in the future (e.g. the tips of each branch, and so on) to ensure a bitmap for them is always available.
3. bitmap_writer_build: this is the computationally expensive part of bitmap generation. Based on the list of commits that were selected in the previous step, we perform several incremental walks to generate the bitmap for each commit.
The walks begin from the oldest commit, and are built up incrementally for each branch. E.g. consider this dag where A, B, C, D, E, F are the selected commits, and a, b, c, e are a chunk of simplified history that will not receive bitmaps.
A---a---B--b--C--c--D
\
E--e--F
We start by building the bitmap for A, using A as the root for a revision walk and marking all the objects that are reachable until the walk is over. Once this bitmap is stored, we reuse the bitmap walker to perform the walk for B, assuming that once we reach A again, the walk will be terminated because A has already been SEEN on the previous walk.
This process is repeated for C, and D, but when we try to generate the bitmaps for E, we cannot reuse neither the current walk nor the bitmap we have generated so far.
What we do now is resetting both the walk and clearing the bitmap, and performing the walk from scratch using E as the origin. This new walk, however, does not need to be completed. Once we hit B, we can lookup the bitmap we have already stored for that commit and OR it with the existing bitmap we've composed so far, allowing us to limit the walk early.
After all the bitmaps have been generated, another iteration through the list of commits is performed to find the best XOR offsets for compression before writing them to disk. Because of the incremental nature of these bitmaps, XORing one of them with its predecesor results in a minimal "bitmap delta" most of the time. We can write this delta to the on-disk bitmap index, and then re-compose the original bitmaps by XORing them again when loaded.
This is a phase very similar to pack-object's find_delta (using bitmaps instead of objects, of course), except the heuristics have been greatly simplified: we only check the 10 bitmaps before any given one to find best compressing one. This operation gives optimal results (again, because of the incremental nature of the bitmaps) and has a very good runtime performance because of the way EWAH bitmaps are implemented.
3. bitmap_writer_finish: the last step in the process is serializing to disk all the bitmap data that has been generated in the two previous steps.
The bitmap is written to a tmp file and then moved atomically to its final destination, using the same process as pack-write.c:write_idx_file.
--- Makefile | 1 + builtin/pack-objects.c | 117 +++++++---- builtin/pack-objects.h | 33 +++ pack-bitmap-write.c | 520 ++++++++++++++++++++++++++++++++++++++++++++++++ pack-bitmap.h | 9 + pack-write.c | 2 + 6 files changed, 646 insertions(+), 36 deletions(-) create mode 100644 builtin/pack-objects.h create mode 100644 pack-bitmap-write.c
Makefile +1 -0
@@ -840,6 +840,7 @@ LIB_OBJS += notes-cache.o LIB_OBJS += notes-merge.o LIB_OBJS += object.o LIB_OBJS += pack-bitmap.o +LIB_OBJS += pack-bitmap-write.o LIB_OBJS += pack-check.o LIB_OBJS += pack-revindex.o LIB_OBJS += pack-write.o
builtin/pack-objects.c +81 -36
204 lines not on this page · raw message
builtin/pack-objects.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef BUILTIN_PACK_OBJECTS_H +#define BUILTIN_PACK_OBJECTS_H + +struct object_entry { +struct pack_idx_entry idx; +unsigned long size;/* uncompressed size */ +struct packed_git *in_pack;/* already in pack */ +off_t in_pack_offset; +struct object_entry *delta;/* delta base object */ +struct object_entry *delta_child;/* deltified objects who bases me */ +struct object_entry *delta_sibling;/* other deltified objects who +* uses the same base as me +*/ +void *delta_data;/* cached delta (uncompressed) */ +unsigned long delta_size;/* delta data size (uncompressed) */ +unsigned long z_delta_size;/* delta data size (compressed) */ +unsigned int hash;/* name hint hash */ + +enum object_type type; +enum object_type in_pack_type; +enum object_type real_type; + +unsigned int index_pos; + +unsigned char in_pack_header_size; +unsigned char preferred_base; +unsigned char no_try_delta; +unsigned char tagged; +unsigned char filled; +unsigned char refered; +}; + +#endif
pack-bitmap-write.c new file +520 -0
520 lines not on this page · raw message
pack-bitmap.h +9 -0
@@ -31,6 +31,8 @@ struct bitmap_disk_header {static const char BITMAP_MAGIC_PREFIX [] = {'B' ,'I' ,'T' ,'M' };; +#define NEEDS_BITMAP (1u<<22) +enum pack_bitmap_opts {BITMAP_OPT_FULL_DAG =1 ,BITMAP_OPT_LE_BITMAPS =2 ,
@@ -50,4 +52,11 @@ int prepare_bitmap_walk(struct rev_info *revs, uint32_t *result_size);void test_bitmap_walk (struct rev_info *revs);char *pack_bitmap_filename (struct packed_git *p); +void bitmap_writer_show_progress (int show); +void bitmap_writer_build_type_index (struct pack_idx_entry **index,uint32_t index_nr); +void bitmap_writer_select_commits (struct commit **indexed_commits, +unsigned int indexed_commits_nr,int max_bitmaps); +void bitmap_writer_build (khash_sha1 *packed_objects); +void bitmap_writer_finish (const char *filename,unsigned char sha1[],uint16_t flags); +#endif
pack-write.c +2 -0
@@ -371,5 +371,7 @@ void finish_tmp_packfile(char *name_buffer,if (rename (idx_tmp_name, name_buffer))die_errno ("unable to rename temporary index file" ); + *end_of_name_prefix ='\0' ; +free ((void *)idx_tmp_name); }
Signature · 1 line
1.7.9.5
PATCH 13/16 repack: consider bitmaps when performing repacks
In reply to Vicent MartiSince pack-objects will write a .bitmap file next to the .pack and .idx files, this commit teaches git-repack to consider the new bitmap indexes (if they exist) when performing repack operations.
This implies moving old bitmap indexes out of the way if we are repacking a repository that already has them, and moving the newly generated bitmap indexes into the objects/pack directory, next to their corresponding packfiles.
Since git repack is now capable of handling these .bitmap files, a normal git gc run on a repository that has pack.usebitmaps set to true in its config file will generate bitmap indexes as part of the garbage collection process.
--- git-repack.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
git-repack.sh +8 -2
@@ -108,7 +108,7 @@ rollback= failed= for name in $names do - for sfx in pack idx + for sfx in pack idx bitmap do file=pack-$name.$sfx test -f "$PACKDIR/$file" || continue
@@ -156,6 +156,11 @@ do fullbases="$fullbases pack-$name" chmod a-w "$PACKTMP-$name.pack" chmod a-w "$PACKTMP-$name.idx" + + test -f "$PACKTMP-$name.bitmap" && + chmod a-w "$PACKTMP-$name.bitmap" && + mv -f "$PACKTMP-$name.bitmap" "$PACKDIR/pack-$name.bitmap" + mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" && mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" || exit
@@ -166,6 +171,7 @@ for name in $names do rm -f "$PACKDIR/old-pack-$name.idx" rm -f "$PACKDIR/old-pack-$name.pack" + rm -f "$PACKDIR/old-pack-$name.bitmap" done # End of pack replacement.
@@ -180,7 +186,7 @@ then do case " $fullbases " in *" $e "*) ;; - *) rm -f "$e.pack" "$e.idx" "$e.keep" ;; + *) rm -f "$e.pack" "$e.idx" "$e.keep" "$e.bitmap" ;; esac done )
Signature · 1 line
1.7.9.5
Re: [PATCH 13/16] repack: consider bitmaps when performing repacks
git-repack.sh do · line 162
Quoted 8 lines · Vicent Marti
git-repack.sh +4
-0@@ -156,6 +156,11 @@ do fullbases="$fullbases pack-$name" chmod a-w "$PACKTMP-$name.pack" chmod a-w "$PACKTMP-$name.idx" + + test -f "$PACKTMP-$name.bitmap" && + chmod a-w "$PACKTMP-$name.bitmap" && + mv -f "$PACKTMP-$name.bitmap" "$PACKDIR/pack-$name.bitmap"
If we see a temporary bitmap but somehow failed to move it to the final name, should we _ignore_ that error, or should we die, like the next two lines do?
Quoted 3 lines
git-repack.sh +0
-0mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" && mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" || exit
Re: [PATCH 13/16] repack: consider bitmaps when performing repacks
Quoted 4 lines · Junio C Hamano
Quoted 4 lines
git-repack.sh +0
-0@@ -156,6 +156,11 @@ do fullbases="$fullbases pack-$name" chmod a-w "$PACKTMP-$name.pack" chmod a-w "$PACKTMP-$name.idx"
Quoted 8 lines
git-repack.sh do · line 162
Quoted 4 lines
git-repack.sh +4
-0+ + test -f "$PACKTMP-$name.bitmap" && + chmod a-w "$PACKTMP-$name.bitmap" && + mv -f "$PACKTMP-$name.bitmap" "$PACKDIR/pack-$name.bitmap"If we see a temporary bitmap but somehow failed to move it to the final name, should we _ignore_ that error, or should we die, like the next two lines do?
I obviously decided against dying (as you can see on the patch, har har), because the bitmap is not required for the proper operation of the Git repository, unlike the packfile and the index.
PATCH 14/16 sha1_file: implement `nth_packed_object_info`
In reply to Vicent MartiA new helper function allows to efficiently query the size and real type of an object in a packfile based on its position on the packfile index.
This is particularly useful when trying to parse all the information of an index in memory.
--- cache.h | 1 + sha1_file.c | 6 ++++++ 2 files changed, 7 insertions(+)
cache.h +1 -0
@@ -1104,6 +1104,7 @@ extern void clear_delta_base_cache(void);extern struct packed_git *add_packed_git (const char *,int ,int );extern const unsigned char *nth_packed_object_sha1 (struct packed_git *,uint32_t );extern off_t nth_packed_object_offset (const struct packed_git *,uint32_t ); +extern int nth_packed_object_info (struct packed_git *p,uint32_t n,unsigned long *sizep);extern int find_pack_entry_pos (const unsigned char *sha1,struct packed_git *p);extern off_t find_pack_entry_one (const unsigned char *,struct packed_git *);extern int is_pack_valid (struct packed_git *);
sha1_file.c +6 -0
@@ -2223,6 +2223,12 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n) } } +int nth_packed_object_info (struct packed_git *p,uint32_t n,unsigned long *sizep) +{ +off_t offset =nth_packed_object_offset (p, n); +return packed_object_info (p, offset, sizep,NULL ); +} +int find_pack_entry_pos (const unsigned char *sha1,struct packed_git *p) {const uint32_t *level1_ofs = p->index_data;
Signature · 1 line
1.7.9.5
PATCH 15/16 write-bitmap: implement new git command to write bitmaps
In reply to Vicent MartiThe pack-objects builtin is capable of writing out bitmap indexes (.bitmap) next to the their corresponding packfile, as part of the process of actually generating the packfile.
This is a very efficient operation because all the required data for writing the bitmap index (commit traversal list, list of all objects in a packfile, sorted index for the packfile, and types for all objects in the packfile) is readily available in memory as part of the process of building the packfile itself.
There are however cases when we want to generate a bitmap index for a packfile that already exists on disk (i.e. one we're not writing from scratch). This new git builtin implements the bitmap index equivalent of git index-pack: it writes a .bitmap file given a pair of existing .pack and .idx files.
NOTE that write-bitmap requires the packfile to have been indexed beforehand. If the packfile doesn't have its corresponding .idx file, git index-pack must be called before write-bitmap can work.
The process of generating bitmaps for an existing packfile is as follows:
1. Load the existing pack index in memory. The .idx for the packfile is loaded into a hash table in mememory so it can be efficiently queried. As part of this loading process, the real type for each object in the packfile is resolved (this implies resolving deltas, which can make this process rather expensive).
2. Find the full closure for the packfile. All the objects from the packfile that have been loaded in memory are iterated, looking for commits. These commits are parsed, and their parents are marked as such to ensure that
a) there is a full closure in the packfile, and no commit has a dangling parent pointer
b) we can find the set of "tips" for the packfile, i.e., the set of commits that don't have any commits pointing to them
3. The "tips" of the packfile are then used as the roots to perform a normal revision walk. The result of this revision walk is the list of commits that will be used by bitmap_writer_select_commits when selecting which commits are going to be bitmapped.
4. We build and write the bitmap index in the same way that pack-objects does, given that we have all the required metadata:
- an array of all the objects in the packfile, in index order
- the types of all these objects
- an array with a walk-ordering of all the commits in the packfile, which will be used for selection
- a hash table to efficiently look up objects in the index
See the previous patch "pack-objects: implement bitmap writing" for details on how the bitmap computation happens.
--- Makefile | 1 + builtin.h | 1 + builtin/write-bitmap.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++++ git.c | 1 + 4 files changed, 259 insertions(+) create mode 100644 builtin/write-bitmap.c
Makefile +1 -0
@@ -1000,6 +1000,7 @@ BUILTIN_OBJS += builtin/upload-archive.o BUILTIN_OBJS += builtin/var.o BUILTIN_OBJS += builtin/verify-pack.o BUILTIN_OBJS += builtin/verify-tag.o +BUILTIN_OBJS += builtin/write-bitmap.o BUILTIN_OBJS += builtin/write-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
builtin.h +1 -0
@@ -144,6 +144,7 @@ extern int cmd_var(int argc, const char **argv, const char *prefix);extern int cmd_verify_tag (int argc,const char **argv,const char *prefix);extern int cmd_version (int argc,const char **argv,const char *prefix);extern int cmd_whatchanged (int argc,const char **argv,const char *prefix); +extern int cmd_write_bitmap (int argc,const char **argv,const char *prefix);extern int cmd_write_tree (int argc,const char **argv,const char *prefix);extern int cmd_verify_pack (int argc,const char **argv,const char *prefix);extern int cmd_show_ref (int argc,const char **argv,const char *prefix);
builtin/write-bitmap.c new file +256 -0
256 lines not on this page · raw message
git.c +1 -0
@@ -426,6 +426,7 @@ static void handle_internal_command(int argc, const char **argv) { "verify-tag", cmd_verify_tag, RUN_SETUP }, { "version", cmd_version }, { "whatchanged", cmd_whatchanged, RUN_SETUP }, + { "write-bitmap", cmd_write_bitmap, RUN_SETUP }, { "write-tree", cmd_write_tree, RUN_SETUP }, };int i;
Signature · 1 line
1.7.9.5
PATCH 16/16 rev-list: Optimize --count using bitmaps too
In reply to Vicent MartiIf bitmap indexes are available, the process of counting reachable commits with git rev-list --count can be greatly sped up. Instead of having to use callbacks that yield each object in the revision list, we can build the reachable bitmap for the list and then use an efficient popcount to find the number of bits set in the bitmap.
This commit implements a count_bitmap_commit_list that can be used after prepare_bitmap_walk has returned successfully to return the number of commits, trees, blobs or tags that have been found to be reachable during the walk.
git rev-list is taught to use this function call when bitmaps are enabled instead of going through the old rev-list machinery. Do note, however, that counts with left_right and cherry_mark are not optimized by this patch.
Here are some sample timings of different ways to count commits in torvalds/linux:
$ time ../git/git rev-list master | wc -l 376549
real 0m6.973s user 0m3.216s sys 0m5.316s
$ time ../git/git rev-list --count master 376549
real 0m1.933s user 0m1.744s sys 0m0.188s
$ time ../git/git rev-list --use-bitmaps --count master 376549
real 0m0.005s user 0m0.000s sys 0m0.004s
Note that the time in the --use-bitmaps invocation is basically noise. In my machine it ranges from 2ms to 6ms.
--- builtin/rev-list.c | 11 +++++++++-- pack-bitmap.c | 37 +++++++++++++++++++++++++++++++++++++ pack-bitmap.h | 2 ++ 3 files changed, 48 insertions(+), 2 deletions(-)
builtin/rev-list.c +9 -2
@@ -354,8 +354,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) revs.limited =1 ;if (use_bitmaps && !prepare_bitmap_walk (&revs,NULL )) { -traverse_bitmap_commit_list (&show_object_fast); -return 0 ; +if (revs.count && !revs.left_right && !revs.cherry_mark) { +uint32_t commit_count; +count_bitmap_commit_list (&commit_count,NULL ,NULL ,NULL ); +printf ("%d\n" , commit_count); +return 0 ; + }else { +traverse_bitmap_commit_list (&show_object_fast); +return 0 ; + } }if (prepare_revision_walk (&revs))
pack-bitmap.c +37 -0
@@ -720,6 +720,43 @@ void traverse_bitmap_commit_list(show_reachable_fn show_reachable) bitmap_git.result =NULL ; } +static uint32_t count_object_type ( +struct bitmap *objects, +struct ewah_bitmap *type_filter) +{ +size_t i =0 , count =0 ; +struct ewah_iterator it; +eword_t filter; + +ewah_iterator_init (&it, type_filter); + +while (i < objects->word_alloc &&ewah_iterator_next (&filter, &it)) { +eword_t word = objects->words[i++] & filter; + count +=__builtin_popcountll (word); + } + +return count; +} + +void count_bitmap_commit_list ( +uint32_t *commits,uint32_t *trees,uint32_t *blobs,uint32_t *tags) +{ +if (!bitmap_git.result) +die ("Tried to count bitmap without setting it up first" ); + +if (commits) + *commits =count_object_type (bitmap_git.result, bitmap_git.commits); + +if (trees) + *trees =count_object_type (bitmap_git.result, bitmap_git.trees); + +if (blobs) + *blobs =count_object_type (bitmap_git.result, bitmap_git.blobs); + +if (tags) + *tags =count_object_type (bitmap_git.result, bitmap_git.tags); +} +struct bitmap_test_data {struct bitmap *base;struct progress *prg;
pack-bitmap.h +2 -0
@@ -47,6 +47,8 @@ typedef int (*show_reachable_fn)(struct packed_git *found_pack, off_t found_offset); +void count_bitmap_commit_list ( +uint32_t *commits,uint32_t *trees,uint32_t *blobs,uint32_t *tags);void traverse_bitmap_commit_list (show_reachable_fn show_reachable);int prepare_bitmap_walk (struct rev_info *revs,uint32_t *result_size);void test_bitmap_walk (struct rev_info *revs);
Signature · 1 line
1.7.9.5
Quoted 3 lines · Vicent Marti
Like with every other patch that offers performance improvements, sample benchmarks are provided (spoiler: they are pretty fucking cool).
Great stuff.
I read the first half, and skimmed the second half. See the individual replies for comments.
However:
Quoted 18 lines
Documentation/technical/bitmap-format.txt | 235 ++++++++ Makefile | 11 + builtin.h | 1 + builtin/pack-objects.c | 362 +++++++----- builtin/pack-objects.h | 33 ++ builtin/rev-list.c | 35 +- builtin/write-bitmap.c | 256 +++++++++ cache.h | 5 + ewah/bitmap.c | 229 ++++++++ ewah/ewah_bitmap.c | 703 ++++++++++++++++++++++++ ewah/ewah_io.c | 199 +++++++ ewah/ewah_rlw.c | 124 +++++ ewah/ewok.h | 194 +++++++ ewah/ewok_rlw.h | 114 ++++ git-compat-util.h | 28 + git-repack.sh | 10 +- git.c | 1 + khash.h | 329 +++++++++++
Quoted 8 lines
list-objects.c | 1 + pack-bitmap-write.c | 520 ++++++++++++++++++ pack-bitmap.c | 855 +++++++++++++++++++++++++++++ pack-bitmap.h | 64 +++ pack-write.c | 2 + revision.c | 5 + revision.h | 2 + sha1_file.c | 57 +-
It's pretty hard to miss that there isn't a single test in the entire series. It seems that the features you add depend on pack.usebitmaps, and since the tests run with empty config (unless of course they set their own) your feature is completely untested -- unless I'm missing something.
I imagine the tests would be of the format
test_expect_success 'do <stuff> without bitmaps' '
git ... >expect
'
test_expect_success 'do <stuff> with bitmaps' '
test_config pack.usebitmaps true && # do something to ensure that we have bitmaps git ... >actual && test_cmp expect actual
'
or some such.
For bonus points, you could also add some light performance tests in t/perf/, just to show off ;-)
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 07/16] compat: add endinanness helpers
In reply to Vicent MartíVicent Martí:
Quoted 1 line
I'm aware of that, but Git needs to build with glibc 2.7+ (or was it 2.6?), hence the need for this compat layer.
Right. But perhaps the compatibility layer could provide the functionality with the names available in the later glibc versions (and on *BSD)? That would make it easier to read the code that is using it.
Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Vicent MartíQuoted 10 lines · Vicent Martí
Quoted 2 lines · Thomas Rast
Please document the RLW format here.
Har har. I was going to comment on your review of the Ewah patchset, but might as well do it here: the only thing I know about Ewah bitmaps is that they work. And I know this because I did extensive fuzz testing of my C port. Unfortunately, the original Java code I ported from has 0 comments, so any documentation here would have to be reverse-engineered.
I think the below would be a reasonable documentation, to be appended after your description of the EWAH format. Maybe Colby can correct me if I got anything wrong. You can basically read this off from the implementation of ewah_each_bit() and the helper functions it uses.
-- 8< --
The compressed bitmap is stored in a form of run-length encoding, as follows. It consists of a concatenation of an arbitrary number of chunks. Each chunk consists of one or more 64-bit words
H L_1 L_2 L_3 .... L_M
H is called RLW (run length word). It consists of (from lower to higher order bits):
- 1 bit: the repeated bit B
- 32 bits: repetition count K (unsigned)
- 31 bits: literal word count M (unsigned)
The bitstream represented by the above chunk is then:
- K repetitions of B
- The bits stored in L_1 through L_M. Within a word, bits at lower order come earlier in the stream than those at higher order.
The next word after L_M (if any) must again be a RLW, for the next chunk. For efficient appending to the bitstream, the EWAH stores a format to the last RLW in the stream.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 09/16] documentation: add documentation for the bitmap format
Thomas Rast <[email protected]> writes:
[...]
Quoted 3 lines
The next word after
L_M(if any) must again be a RLW, for the next chunk. For efficient appending to the bitstream, the EWAH stores a format to the last RLW in the stream.
^^^^^^
I have no idea what Freud did there, but "pointer" or some such is probably a saner choice.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Vicent MartíQuoted 11 lines · Vicent Martí
Quoted 7 lines · Junio C Hamano
What case are you talking about?
The n-th object must be one of these four types and can never be of more than one type at the same time, so a natural expectation from the reader is "If you OR them together, you will get the same set". If you say "If you XOR them", that forces the reader to wonder when these bitmaps ever can overlap at the same bit position.
I guess this is just wording. I don't particularly care about the distinction, but I'll change it to OR.
Hmm, OK. If you think XOR and OR are the same operation, I also have a bridge to sell you. Its in Brooklyn. Its a great value.
The correct operation is OR. Not XOR. OR. Drop the X.
Quoted 4 lines
It cannot be mmapped not particularly because of endianness issues, but because the original format is not indexed and requires a full parse of the whole index before it can be accessed programatically. The wrong endianness just increases the parse time.
Wrong endianness has nothing to do with the parse time. Modern CPUs can flip a word around very quickly. In JGit we chose to parse the file at load time because its simpler than having an additional index segment, and we do what you did which is to toss the object SHA-1s into a hashtable for fast lookup. By the time we look for the SHA-1s and toss them into a hashtable we can stride through the file and find the bitmap regions. Simple.
In other words, the least complex solution possible that still provides good performance. I'd say we have pretty good performance.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
and I'm going to try to make it run fast enough in that encoding.
Hmph. Is it an option to start from what JGit does, so that people can use both JGit and your code on the same repository?
I'm afraid I agree here with Junio. The JGit format is already shipping in JGit 3.0, Gerrit Code Review 2.6, and in heavy production use for almost a year on android.googlesource.com, and Google's own internal Git trees.
I would prefer to see a series adding bitmap support to C Git start with the existing format, make it run, taking advantage of the optimizations JGit uses (many of which you ignored and tried to "fix" in other ways), and then look at improving the file format itself if load time is still the largest low hanging fruit in upload-pack. I'm guessing its not. You futzed around with the object table, but JGit sped itself up considerably by simply not using the object table when the bitmap is used. I think there are several such optimizations you missed in your rush to redefine the file format.
Quoted 11 lines
Quoted 4 lines
And then if
you do not succeed, after trying to optimize in-core processing using that on-disk format to make it fast enough, start thinking about tweaking the on-disk format?I'm afraid this is not an option. I have an old patchset that implements JGit v1 bitmap loading (and in fact that's how I initially developed these series -- by loading the bitmaps from JGit for debugging), but I discarded it because it simply doesn't pan out in production. ~3 seconds time to spawn
upload-packis not an option for us. I did not develop a tweaked on-disk format out of boredom.
I think your code or experiments are bogus. Even on our systems with JGit a cold start for the Linux kernel doesn't take 3s. And this is JGit where Java is slow because "Jesus it has a lot of factories", and without mmap'ing the file into the server's address space. Hell the file has to come over the network from a remote disk array.
Quoted 6 lines
I could dig up the patch if you're particularly interested in backwards compatibility, but since it was several times slower than the current iteration, I have no interest (time, actually) to maintain it, brush it up, and so on. I have already offered myself to port the v2 format to JGit as soon as it's settled. It sounds like a better investment of all our times.
Actually, I think the format you propose here is inferior to the JGit format. In particular the idx-ordering means the EWAH code is useless. You might as well not use the EWAH format and just store 2.6M bits per commit. The idx-ordering also makes *much* harder to emit a pack file a reasonable order for the client. Colby and I tried idx-ordering and discarded it when it didn't perform as well as the pack-ordering that JGit uses.
Quoted 5 lines
Following up on Shawn's comments, I removed the little-endian support from the on-disk format and implemented lazy loading of the bitmaps to make up for it. The result is decent (slowed down from 250ms to 300ms) and it lets us keep the whole format as NWO on disk. I think it's a good tradeback.
The maintenance burden of two endian formats in a single file is too high to justify. I'm glad to see you saw that.
Quoted 3 lines
As it stands right now, the only two changes from v1 of the on-disk format are:
- There is an index at the end. This is a good idea.
I don't think the index is necessary if you plan to build a hashtable at runtime anyway. If you mmap the file you can quickly skip over a bitmap and find the next SHA-1 using this thing called "pointer arithmetic". I am not sure if you are familiar with the term, perhaps you could search the web for it.
Quoted 2 lines
- The bitmaps are sorted in packfile-index order, not in packfile order. This is a good idea.
As Colby and I have repeatedly tried to explain, this is not a good idea.
Quoted 1 line
German kisses,
Strawberry and now German kisses? What's next, Mango kisses?
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
That was a very rude reply. :(
Please refrain from interacting with me in the ML in the future. I'l do accordingly.
Thanks!
vmg
Quoted 115 lines · Shawn Pearce
Quoted 11 lines · Vicent Martí
Quoted 7 lines · Junio C Hamano
What case are you talking about?
The n-th object must be one of these four types and can never be of more than one type at the same time, so a natural expectation from the reader is "If you OR them together, you will get the same set". If you say "If you XOR them", that forces the reader to wonder when these bitmaps ever can overlap at the same bit position.
I guess this is just wording. I don't particularly care about the distinction, but I'll change it to OR.
Hmm, OK. If you think XOR and OR are the same operation, I also have a bridge to sell you. Its in Brooklyn. Its a great value.
The correct operation is OR. Not XOR. OR. Drop the X.
Quoted 4 lines
It cannot be mmapped not particularly because of endianness issues, but because the original format is not indexed and requires a full parse of the whole index before it can be accessed programatically. The wrong endianness just increases the parse time.
Wrong endianness has nothing to do with the parse time. Modern CPUs can flip a word around very quickly. In JGit we chose to parse the file at load time because its simpler than having an additional index segment, and we do what you did which is to toss the object SHA-1s into a hashtable for fast lookup. By the time we look for the SHA-1s and toss them into a hashtable we can stride through the file and find the bitmap regions. Simple.
In other words, the least complex solution possible that still provides good performance. I'd say we have pretty good performance.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
and I'm going to try to make it run fast enough in that encoding.
Hmph. Is it an option to start from what JGit does, so that people can use both JGit and your code on the same repository?
I'm afraid I agree here with Junio. The JGit format is already shipping in JGit 3.0, Gerrit Code Review 2.6, and in heavy production use for almost a year on android.googlesource.com, and Google's own internal Git trees.
I would prefer to see a series adding bitmap support to C Git start with the existing format, make it run, taking advantage of the optimizations JGit uses (many of which you ignored and tried to "fix" in other ways), and then look at improving the file format itself if load time is still the largest low hanging fruit in upload-pack. I'm guessing its not. You futzed around with the object table, but JGit sped itself up considerably by simply not using the object table when the bitmap is used. I think there are several such optimizations you missed in your rush to redefine the file format.
Quoted 11 lines
Quoted 4 lines
And then if
you do not succeed, after trying to optimize in-core processing using that on-disk format to make it fast enough, start thinking about tweaking the on-disk format?I'm afraid this is not an option. I have an old patchset that implements JGit v1 bitmap loading (and in fact that's how I initially developed these series -- by loading the bitmaps from JGit for debugging), but I discarded it because it simply doesn't pan out in production. ~3 seconds time to spawn
upload-packis not an option for us. I did not develop a tweaked on-disk format out of boredom.I think your code or experiments are bogus. Even on our systems with JGit a cold start for the Linux kernel doesn't take 3s. And this is JGit where Java is slow because "Jesus it has a lot of factories", and without mmap'ing the file into the server's address space. Hell the file has to come over the network from a remote disk array.
Quoted 6 lines
I could dig up the patch if you're particularly interested in backwards compatibility, but since it was several times slower than the current iteration, I have no interest (time, actually) to maintain it, brush it up, and so on. I have already offered myself to port the v2 format to JGit as soon as it's settled. It sounds like a better investment of all our times.
Actually, I think the format you propose here is inferior to the JGit format. In particular the idx-ordering means the EWAH code is useless. You might as well not use the EWAH format and just store 2.6M bits per commit. The idx-ordering also makes *much* harder to emit a pack file a reasonable order for the client. Colby and I tried idx-ordering and discarded it when it didn't perform as well as the pack-ordering that JGit uses.
Quoted 5 lines
Following up on Shawn's comments, I removed the little-endian support from the on-disk format and implemented lazy loading of the bitmaps to make up for it. The result is decent (slowed down from 250ms to 300ms) and it lets us keep the whole format as NWO on disk. I think it's a good tradeback.
The maintenance burden of two endian formats in a single file is too high to justify. I'm glad to see you saw that.
Quoted 3 lines
As it stands right now, the only two changes from v1 of the on-disk format are:
- There is an index at the end. This is a good idea.
I don't think the index is necessary if you plan to build a hashtable at runtime anyway. If you mmap the file you can quickly skip over a bitmap and find the next SHA-1 using this thing called "pointer arithmetic". I am not sure if you are familiar with the term, perhaps you could search the web for it.
Quoted 2 lines
- The bitmaps are sorted in packfile-index order, not in packfile order. This is a good idea.
As Colby and I have repeatedly tried to explain, this is not a good idea.
Quoted 1 line
German kisses,
Strawberry and now German kisses? What's next, Mango kisses?
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 4 lines · Vicent Martí
That was a very rude reply. :(
Please refrain from interacting with me in the ML in the future. I'l do accordingly.
I agree that the pointer arithmetic thing may have been a little much, but I think there are some points we need to address in Shawn's email.
In particular, it seems like the slowness we saw with the v1 bitmap format is not what Shawn and Colby have experienced. So it's possible that our test setup is bad or different. Or maybe the C v1 reading implementation had some problems that are fixable. It's hard to say because we haven't shown any code that can be timed and compared.
And the pack-order versus idx-order for the bitmaps is still up in the air. Do we have numbers on the on-disk sizes of the resulting EWAHs? The pack-order ones should be more amenable to run-length encoding, especially as you get further down into history (the tip ones would mostly be 1's, no matter how you order them).
-Peff
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 6 lines · Jeff King
In particular, it seems like the slowness we saw with the v1 bitmap format is not what Shawn and Colby have experienced. So it's possible that our test setup is bad or different. Or maybe the C v1 reading implementation had some problems that are fixable. It's hard to say because we haven't shown any code that can be timed and compared.
Right, the format and implementation in JGit can do "Counting objects" in 87ms for the Linux kernel history. But I think we are comparing apples to steaks here, Vincent is (rightfully) concerned about process startup performance, whereas our timings were assuming the process was already running.
It would help everyone to understand the issues involved if we are at least looking at the same file format.
Quoted 2 lines
And the pack-order versus idx-order for the bitmaps is still up in the air. Do we have numbers on the on-disk sizes of the resulting EWAHs?
I did not see any presented in this thread, and I am very interested in this aspect of the series. The path hash cache should be taking about 9.9M of disk space, but I recall reading the bitmap file is 8M. I don't understand.
Colby and I were very concerned about the size of the EWAH compressed bitmaps because we wanted hundreds of them for a large history like the kernel, and we wanted to minimize the amount of memory consumed by the bitmap index when loaded into the process.
In the JGit implementation our copy of Linus' tree has 3.1M objects, an 81.5 MiB idx file, and a 3.8 MiB bitmap file. We were trying to keep the overhead below 10% of the idx file, and I think we have succeeded on that. With 3.1M objects the v2 bitmap proposed in this thread needs at least 11.8M, or 14+% overhead just for the path hash cache.
The path hash cache may still be required, Colby and I have been debating the merits of having the data available for delta compression vs. the increase in memory required to hold it.
Quoted 4 lines
The
pack-order ones should be more amenable to run-length encoding, especially as you get further down into history (the tip ones would mostly be 1's, no matter how you order them).
This is also true for the type bitmaps, but especially so in the JGit file ordering where we always write all trees before any blobs. The type bitmaps are very compact and basically amount to defining a single range in the file. This takes only a few words in the EWAH compressed format.
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 7 lines · Shawn O. Pearce
Quoted 2 lines
And the pack-order versus idx-order for the bitmaps is still up in the air. Do we have numbers on the on-disk sizes of the resulting EWAHs?
I did not see any presented in this thread, and I am very interested in this aspect of the series. The path hash cache should be taking about 9.9M of disk space, but I recall reading the bitmap file is 8M. I don't understand.
I don't know there the 8M number came from, or if it was on the kernel repo. My bitmap-enabled pack of linux-2.6 (about 3.2M objects) using Vicent's patches looks like:
$ du -sh * 42M pack-9ea76831aec6c49c5ff42509a2a2ce97da13c5ad.bitmap 87M pack-9ea76831aec6c49c5ff42509a2a2ce97da13c5ad.idx 630M pack-9ea76831aec6c49c5ff42509a2a2ce97da13c5ad.pack
Packing the same repo with "jgit debug-gc" (jgit 3.0.0) yields:
$ du -sh * 3.0M pack-2478783825733a1f1012f0087a0b5a92aa7437d8.bitmap 82M pack-2478783825733a1f1012f0087a0b5a92aa7437d8.idx 585M pack-2478783825733a1f1012f0087a0b5a92aa7437d8.pack 4.8M pack-f61fb76112372288923be7a0464476892dfebe3e.idx 97M pack-f61fb76112372288923be7a0464476892dfebe3e.pack
If we assume that 12M of that is name-hash, that's still an order of magnitude larger. For reference, jgit created 327 bitmaps (according to its progress eye candy), and Vicent's patches generated 385. So that explains some of the increase, but the per-bitmap size is still much larger.
Quoted 3 lines
The path hash cache may still be required, Colby and I have been debating the merits of having the data available for delta compression vs. the increase in memory required to hold it.
I guess this is not an option for JGit, but for C git, an mmap-able name-hash file means we can just fault in the pages mentioning objects we actually need it for. And its use can be completely optional; in fact, it doesn't even need to be inside the .bitmap file (though I cannot think of a reason it would be useful outside of having bitmaps).
-Peff
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Jeff KingQuoted 6 lines
Pinning the bitmap index on the reverse index adds complexity (lookups are two-step: first find the entry in the reverse index, and then find the SHA1 in the index) and is measurably slower, in both loading and lookup times. Since Git doesn't have a memory problem, it's very hard to make an argument for design that is more complex and runs slower to save memory.
Sorting by SHA1 will generate a random distribution. This will require you to inflate the entire bitmap on every fetch request, in order to do the "contains" operation. Sorting by pack offset allows us to inflate only the bits we need as we are walking the graph, since they are usually at the start of the bitmap.
What is the general size in bytes of the SHA1 sorted bitmaps? If they are much larger, the size of the bitmap has an impact on how fast you can perform bitwise operations on them, which is important for fetch when doing wants AND NOT haves.
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 13 lines
Quoted 6 lines
Pinning the bitmap index on the reverse index adds complexity (lookups are two-step: first find the entry in the reverse index, and then find the SHA1 in the index) and is measurably slower, in both loading and lookup times. Since Git doesn't have a memory problem, it's very hard to make an argument for design that is more complex and runs slower to save memory.
Sorting by SHA1 will generate a random distribution. This will require you to inflate the entire bitmap on every fetch request, in order to do the "contains" operation. Sorting by pack offset allows us to inflate only the bits we need as we are walking the graph, since they are usually at the start of the bitmap.
Quoted 4 lines
What is the general size in bytes of the SHA1 sorted bitmaps? If they are much larger, the size of the bitmap has an impact on how fast you can perform bitwise operations on them, which is important for fetch when doing wants AND NOT haves.
Furthermore, JGit primarily operates on the bitmap representation, rarely converting bitmap id -> SHA1 during clone. When the bitmap of objects to include in the output pack contains all of the objects in the bitmap'd pack, we only do the translation of the bitmap ids of new objects, not in the bitmap index, and it is just a lookup in an array. Those objects are put at the front of the stream. The rest of the objects are streamed directly from the pack, with some header munging, since it is guaranteed to be a fully connected pack. Most of the time this works because JGit creates 2 packs during GC: a heads pack, which is bitmap'd, and an everything else pack.
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Documentation/technical/bitmap-format.txt line 209
Quoted 4 lines
Documentation/technical/bitmap-format.txt new file +4
-0+ Generating this reverse index at runtime is **not** free (around 900ms + generation time for a repository like `torvalds/linux`), and once again, + this generation time needs to happen every time `pack-objects` is + spawned.
If generating the reverse index is expensive, it is probably worthwhile to create a ".revidx" or extend the ".idx" with the information sorted by offset.
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 4 lines · Colby Ranger
Review
Quoted 4 lines
(quoted diff) +4
-0+ Generating this reverse index at runtime is **not** free (around 900ms + generation time for a repository like `torvalds/linux`), and once again, + this generation time needs to happen every time `pack-objects` is + spawned.
900ms is fishy. Creating the revidx should not take that long. But if it is...
Quoted 3 lines
If generating the reverse index is expensive, it is probably worthwhile to create a ".revidx" or extend the ".idx" with the information sorted by offset.
Colby is probably right that a cached copy of the revidx would help. Or update the .idx format to have two additional sections that stores the length of each packed object and the delta base of each packed object, allowing pack-objects to avoid creating the revidx. This would be an additional ~8 bytes per object, so ~19.8M for the Linux kernel (given ~2.6M objects).
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Jeff KingQuoted 14 lines · Jeff King
Quoted 11 lines · Vicent Martí
Quoted 7 lines
One way we side-stepped the size inflation problem in JGit was to only use the bitmap index information when sending data on the wire to a client. Here delta reuse plays a significant factor in building the pack, and we don't have to be as accurate on matching deltas. During the equivalent of
git repackbitmaps are not used, allowing the traditional graph enumeration algorithm to generate path hash information.OH BOY HERE WE GO. This is worth its own thread, lots to discuss here. I think peff will have a patchset regarding this to upstream soon, we'll get back to it later.
Quoted 8 lines
We do the same thing (only use bitmaps during on-the-wire fetches). But there a few problems with assuming delta reuse.
For us (GitHub), the foremost one is that we pack many "forks" of a repository together into a single packfile. That means when you clone torvalds/linux, an object you want may be stored in the on-disk pack with a delta against an object that you are not going to get. So we have to throw out that delta and find a new one.
Gerrit Code Review ran into the same problem a few years ago with the refs/changes namespace. Objects reachable from a branch were often delta compressed against dropped code review revisions, making for some slow transfers. We fixed this by creating a pack of everything reachable from refs/heads/* and then another pack of the other stuff.
I would encourage you to do what you suggest...
Quoted 10 lines
I'm dealing with that by adding an option to respect "islands" during packing, where an island is a set of common objects (we split it by fork, since we expect those objects to be fetched together, but you could use other criteria). The rule is that an object cannot delta against another object that is not in all of its islands. So everybody can delta against shared history, but objects in your fork can only delta against other objects in the fork. You are guaranteed to be able to reuse such deltas during a full clone of a fork, and the on-disk pack size does not suffer all that much (because there is usually a good alternate delta base within your reachable history).
Yes, exactly. I want to do the same thing on our servers, as we have many forks of some popular open source repositories that are also not small (Linux kernel, WebKit). Unfortunately Google has not had the time to develop the necessary support into JGit.
Quoted 10 lines
So with that series, we can get good reuse for clones. But there are still two cases worth considering:
1. When you fetch a subset of the commits, git marks only the edges as preferred bases, and does not walk the full object graph down to the roots. So any object you want that is delta'd against something older will not get reused. If you have reachability bitmaps, I don't think there is any reason that we cannot use the entire object graph (starting at the "have" tips, of course) as preferred bases.
In JGit we use the reachability bitmap to provide proof a client has an object. Even if its not in the edges. This allows us much better delta reuse, as often frequently deltas will be available pointing to something behind the edge, but that the client certainly has given the edges we know about.
We also use the reachability bitmap to provide proof a client does not need an object. We found a reduction in number of objects transferred because the "want AND NOT have" subtracted out a number of objects not in the edge. Apparently merges, reverts and cherry-picks happen often enough in the repositories we host that this particular optimization helps reduce data transfer, and work at both server and client ends of the connection. Its a nice freebie the bitmap algorithm gives us.
Quoted 4 lines
2. The server is not necessarily fully packed. In an active repo, you may have a large "base" pack with bitmaps, with several recently pushed packs on top. You still need to delta the recently pushed objects against the base objects.
Yes, this is unfortunate. One way we avoid this in JGit is to keep everything in pack files, rather than exploding loose. The reachability bitmap often proves the client has the delta base the pusher used to make the object, allowing us to reuse the delta. It may not be the absolute best delta in the world, but reuse is faster than inflate()+delta()+deflate(), and the delta is probably "good enough" until the server can do a real GC in the background.
We combine small packs from pushes together by almost literally just concat'ing the packs together and creating a new .idx. Newer pushed data is put in front of the older data, the pack is clustered by "commit, tree, blob" ordering, duplicates are removed, and its written back to disk. Typically we complete this "pack concat" operation mere seconds after a push finishes, so readers have very few packs to deal with.
Quoted 4 lines
I don't have measurements on how much the deltas suffer in those two cases. I know they suffered quite badly for clones without the name hashes in our alternates repos, but that part should go away with my patch series.
JGit doesn't poke objects into the object table (or even the object list) when a bitmap is used. We spool the bits out of the bitmap in bitmap order and write them to the wire in that order. Its way faster, but depends on the bitmap being in pack-ordering. So clones are crazy fast even though we don't have the path-hash table.
JGit also has another optimization where we figure out based on the bitmap if the client needs *everything* in this pack. Which given a pack created only for refs/heads/* is the common case for a clone. If the client is getting all objects we essentially just do a sendfile() for the region starting at offset 12 through end-20. It can't be a sendfile() syscall because it has to be computed into the trailer SHA-1 the client sees, but its a crazy tight IO copy loop with no Git smarts beyond the SHA-1 updating.
Like I said, there are a ton of optimizations you guys missed. And we think they make a bigger difference than screwing around with little-endian format to favor x86 CPUs.
Re: [PATCH 11/16] rev-list: add bitmap mode to speed up lists
In reply to Vicent MartíQuoted 3 lines · Vicent Martí
I'm afraid I cannot reproduce the segfault locally (assuming you're performing the rev-list on the git/git repository). Could you please send me more information, and a core dump if possible?
Sure, but isn't the core dump useless if you don't have the same executable? And since I'm building "custom" git, you won't have that.
Here's a semi-full backtrace (I left out the spammy output in the outermost frames). Some variables in #2 and #3 seem to have gone off the rails.
#0 0x00007ffff72b06fb in __memset_sse2 () from /lib64/libc.so.6
No symbol table info available.
#1 0x000000000054c31c in bitmap_set (self=0x89c360, pos=18446744072278122040) at ewah/bitmap.c:46
old_size = 7666
block = 288230376129345656
#2 0x00000000004e6c70 in add_to_include_set (data=0x7fffffffcd00, sha1=0x85c014 "\230\062˝M\311i\373\372\317\321\370\224\017\313\336\301\213\271\060", bitmap_pos=-1431429576) at pack-bitmap.c:428
hash_pos = 512
#3 0x00000000004e6cd6 in should_include (commit=0x85c010, _data=0x7fffffffcd00) at pack-bitmap.c:443
data = 0x7fffffffcd00
bitmap_pos = -1431429576
#4 0x000000000050cf1d in add_parents_to_list (revs=0x7fffffffce30, commit=0x85c010, list=0x7fffffffce30, cache_ptr=0x0) at revision.c:784
parent = 0x88c260
left_flag = 32767
cached_base = 0x0
#5 0x0000000000512b66 in get_revision_1 (revs=0x7fffffffce30) at revision.c:2857
entry = 0x8f9ce0
commit = 0x85c010
#6 0x0000000000512dcf in get_revision_internal (revs=0x7fffffffce30) at revision.c:2964
c = 0x0
l = 0x1000
#7 0x0000000000512fe1 in get_revision (revs=0x7fffffffce30) at revision.c:3040
c = 0xb92608
reversed = 0x89c360
#8 0x00000000004d2a24 in traverse_commit_list (revs=0x7fffffffce30, show_commit=0x4e6b72 <show_commit>, show_object=0x4e6afa <show_object>, data=0x89c360) at list-objects.c:179
i = -1
commit = 0xb92608
base = {
alloc = 4097,
len = 0,
buf = 0x87bbe0 ""
}
#9 0x00000000004e6fa4 in find_objects (revs=0x7fffffffce30, roots=0x0, seen=0x85b760) at pack-bitmap.c:549
incdata = {
base = 0x89c360,
seen = 0x85b760
}
base = 0x89c360
needs_walk = true
not_mapped = 0x8f9dc0
#10 0x00000000004e747b in prepare_bitmap_walk (revs=0x7fffffffce30, result_size=0x0) at pack-bitmap.c:679
i = 2
pending_nr = 2
pending_alloc = 64
pending_e = 0x853e10
wants = 0x8545b0
haves = 0x854820
wants_bitmap = 0x0
haves_bitmap = 0x85b760#11 0x0000000000474bb3 in cmd_rev_list (argc=2, argv=0x7fffffffd6e8, prefix=0x0) at builtin/rev-list.c:356 #12 0x0000000000405820 in run_builtin (p=0x7c3ef8 <commands.20770+2040>, argc=4, argv=0x7fffffffd6e8) at git.c:291 #13 0x00000000004059b3 in handle_internal_command (argc=4, argv=0x7fffffffd6e8) at git.c:454 #14 0x0000000000405b87 in main (argc=4, av=0x7fffffffd6e8) at git.c:544
This is with a version of your series that you can find at
https://github.com/trast/git.git vm/ewah
I am'd your patches on top of Junio's master at the time, except for the parts to the Makefile that did not apply, which I fixed up manually.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Shawn PearceQuoted 2 lines
Right, the format and implementation in JGit can do "Counting objects" in 87ms for the Linux kernel history.
Actually, that was the timing when I first pushed the change. With the improvements submitted throughout the year, we can do counting in 50ms, on my same machine.
Quoted 5 lines
But I think we are comparing
apples to steaks here, Vincent is (rightfully) concerned about process startup performance, whereas our timings were assuming the process was already running.
I did some timing on loading the reverse index for the kernel and it is pretty slow (~1200ms). I just submitted a fix to do a bucket sort and reduced that to ~450ms, which is still slow but much better:
https://eclipse.googlesource.com/jgit/jgit/+/6cc532a43cf28403cb623d3df8600a2542a40a43%5E%21/
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 10 lines · Colby Ranger
Quoted 5 lines
But I think we are comparing
apples to steaks here, Vincent is (rightfully) concerned about process startup performance, whereas our timings were assuming the process was already running.I did some timing on loading the reverse index for the kernel and it is pretty slow (~1200ms). I just submitted a fix to do a bucket sort and reduced that to ~450ms, which is still slow but much better:
https://eclipse.googlesource.com/jgit/jgit/+/6cc532a43cf28403cb623d3df8600a2542a40a43%5E%21/
A reverse index that is hot in RAM would obviously load in about 0ms. But a cold load of a reverse index that uses only 4 bytes per object (as Colby did here) for 3.1M objects could take ~590ms to read from disk, assuming spinning media moving 20 MiB/s. If 8 byte offsets were also stored this could be more like 1700ms.
Numbers obviously get better if the spinning media can transfer at 40 MiB/s, now its more like 295ms for 4 bytes/object and 885ms for 12 bytes/object.
I think its still reasonable to compute the reverse index on the fly. But JGit certainly does have the benefit of reusing it across requests by relying on process memory based caches. C Git needs to rely on the kernel buffer cache, which requires this data be written out to a file to be shared.
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
In reply to Colby RangerQuoted 9 lines · Colby Ranger
Quoted 5 lines
But I think we are comparing
apples to steaks here, Vincent is (rightfully) concerned about process startup performance, whereas our timings were assuming the process was already running.I did some timing on loading the reverse index for the kernel and it is pretty slow (~1200ms). I just submitted a fix to do a bucket sort and reduced that to ~450ms, which is still slow but much better:
On my machine, loading the kernel revidx in C git is about ~830ms. I switched the qsort() call to a radix/bucket sort, and have it down to ~200ms. So definitely much better, though that still leaves a bit to be desired for quick commands. E.g., "git rev-list --count A..B" should become fairly instantaneous with bitmaps, but in many cases the revindex loading will take longer than it would have to simply do the actual traversal.
-Peff
Re: [PATCH 09/16] documentation: add documentation for the bitmap format
Quoted 8 lines · Jeff King
Quoted 6 lines · Colby Ranger
Quoted 5 lines
But I think we are comparing
apples to steaks here, Vincent is (rightfully) concerned about process startup performance, whereas our timings were assuming the process was already running.
Quoted 7 lines
Quoted 3 lines
I did some timing on loading the reverse index for the kernel and it is pretty slow (~1200ms). I just submitted a fix to do a bucket sort and reduced that to ~450ms, which is still slow but much better:
On my machine, loading the kernel revidx in C git is about ~830ms. I switched the
qsort()call to a radix/bucket sort, and have it down to ~200ms. So definitely much better,
This is a very nice reduction. pack-objects would benefit from it even without bitmaps. Since it doesn't require a data format change this is a pretty harmless patch to include in Git. We may later conclude caching the revidx is worthwhile, but until then a bucket sort doesn't hurt. :-)
Quoted 5 lines
though that still leaves a bit to be
desired for quick commands. E.g., "git rev-list --count A..B" should become fairly instantaneous with bitmaps, but in many cases the revindex loading will take longer than it would have to simply do the actual traversal.
Yea, we don't know of a way around this. In a few cases the bitmap code in JGit is slower than the naive traversal, but these are only on small segments of history. I wonder if you could guess which algorithm to use by looking at the offsets of A and B using the idx file. If they are near each other in the pack, run the naive algorithm without bitmaps and revidx. If they are farther apart assume the bitmap would help more than traversal and use bitmap+revidx.
Working out what the correct "distance" should be before switching algorithms is hard. A and B could be megabytes apart in the pack but A could be B's grandparent and traversed in milliseconds. I wonder how often that is in practice, certainly if A and B are within a few hundred kilobytes of each other the naive traversal should be almost instant.