Skip to contentSkip to conversation

pack bitmaps

PATCH Superseded Jeff King 9 participants 68 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore

Jeff King

author
#0 lore raw

v4 cover pack bitmaps

Here's the v4 re-roll of the pack bitmap series.

The changes from v3 are:

- reworked add_object_entry refactoring (see patch 11, which is new, and patch 12 which builds on it in a more natural way)

- better error/die reporting from write_reused_pack

- added Ramsay's PRIx64 compat fix

- fixed a user-after-free in the warning message of open_pack_bitmap_1

- minor typo/thinko fixes from Thomas in docs and tests

Interdiff is below.

[01/23]: sha1write: make buffer const-correct [02/23]: revindex: Export new APIs
[03/23]: pack-objects: Refactor the packing list [04/23]: pack-objects: factor out name_hash
[05/23]: revision: allow setting custom limiter function [06/23]: sha1_file: export git_open_noatime [07/23]: compat: add endianness helpers
[08/23]: ewah: compressed bitmap implementation [09/23]: documentation: add documentation for the bitmap format [10/23]: pack-bitmap: add support for bitmap indexes [11/23]: pack-objects: split add_object_entry [12/23]: pack-objects: use bitmaps when packing objects [13/23]: rev-list: add bitmap mode to speed up object lists [14/23]: pack-objects: implement bitmap writing [15/23]: repack: stop using magic number for ARRAY_SIZE(exts) [16/23]: repack: turn exts array into array-of-struct [17/23]: repack: handle optional files created by pack-objects [18/23]: repack: consider bitmaps when performing repacks [19/23]: count-objects: recognize .bitmap in garbage-checking [20/23]: t: add basic bitmap functionality tests [21/23]: t/perf: add tests for pack bitmaps
[22/23]: pack-bitmap: implement optional name_hash cache [23/23]: compat/mingw.h: Fix the MinGW and msvc builds

---

Documentation/config.txt +1 -1
index e6d3922..499a3c4 100644
@@ -1866,7 +1866,7 @@ pack.useBitmaps::
 
 pack.writebitmaps::
 	When true, git will write a bitmap index when packing all
-	objects to disk (e.g., as when `git repack -a` is run).  This
+	objects to disk (e.g., when `git repack -a` is run).  This
 	index can speed up the "counting objects" phase of subsequent
 	packs created for clones and fetches, at the cost of some disk
 	space and extra time spent on the initial repack.  Defaults to
builtin/pack-objects.c +113 -67

257 lines not on this page · raw message

pack-bitmap.c +1 -1
index 078f7c6..ae0b57b 100644
@@ -266,7 +266,7 @@ static int open_pack_bitmap_1(struct packed_git *packfile)
 	}
 
 	if (bitmap_git.pack) {
-		warning("ignoring extra bitmap file: %s", idx_name);
+		warning("ignoring extra bitmap file: %s", packfile->pack_name);
 		close(fd);
 		return -1;
 	}
pack-bitmap.h +1 -1
index e4e1a57..8b7f4e9 100644
@@ -19,7 +19,7 @@ struct bitmap_disk_header {
 	unsigned char checksum[20];
 };
 
-static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};;
+static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
 
 #define NEEDS_BITMAP (1u<<22)
 
t/perf/p5310-pack-bitmaps.sh +2 -2
index 8811fc4..685d46f 100755
@@ -22,7 +22,7 @@ test_perf 'simulated clone' '
 '
 
 test_perf 'simulated fetch' '
-	have=$(git rev-list HEAD --until=1.week.ago -1) &&
+	have=$(git rev-list HEAD~100 -1) &&
 	{
 		echo HEAD &&
 		echo ^$have
@@ -31,7 +31,7 @@ test_perf 'simulated fetch' '
 
 test_expect_success 'create partial bitmap state' '
 	# pick a commit to represent the repo tip in the past
-	cutoff=$(git rev-list HEAD --until=1.week.ago -1) &&
+	cutoff=$(git rev-list HEAD~100 -1) &&
 	orig_tip=$(git rev-parse HEAD) &&
 
 	# now kill off all of the refs and pretend we had
t/t5310-pack-bitmaps.sh +2 -2
index 2c2632f..d3a3afa 100755
@@ -127,9 +127,9 @@ test_expect_success JGIT 'we can read jgit bitmaps' '
 '
 
 test_expect_success JGIT 'jgit can read our bitmaps' '
-	git clone . compat-us.git &&
+	git clone . compat-us &&
 	(
-		cd compat-us.git &&
+		cd compat-us &&
 		git repack -adb &&
 		# jgit gc will barf if it does not like our bitmaps
 		jgit gc
author
#1 lore raw

PATCH v4 1/23 sha1write: make buffer const-correct

We are passed a "void *" and write it out without ever touching it; let's indicate that by using "const".

---
 csum-file.c | 6 +++---
 csum-file.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
csum-file.c +3 -3
index 53f5375..465971c 100644
@@ -11,7 +11,7 @@
 #include "progress.h"
 #include "csum-file.h"
 
-static void flush(struct sha1file *f, void *buf, unsigned int count)
+static void flush(struct sha1file *f, const void *buf, unsigned int count)
 {
 	if (0 <= f->check_fd && count)  {
 		unsigned char check_buffer[8192];
@@ -86,13 +86,13 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
 	return fd;
 }
 
-int sha1write(struct sha1file *f, void *buf, unsigned int count)
+int sha1write(struct sha1file *f, const void *buf, unsigned int count)
 {
 	while (count) {
 		unsigned offset = f->offset;
 		unsigned left = sizeof(f->buffer) - offset;
 		unsigned nr = count > left ? left : count;
-		void *data;
+		const void *data;
 
 		if (f->do_crc)
 			f->crc32 = crc32(f->crc32, buf, nr);
csum-file.h +1 -1
index 3b540bd..9dedb03 100644
@@ -34,7 +34,7 @@ extern struct sha1file *sha1fd(int fd, const char *name);
 extern struct sha1file *sha1fd_check(const char *name);
 extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp);
 extern int sha1close(struct sha1file *, unsigned char *, unsigned int);
-extern int sha1write(struct sha1file *, void *, unsigned int);
+extern int sha1write(struct sha1file *, const void *, unsigned int);
 extern void sha1flush(struct sha1file *f);
 extern void crc32_begin(struct sha1file *);
 extern uint32_t crc32_end(struct sha1file *);
Signature · 1 line
1.8.5.1.399.g900e7cd
#2 lore raw

Re: [PATCH v4 01/23] sha1write: make buffer const-correct

Quoted 1 line · Jeff King

We are passed a "void *" and write it out without ever

s/are passed/pass/

Cheers,
Christian.

author
#3 lore raw

PATCH v4 2/23 revindex: Export new APIs

In reply to Jeff King

From: Vicent Marti <[email protected]>

Allow users to efficiently lookup consecutive entries that are expected to be found on the same revindex by exporting find_revindex_position:
this function takes a pointer to revindex itself, instead of looking up the proper revindex for a given packfile on each call.

---
 pack-revindex.c | 38 +++++++++++++++++++++++++-------------
 pack-revindex.h |  8 ++++++++
 2 files changed, 33 insertions(+), 13 deletions(-)
pack-revindex.c +25 -13
index b4d2b35..0bb13b1 100644
@@ -16,11 +16,6 @@
  * get the object sha1 from the main index.
  */
 
-struct pack_revindex {
-	struct packed_git *p;
-	struct revindex_entry *revindex;
-};
-
 static struct pack_revindex *pack_revindex;
 static int pack_revindex_hashsz;
 
@@ -201,15 +196,14 @@ static void create_pack_revindex(struct pack_revindex *rix)
 	sort_revindex(rix->revindex, num_ent, p->pack_size);
 }
 
-struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
+struct pack_revindex *revindex_for_pack(struct packed_git *p)
 {
 	int num;
-	unsigned lo, hi;
 	struct pack_revindex *rix;
-	struct revindex_entry *revindex;
 
 	if (!pack_revindex_hashsz)
 		init_pack_revindex();
+
 	num = pack_revindex_ix(p);
 	if (num < 0)
 		die("internal error: pack revindex fubar");
@@ -217,21 +211,39 @@ struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
 	rix = &pack_revindex[num];
 	if (!rix->revindex)
 		create_pack_revindex(rix);
-	revindex = rix->revindex;
 
-	lo = 0;
-	hi = p->num_objects + 1;
+	return rix;
+}
+
+int find_revindex_position(struct pack_revindex *pridx, off_t ofs)
+{
+	int lo = 0;
+	int hi = pridx->p->num_objects + 1;
+	struct revindex_entry *revindex = pridx->revindex;
+
 	do {
 		unsigned mi = lo + (hi - lo) / 2;
 		if (revindex[mi].offset == ofs) {
-			return revindex + mi;
+			return mi;
 		} else if (ofs < revindex[mi].offset)
 			hi = mi;
 		else
 			lo = mi + 1;
 	} while (lo < hi);
+
 	error("bad offset for revindex");
-	return NULL;
+	return -1;
+}
+
+struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
+{
+	struct pack_revindex *pridx = revindex_for_pack(p);
+	int pos = find_revindex_position(pridx, ofs);
+
+	if (pos < 0)
+		return NULL;
+
+	return pridx->revindex + pos;
 }
 
 void discard_revindex(void)
pack-revindex.h +8 -0
index 8d5027a..866ca9c 100644
@@ -6,6 +6,14 @@ struct revindex_entry {
 	unsigned int nr;
 };
 
+struct pack_revindex {
+	struct packed_git *p;
+	struct revindex_entry *revindex;
+};
+
+struct pack_revindex *revindex_for_pack(struct packed_git *p);
+int find_revindex_position(struct pack_revindex *pridx, off_t ofs);
+
 struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs);
 void discard_revindex(void);
 
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#4 lore raw

PATCH v4 3/23 pack-objects: Refactor the packing list

In reply to Jeff King

From: Vicent Marti <[email protected]>

The hash table that stores the packing list for a given pack-objects run was tightly coupled to the pack-objects code.

In this commit, we refactor the hash table and the underlying storage array into a packing_data struct. The functionality for accessing and adding entries to the packing list is hence accessible from other parts of Git besides the pack-objects builtin.

This refactoring is a requirement for further patches in this series that will require accessing the commit packing list from outside of pack-objects.

The hash table implementation has been minimally altered: we now use table sizes which are always a power of two, to ensure a uniform index distribution in the array.

---
 Makefile               |   2 +
 builtin/pack-objects.c | 175 +++++++++++--------------------------------------
 pack-objects.c         | 111 +++++++++++++++++++++++++++++++
 pack-objects.h         |  47 +++++++++++++
 4 files changed, 200 insertions(+), 135 deletions(-)
 create mode 100644 pack-objects.c
 create mode 100644 pack-objects.h
Makefile +2 -0
index af847f8..48ff0bd 100644
@@ -694,6 +694,7 @@ LIB_H += notes-merge.h
 LIB_H += notes-utils.h
 LIB_H += notes.h
 LIB_H += object.h
+LIB_H += pack-objects.h
 LIB_H += pack-revindex.h
 LIB_H += pack.h
 LIB_H += parse-options.h
@@ -831,6 +832,7 @@ LIB_OBJS += notes-merge.o
 LIB_OBJS += notes-utils.o
 LIB_OBJS += object.o
 LIB_OBJS += pack-check.o
+LIB_OBJS += pack-objects.o
 LIB_OBJS += pack-revindex.o
 LIB_OBJS += pack-write.o
 LIB_OBJS += pager.o
builtin/pack-objects.c +40 -135

338 lines not on this page · raw message

pack-objects.c new file +111 -0

111 lines not on this page · raw message

pack-objects.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.8.5.1.399.g900e7cd
author
#5 lore raw

PATCH v4 4/23 pack-objects: factor out name_hash

In reply to Jeff King

From: Vicent Marti <[email protected]>

As the pack-objects system grows beyond the single pack-objects.c file, more parts (like the soon-to-exist bitmap code) will need to compute hashes for matching deltas. Factor out name_hash to make it available to other files.

---
 builtin/pack-objects.c | 24 ++----------------------
 pack-objects.h         | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 22 deletions(-)
builtin/pack-objects.c +2 -22
index f3f0cf9..faf746b 100644
@@ -778,26 +778,6 @@ static void write_pack_file(void)
 			written, nr_result);
 }
 
-static uint32_t name_hash(const char *name)
-{
-	uint32_t 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;
@@ -826,7 +806,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
 	struct object_entry *entry;
 	struct packed_git *p, *found_pack = NULL;
 	off_t found_offset = 0;
-	uint32_t hash = name_hash(name);
+	uint32_t hash = pack_name_hash(name);
 	uint32_t index_pos;
 
 	entry = packlist_find(&to_pack, sha1, &index_pos);
@@ -1082,7 +1062,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;
pack-objects.h +20 -0
index f528215..90ad0a8 100644
@@ -44,4 +44,24 @@ struct object_entry *packlist_find(struct packing_data *pdata,
 				   const unsigned char *sha1,
 				   uint32_t *index_pos);
 
+static inline uint32_t pack_name_hash(const char *name)
+{
+	uint32_t 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;
+}
+
 #endif
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#6 lore raw

PATCH v4 5/23 revision: allow setting custom limiter function

In reply to Jeff King

From: Vicent Marti <[email protected]>

This 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 | 4 ++++
 revision.h | 2 ++
 2 files changed, 6 insertions(+)
revision.c +4 -0
index 0173e01..cddd605 100644
@@ -779,6 +779,10 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
 		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
index e7f1d21..9957f3c 100644
@@ -168,6 +168,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.8.5.1.399.g900e7cd
author
#7 lore raw

PATCH v4 6/23 sha1_file: export `git_open_noatime`

In reply to Jeff King

From: Vicent Marti <[email protected]>

The 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
index 5e3fc72..f2e5aa7 100644
@@ -780,6 +780,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
index f80bbe4..4714bd8 100644
@@ -239,8 +239,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.
  *
@@ -1357,7 +1355,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.8.5.1.399.g900e7cd
author
#8 lore raw

PATCH v4 7/23 compat: add endianness helpers

In reply to Jeff King

From: Vicent Marti <[email protected]>

The POSIX standard doesn't currently define a ntohll/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.

Many thanks to Ramsay Jones <[email protected]> and Torsten Bögershausen <[email protected]> for cygwin/mingw/msvc portability fixes.

---
 compat/bswap.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)
compat/bswap.h +75 -1
index 5061214..c18a78e 100644
@@ -17,7 +17,20 @@ static inline uint32_t default_swab32(uint32_t val)
 		((val & 0x000000ff) << 24));
 }
 
+static inline uint64_t default_bswap64(uint64_t val)
+{
+	return (((val & (uint64_t)0x00000000000000ffULL) << 56) |
+		((val & (uint64_t)0x000000000000ff00ULL) << 40) |
+		((val & (uint64_t)0x0000000000ff0000ULL) << 24) |
+		((val & (uint64_t)0x00000000ff000000ULL) <<  8) |
+		((val & (uint64_t)0x000000ff00000000ULL) >>  8) |
+		((val & (uint64_t)0x0000ff0000000000ULL) >> 24) |
+		((val & (uint64_t)0x00ff000000000000ULL) >> 40) |
+		((val & (uint64_t)0xff00000000000000ULL) >> 56));
+}
+
 #undef bswap32
+#undef bswap64
 
 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
 
@@ -32,15 +45,42 @@ static inline uint32_t git_bswap32(uint32_t x)
 	return result;
 }
 
+#define bswap64 git_bswap64
+#if defined(__x86_64__)
+static inline uint64_t git_bswap64(uint64_t x)
+{
+	uint64_t result;
+	if (__builtin_constant_p(x))
+		result = default_bswap64(x);
+	else
+		__asm__("bswap %q0" : "=r" (result) : "0" (x));
+	return result;
+}
+#else
+static inline uint64_t git_bswap64(uint64_t x)
+{
+	union { uint64_t i64; uint32_t i32[2]; } tmp, result;
+	if (__builtin_constant_p(x))
+		result.i64 = default_bswap64(x);
+	else {
+		tmp.i64 = x;
+		result.i32[0] = git_bswap32(tmp.i32[1]);
+		result.i32[1] = git_bswap32(tmp.i32[0]);
+	}
+	return result.i64;
+}
+#endif
+
 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
 
 #include <stdlib.h>
 
 #define bswap32(x) _byteswap_ulong(x)
+#define bswap64(x) _byteswap_uint64(x)
 
 #endif
 
-#ifdef bswap32
+#if defined(bswap32)
 
 #undef ntohl
 #undef htonl
@@ -48,3 +88,37 @@ static inline uint32_t git_bswap32(uint32_t x)
 #define htonl(x) bswap32(x)
 
 #endif
+
+#if defined(bswap64)
+
+#undef ntohll
+#undef htonll
+#define ntohll(x) bswap64(x)
+#define htonll(x) bswap64(x)
+
+#else
+
+#undef ntohll
+#undef htonll
+
+#if !defined(__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
+# endif
+#endif
+
+#if !defined(__BYTE_ORDER)
+# error "Cannot determine endianness"
+#endif
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+# define ntohll(n) (n)
+# define htonll(n) (n)
+#else
+# define ntohll(n) default_bswap64(n)
+# define htonll(n) default_bswap64(n)
+#endif
+
+#endif
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#9 lore raw

PATCH v4 8/23 ewah: compressed bitmap implementation

In reply to Jeff King

From: Vicent Marti <[email protected]>

EWAH 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           |  11 +-
 ewah/bitmap.c      | 221 ++++++++++++++++
 ewah/ewah_bitmap.c | 726 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 ewah/ewah_io.c     | 193 ++++++++++++++
 ewah/ewah_rlw.c    | 115 +++++++++
 ewah/ewok.h        | 235 +++++++++++++++++
 ewah/ewok_rlw.h    | 114 +++++++++
 7 files changed, 1613 insertions(+), 2 deletions(-)
 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 +9 -2
index 48ff0bd..64a1ed7 100644
@@ -667,6 +667,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
@@ -800,6 +802,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
@@ -2474,8 +2480,9 @@ profile-clean:
 	$(RM) $(addsuffix *.gcno,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
 
 clean: profile-clean coverage-clean
-	$(RM) *.o *.res block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \
-		builtin/*.o $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
+	$(RM) *.o *.res block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o
+	$(RM) xdiff/*.o vcs-svn/*.o ewah/*.o builtin/*.o
+	$(RM) $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
 	$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
 	$(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
 	$(RM) -r bin-wrappers $(dep_dirs)
ewah/bitmap.c new file +221 -0

221 lines not on this page · raw message

ewah/ewah_bitmap.c new file +726 -0

726 lines not on this page · raw message

ewah/ewah_io.c new file +193 -0

193 lines not on this page · raw message

ewah/ewah_rlw.c new file +115 -0

115 lines not on this page · raw message

ewah/ewok.h new file +235 -0

235 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.8.5.1.399.g900e7cd
#10 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Hi,

Quoted 2 lines · Jeff King

EWAH 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).

I suspect that for some callers it's not word-aligned.

Without the following squashed in, commits 212f2ffb and later fail t5310 on some machines[1].

On ARMv5:

	expecting success: 
		git rev-list --test-bitmap HEAD

	*** Error in `/«PKGBUILDDIR»/git': realloc(): invalid pointer: 0x008728b0 ***
	Aborted
	not ok 3 - rev-list --test-bitmap verifies bitmaps

On sparc:

	expecting success: 
		git rev-list --test-bitmap HEAD

	Bus error
	not ok 3 - rev-list --test-bitmap verifies bitmaps

Hopefully it's possible to get the alignment right in the caller and tweak the signature to require that instead of using unaligned reads like this. There's still something wrong after this patch --- the new result is a NULL pointer dereference in t5310.7 "enumerate --objects (full bitmap)".

(gdb) run
Starting program: /home/jrnieder/src/git/git rev-list --objects --use-bitmap-index HEAD [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/sparc-linux-gnu/libthread_db.so.1". 537ea4d3eb79c95f602873b1167c480006d2ac2d
[...]
ec635144f60048986bc560c5576355344005e6e7

  Program received signal SIGSEGV, Segmentation fault.
  0x001321c0 in sha1_to_hex (sha1=0x0) at hex.c:68
  68                      unsigned int val = *sha1++;
  (gdb) bt
  #0  0x001321c0 in sha1_to_hex (sha1=0x0) at hex.c:68
  #1  0x000b839c in show_object_fast (sha1=0x0, type=OBJ_TREE, exclude=0, name_hash=0, found_pack=0x2b8480, found_offset=4338) at builtin/rev-list.c:270
  #2  0x00158abc in show_objects_for_type (objects=0x2b2498, type_filter=0x2b0fb0, object_type=OBJ_TREE, show_reach=0xb834c <show_object_fast>) at pack-bitmap.c:640
  #3  0x001592d0 in traverse_bitmap_commit_list (show_reachable=0xb834c <show_object_fast>) at pack-bitmap.c:818
  #4  0x000b894c in cmd_rev_list (argc=2, argv=0xffffd688, prefix=0x0) at builtin/rev-list.c:369
  #5  0x00014024 in run_builtin (p=0x256e38 <commands+1020>, argc=4, argv=0xffffd688) at git.c:314
  #6  0x00014330 in handle_builtin (argc=4, argv=0xffffd688) at git.c:487
  #7  0x000144a8 in run_argv (argcp=0xffffd5ec, argv=0xffffd5a0) at git.c:533
  #8  0x000146fc in main (argc=4, av=0xffffd684) at git.c:616
  (gdb) frame 2
  #2  0x00158abc in show_objects_for_type (objects=0x2b2498, type_filter=0x2b0fb0, object_type=OBJ_TREE, show_reach=0xb834c <show_object_fast>) at pack-bitmap.c:640
  640                             show_reach(sha1, object_type, 0, hash, bitmap_git.pack, entry->offset);
  (gdb) p entry->nr
  $1 = 4294967295

Line numbers are in the context of 8e6341d9. Ideas?

[1] ARMv5 and sparc:
https://buildd.debian.org/status/logs.php?pkg=git&suite=experimental

ewah/ewah_io.c +21 -8
index aed0da6..696a8ec 100644
@@ -110,25 +110,38 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
 	return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
 }
 
+#define get_be32(p) ( \
+	(*((unsigned char *)(p) + 0) << 24) | \
+	(*((unsigned char *)(p) + 1) << 16) | \
+	(*((unsigned char *)(p) + 2) <<  8) | \
+	(*((unsigned char *)(p) + 3) <<  0) )
+
+#define get_be64(p) ( \
+	((uint64_t) get_be32(p) << 32) | \
+	get_be32((unsigned char *)(p) + 4) )
+
 int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
 {
-	uint32_t *read32 = map;
-	eword_t *read64;
+	unsigned char *p = map;
 	size_t i;
 
-	self->bit_size = ntohl(*read32++);
-	self->buffer_size = self->alloc_size = ntohl(*read32++);
+	self->bit_size = get_be32(p);
+	p += 4;
+	self->buffer_size = self->alloc_size = get_be32(p);
+	p += 4;
 	self->buffer = ewah_realloc(self->buffer,
 		self->alloc_size * sizeof(eword_t));
 
 	if (!self->buffer)
 		return -1;
 
-	for (i = 0, read64 = (void *)read32; i < self->buffer_size; ++i)
-		self->buffer[i] = ntohll(*read64++);
+	for (i = 0; i < self->buffer_size; ++i) {
+		self->buffer[i] = get_be64(p);
+		p += 8;
+	}
 
-	read32 = (void *)read64;
-	self->rlw = self->buffer + ntohl(*read32++);
+	self->rlw = self->buffer + get_be32(p);
+	p += 4;
 
 	return (3 * 4) + (self->buffer_size * 8);
 }
author
#11 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 6 lines · Jonathan Nieder
Quoted 2 lines · Jeff King

EWAH 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).

I suspect that for some callers it's not word-aligned.

Yes, the mmap'd buffers aren't necessarily word-aligned. I don't think we can fix that easily without changing the on-disk format (which comes from JGit anyway). However, since we are memcpying the bulk of the data into a newly allocated buffer (which must be aligned), we can do that first, and then fix the endian-ness in place.

The only SPARC machine I have access to is running Solaris, but after some slight wrestling with the BYTE_ORDER macros, I managed to get it to compile and reproduced the bus error.

Here's a patch series (on top of jk/pack-bitmap, naturally) that lets t5310 pass there. I assume the ARM problem is the same, though seeing the failure in realloc() is unexpected. Can you try it on both your platforms with these patches?

[1/2]: compat: move unaligned helpers to bswap.h [2/2]: ewah: support platforms that require aligned reads

Quoted 5 lines

Hopefully it's possible to get the alignment right in the caller and tweak the signature to require that instead of using unaligned reads like this. There's still something wrong after this patch --- the new result is a NULL pointer dereference in t5310.7 "enumerate --objects (full bitmap)".

After my patches, t5310 runs fine for me. I didn't try your patch, but mine are similar. Let me know if you still see the problem (there may simply be a bug in yours, but I didn't see it).

-Peff

author
#12 lore raw

PATCH 1/2 compat: move unaligned helpers to bswap.h

From: Vicent Marti <[email protected]>

Commit d60c49c (read-cache.c: allow unaligned mapping of the index file, 2012-04-03) introduced helpers to access unaligned data. Let's factor them out to make them more widely available.

While we're at it, we'll give the helpers more readable names, add a helper for the "ntohll" form, and add the appropriate Makefile knob.

---
 Makefile       |  7 +++++++
 compat/bswap.h | 28 ++++++++++++++++++++++++++++
 read-cache.c   | 44 ++++++++++++--------------------------------
 3 files changed, 47 insertions(+), 32 deletions(-)
Makefile +7 -0
index 4136c4f..5711c0e 100644
@@ -342,6 +342,9 @@ all::
 # Define DEFAULT_HELP_FORMAT to "man", "info" or "html"
 # (defaults to "man") if you want to have a different default when
 # "git help" is called without a parameter specifying the format.
+#
+# Define NEEDS_ALIGNED_ACCESS if your platform cannot handle unaligned
+# access to integers in mmap'd files.
 
 GIT-VERSION-FILE: FORCE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1505,6 +1508,10 @@ ifneq (,$(XDL_FAST_HASH))
 	BASIC_CFLAGS += -DXDL_FAST_HASH
 endif
 
+ifdef NEEDS_ALIGNED_ACCESS
+	BASIC_CFLAGS += -DNEEDS_ALIGNED_ACCESS
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK = NoThanks
 endif
compat/bswap.h +28 -0
index c18a78e..80abc54 100644
@@ -122,3 +122,31 @@ static inline uint64_t git_bswap64(uint64_t x)
 #endif
 
 #endif
+
+#ifndef NEEDS_ALIGNED_ACCESS
+#define align_ntohs(var) ntohs(var)
+#define align_ntohl(var) ntohl(var)
+#define align_ntohll(var) ntohll(var)
+#else
+static inline uint16_t ntohs_force_align(void *p)
+{
+	uint16_t x;
+	memcpy(&x, p, sizeof(x));
+	return ntohs(x);
+}
+static inline uint32_t ntohl_force_align(void *p)
+{
+	uint32_t x;
+	memcpy(&x, p, sizeof(x));
+	return ntohl(x);
+}
+static inline uint64_t ntohll_force_align(void *p)
+{
+	uint64_t x;
+	memcpy(&x, p, sizeof(x));
+	return ntohll(x);
+}
+#define align_ntohs(var) ntohs_force_align(&(var))
+#define align_ntohl(var) ntohl_force_align(&(var))
+#define align_ntohll(var) ntohll_force_align(&(var))
+#endif
read-cache.c +12 -32

68 lines not on this page · raw message

Signature · 1 line
1.8.5.2.500.g8060133
#13 lore raw

Re: [PATCH 1/2] compat: move unaligned helpers to bswap.h

Quoted 8 lines · Jeff King

Commit d60c49c (read-cache.c: allow unaligned mapping of the index file, 2012-04-03) introduced helpers to access unaligned data. Let's factor them out to make them more widely available.

While we're at it, we'll give the helpers more readable names, add a helper for the "ntohll" form, and add the appropriate Makefile knob.

Weird. Why wasn't git broken on the relevant platforms before (given that no one has been setting NEEDS_ALIGNED_ACCESS for them)?

Puzzled,
Jonathan

author
#14 lore raw

Re: [PATCH 1/2] compat: move unaligned helpers to bswap.h

Quoted 7 lines · Jonathan Nieder
Quoted 5 lines · Jeff King

Commit d60c49c (read-cache.c: allow unaligned mapping of the index file, 2012-04-03) introduced helpers to access unaligned data. Let's factor them out to make them more widely available.

Quoted 6 lines
Quoted 3 lines

While we're at it, we'll give the helpers more readable names, add a helper for the "ntohll" form, and add the appropriate Makefile knob.

Weird. Why wasn't git broken on the relevant platforms before (given that no one has been setting NEEDS_ALIGNED_ACCESS for them)?

Because most of our data structures support aligned access. Thomas mentioned this as a potential issue earlier, and I said in a re-roll cover letter:

I did not include the NEEDS_ALIGNED_ACCESS patch. I note that we do not even have a Makefile knob for this, and the code in read-cache.c has probably never actually been used. Are there real systems that have a problem? The read-cache code was in support of the index v4 experiment, which did away with the 8-byte padding. So it could be that we simply don't see it, because everything is currently aligned.

I think it was a bug waiting to surface if index v4 ever got wide use.

-Peff

#15 lore raw

Re: [PATCH 1/2] compat: move unaligned helpers to bswap.h

Quoted 1 line · Jeff King

I think it was a bug waiting to surface if index v4 ever got wide use.

Ah, ok.

In that case I think git-compat-util.h should include something like what block-sha1/sha1.c has:

	#if !defined(__i386__) && !defined(__x86_64__) && \
	    !defined(_M_IX86) && !defined(_M_X64) && \
	    !defined(__ppc__) && !defined(__ppc64__) && \
	    !defined(__powerpc__) && !defined(__powerpc64__) && \
	    !defined(__s390__) && !defined(__s390x__)
	#define NEEDS_ALIGNED_ACCESS
	#endif

Otherwise we are relying on the person building to know their own architecture intimately, which shouldn't be necessary.

Meanwhile, as mentioned in the other message, I suspect the NEEDS_ALIGNED_ACCESS code path is broken for aggressive compilers anyway. Looking more.

Thanks,
Jonathan

author
#16 lore raw

Re: [PATCH 1/2] compat: move unaligned helpers to bswap.h

Quoted 17 lines · Jonathan Nieder
Quoted 1 line · Jeff King

I think it was a bug waiting to surface if index v4 ever got wide use.

Ah, ok.

In that case I think git-compat-util.h should include something like what block-sha1/sha1.c has:

	#if !defined(__i386__) && !defined(__x86_64__) && \
	    !defined(_M_IX86) && !defined(_M_X64) && \
	    !defined(__ppc__) && !defined(__ppc64__) && \
	    !defined(__powerpc__) && !defined(__powerpc64__) && \
	    !defined(__s390__) && !defined(__s390x__)
	#define NEEDS_ALIGNED_ACCESS
	#endif
Quoted 2 lines

Otherwise we are relying on the person building to know their own architecture intimately, which shouldn't be necessary.

Yeah, I agree it would be nice to autodetect. I just didn't know what the right set of platforms was, and assumed people would tweak the Makefile knob as appropriate (though it is probably much easier to do so within the compiler, where we have the right architecture variables set).

-Peff

#17 lore raw

Re: [PATCH 1/2] compat: move unaligned helpers to bswap.h

Quoted 13 lines · Jeff King
Quoted 11 lines · Jonathan Nieder

In that case I think git-compat-util.h should include something like what block-sha1/sha1.c has:

	#if !defined(__i386__) && !defined(__x86_64__) && \
	    !defined(_M_IX86) && !defined(_M_X64) && \
	    !defined(__ppc__) && !defined(__ppc64__) && \
	    !defined(__powerpc__) && !defined(__powerpc64__) && \
	    !defined(__s390__) && !defined(__s390x__)
	#define NEEDS_ALIGNED_ACCESS
	#endif
Quoted 4 lines
Quoted 2 lines

Otherwise we are relying on the person building to know their own architecture intimately, which shouldn't be necessary.

Yeah, I agree it would be nice to autodetect.

The nice thing is that false positives are harmless, modulo slowing down git a little if the compiler doesn't figure out how to optimize the NEEDS_ALIGNED_ACCESS codepath when on an unlisted platform that doesn't, in fact, need aligned access.

In other words, it would work out of the box for everybody.

author
#18 lore raw

Re: [PATCH 1/2] compat: move unaligned helpers to bswap.h

Quoted 17 lines · Jonathan Nieder
Quoted 16 lines · Jeff King
Quoted 13 lines · Jonathan Nieder

In that case I think git-compat-util.h should include something like what block-sha1/sha1.c has:

	#if !defined(__i386__) && !defined(__x86_64__) && \
	    !defined(_M_IX86) && !defined(_M_X64) && \
	    !defined(__ppc__) && !defined(__ppc64__) && \
	    !defined(__powerpc__) && !defined(__powerpc64__) && \
	    !defined(__s390__) && !defined(__s390x__)
	#define NEEDS_ALIGNED_ACCESS
	#endif

Otherwise we are relying on the person building to know their own architecture intimately, which shouldn't be necessary.

Quoted 6 lines
Quoted 1 line

Yeah, I agree it would be nice to autodetect.

The nice thing is that false positives are harmless, modulo slowing down git a little if the compiler doesn't figure out how to optimize the NEEDS_ALIGNED_ACCESS codepath when on an unlisted platform that doesn't, in fact, need aligned access.

OK, I'll refactor the knob.

-Peff

author
#19 lore raw

PATCH 2/2 ewah: support platforms that require aligned reads

In reply to Jeff King

From: Vicent Marti <[email protected]>

The caller may hand us an unaligned buffer (e.g., because it is an mmap of a file with many ewah bitmaps). On some platforms (like SPARC) this can cause a bus error. We can fix it with a combination of force-align macros and moving the data into an aligned buffer (which we would do anyway, but we can move it before fixing the endianness).

---
 ewah/ewah_io.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
ewah/ewah_io.c +24 -9
index aed0da6..1948ba5 100644
@@ -112,23 +112,38 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
 
 int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
 {
-	uint32_t *read32 = map;
-	eword_t *read64;
-	size_t i;
+	uint8_t *ptr = map;
+
+	self->bit_size = align_ntohl(*(uint32_t *)ptr);
+	ptr += sizeof(uint32_t);
+
+	self->buffer_size = self->alloc_size = align_ntohl(*(uint32_t *)ptr);
+	ptr += sizeof(uint32_t);
 
-	self->bit_size = ntohl(*read32++);
-	self->buffer_size = self->alloc_size = ntohl(*read32++);
 	self->buffer = ewah_realloc(self->buffer,
 		self->alloc_size * sizeof(eword_t));
 
 	if (!self->buffer)
 		return -1;
 
-	for (i = 0, read64 = (void *)read32; i < self->buffer_size; ++i)
-		self->buffer[i] = ntohll(*read64++);
+	/*
+	 * Copy the raw data for the bitmap as a whole chunk;
+	 * if we're in a little-endian platform, we'll perform
+	 * the endianness conversion in a separate pass to ensure
+	 * we're loading 8-byte aligned words.
+	 */
+	memcpy(self->buffer, ptr, self->buffer_size * sizeof(uint64_t));
+	ptr += self->buffer_size * sizeof(uint64_t);
+
+#if __BYTE_ORDER != __BIG_ENDIAN
+	{
+		size_t i;
+		for (i = 0; i < self->buffer_size; ++i)
+			self->buffer[i] = ntohll(self->buffer[i]);
+	}
+#endif
 
-	read32 = (void *)read64;
-	self->rlw = self->buffer + ntohl(*read32++);
+	self->rlw = self->buffer + align_ntohl(*(uint32_t *)ptr);
 
 	return (3 * 4) + (self->buffer_size * 8);
 }
Signature · 1 line
1.8.5.2.500.g8060133
#20 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

In reply to Jeff King
Quoted 4 lines · Jeff King

Here's a patch series (on top of jk/pack-bitmap, naturally) that lets t5310 pass there. I assume the ARM problem is the same, though seeing the failure in realloc() is unexpected. Can you try it on both your platforms with these patches?

Thanks. Trying it out now.

[...]

Quoted 9 lines
Quoted 5 lines

Hopefully it's possible to get the alignment right in the caller and tweak the signature to require that instead of using unaligned reads like this. There's still something wrong after this patch --- the new result is a NULL pointer dereference in t5310.7 "enumerate --objects (full bitmap)".

After my patches, t5310 runs fine for me. I didn't try your patch, but mine are similar. Let me know if you still see the problem (there may simply be a bug in yours, but I didn't see it).

I had left out a cast to unsigned, producing an overflow.

My main worry about the patches is that they will probably run into an analagous problem to the one that v1.7.12-rc0~1^2~2 (block-sha1:
avoid pointer conversion that violates alignment constraints, 2012-07-22) solved. By casting the pointer to (uint32_t *) we are telling the compiler it is 32-bit aligned (C99 section 6.3.2.3).

Thanks,
Jonathan

author
#21 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 11 lines · Jonathan Nieder
Quoted 3 lines

After my patches, t5310 runs fine for me. I didn't try your patch, but mine are similar. Let me know if you still see the problem (there may simply be a bug in yours, but I didn't see it).

I had left out a cast to unsigned, producing an overflow.

My main worry about the patches is that they will probably run into an analagous problem to the one that v1.7.12-rc0~1^2~2 (block-sha1:
avoid pointer conversion that violates alignment constraints, 2012-07-22) solved. By casting the pointer to (uint32_t *) we are telling the compiler it is 32-bit aligned (C99 section 6.3.2.3).

Yeah, maybe. We go via memcpy, which takes a "void *", so that part is good. However, the new code looks like:

  foo = align_ntohl(*(uint32_t *)ptr);

I think this probably works in practice because align_ntohl is inlined, and any sane compiler will never actually load the variable. If we change the signature of align_ntohl, we can do this:

  uint32_t align_ntohl(void *ptr)
  {
          uint32_t x;
          memcpy(x, ptr, sizeof(x));
          return ntohl(x);
  }

...

  foo = align_ntohl(ptr);

The memcpy solution is taken from read-cache.c, but as we noted, it probably hasn't been used a lot. The blk_sha1 get_be may be faster, as it converts as it reads. However, the bulk of the data is copied via a single memcpy and then modified in place. I don't know if that would be faster or not (for a big-endian system it probably is, since we can omit the modification loop entirely).

-Peff

#22 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 4 lines · Jeff King
Quoted 2 lines · Jonathan Nieder

My main worry about the patches is that they will probably run into an analagous problem to the one that v1.7.12-rc0~1^2~2

[...]

Quoted 2 lines

I think this probably works in practice because align_ntohl is inlined, and any sane compiler will never actually load the variable.

I don't think that's safe to rely on. The example named above didn't pose any problems except on one platform. All the relevant functions were static and easy to inline. GCC just followed the standard literally and chose to break by reading one word at a time, just like in this case it could break e.g. by copying one word at a time in __builtin_memcpy (which seems perfectly reasonable to me --- optimization involves a lot of constraint solving, and if you can't trust your constraints then there's not much you can do).

author
#23 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 9 lines · Jonathan Nieder
Quoted 4 lines · Jeff King
Quoted 2 lines · Jonathan Nieder

My main worry about the patches is that they will probably run into an analagous problem to the one that v1.7.12-rc0~1^2~2

[...]

Quoted 2 lines

I think this probably works in practice because align_ntohl is inlined, and any sane compiler will never actually load the variable.

Quoted 8 lines

I don't think that's safe to rely on. The example named above didn't pose any problems except on one platform. All the relevant functions were static and easy to inline. GCC just followed the standard literally and chose to break by reading one word at a time, just like in this case it could break e.g. by copying one word at a time in __builtin_memcpy (which seems perfectly reasonable to me --- optimization involves a lot of constraint solving, and if you can't trust your constraints then there's not much you can do).

I wasn't disagreeing with you. I was guessing at why it did not fail out of the box when I tested it. What do you think of the alternative I posted?

-Peff

#24 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

In reply to Jeff King
Quoted 10 lines · Jeff King

If we
change the signature of align_ntohl, we can do this:

  uint32_t align_ntohl(void *ptr)
  {
          uint32_t x;
          memcpy(x, ptr, sizeof(x));
          return ntohl(x);
  }
Quoted 7 lines

...

  foo = align_ntohl(ptr);

The memcpy solution is taken from read-cache.c, but as we noted, it probably hasn't been used a lot. The blk_sha1 get_be may be faster, as it converts as it reads.

I doubt there's much difference either way, especially after an optimizer gets its hands on it. According to [1] ARM has no fast byte swap instruction so with -O0 the byte-at-a-time implementation is probably faster there. I can try a performance test if you like.

Jonathan

[1] http://thread.gmane.org/gmane.comp.version-control.git/125737

author
#25 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 8 lines · Jonathan Nieder
Quoted 3 lines

The memcpy solution is taken from read-cache.c, but as we noted, it probably hasn't been used a lot. The blk_sha1 get_be may be faster, as it converts as it reads.

I doubt there's much difference either way, especially after an optimizer gets its hands on it. According to [1] ARM has no fast byte swap instruction so with -O0 the byte-at-a-time implementation is probably faster there. I can try a performance test if you like.

If you're curious and have time, go ahead and benchmark what I posted against what you posted (with your fix). But you'll probably need a big repo like the kernel to notice anything.

But I don't mind that much if we just use the memcpy trick for now. It's nice and obvious, and we can always change it later if somebody has numbers (I doubt it will be all that noticeable anyway; this isn't nearly as tight a loop as the BLK_SHA1 code).

-Peff

author
#26 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

In reply to Jeff King
Quoted 6 lines · Jeff King
Quoted 5 lines

My main worry about the patches is that they will probably run into an analagous problem to the one that v1.7.12-rc0~1^2~2 (block-sha1:
avoid pointer conversion that violates alignment constraints, 2012-07-22) solved. By casting the pointer to (uint32_t *) we are telling the compiler it is 32-bit aligned (C99 section 6.3.2.3).

Quoted 8 lines

Yeah, maybe. We go via memcpy, which takes a "void *", so that part is good. However, the new code looks like:

  foo = align_ntohl(*(uint32_t *)ptr);

I think this probably works in practice because align_ntohl is inlined, and any sane compiler will never actually load the variable. If we change the signature of align_ntohl, we can do this:

Actually, it is a little trickier than that. We actually take the address in the macro. So even without inlining, we end up casting to void. I still think this:

Quoted 6 lines
  uint32_t align_ntohl(void *ptr)
  {
          uint32_t x;
          memcpy(x, ptr, sizeof(x));
          return ntohl(x);
  }

is a little more obvious, though. It does mean that everybody has to pass a pointer, though, and on platforms where non-aligned reads are OK, we do the cast ourselves. That means that:

  foo = align_ntohl(&bar);

will not be able to do any type-checking for "bar" (say, when we are pulling "bar" straight out of a packed struct). I don't know how much we care.

-Peff

author
#28 lore raw

v2 cover unaligned reads from .bitmap files

In reply to Jeff King
Quoted 7 lines · Jeff King

Here's a patch series (on top of jk/pack-bitmap, naturally) that lets t5310 pass there. I assume the ARM problem is the same, though seeing the failure in realloc() is unexpected. Can you try it on both your platforms with these patches?

[1/2]: compat: move unaligned helpers to bswap.h [2/2]: ewah: support platforms that require aligned reads

Here it is again, fixing the issues we've discussed.

Instead of building on the code in read-cache, it pulls the much more battle-tested code from block-sha1, and refactors read-cache to use that instead. So the fix now kicks in automatically, and in theory it is a slight bit faster (though I still doubt it would even be measurable in this case).

[1/3]: block-sha1: factor out get_be and put_be wrappers [2/3]: read-cache: use get_be32 instead of hand-rolled ntoh_l [3/3]: ewah: support platforms that require aligned reads

-Peff

author
#29 lore raw

PATCH v2 1/3 block-sha1: factor out get_be and put_be wrappers

The BLK_SHA1 code has optimized wrappers for doing endian conversions on memory that may not be aligned. Let's pull them out so that we can use them elsewhere, especially the time-tested list of platforms that prefer each strategy.

---
These short names might not be descriptive enough now that they are globals. However, they make sense to me. I'm open to suggestions if somebody disagrees.

 block-sha1/sha1.c | 32 --------------------------------
 compat/bswap.h    | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 32 deletions(-)
block-sha1/sha1.c +0 -32
index e1a1eb6..22b125c 100644
@@ -62,38 +62,6 @@
   #define setW(x, val) (W(x) = (val))
 #endif
 
-/*
- * Performance might be improved if the CPU architecture is OK with
- * unaligned 32-bit loads and a fast ntohl() is available.
- * Otherwise fall back to byte loads and shifts which is portable,
- * and is faster on architectures with memory alignment issues.
- */
-
-#if defined(__i386__) || defined(__x86_64__) || \
-    defined(_M_IX86) || defined(_M_X64) || \
-    defined(__ppc__) || defined(__ppc64__) || \
-    defined(__powerpc__) || defined(__powerpc64__) || \
-    defined(__s390__) || defined(__s390x__)
-
-#define get_be32(p)	ntohl(*(unsigned int *)(p))
-#define put_be32(p, v)	do { *(unsigned int *)(p) = htonl(v); } while (0)
-
-#else
-
-#define get_be32(p)	( \
-	(*((unsigned char *)(p) + 0) << 24) | \
-	(*((unsigned char *)(p) + 1) << 16) | \
-	(*((unsigned char *)(p) + 2) <<  8) | \
-	(*((unsigned char *)(p) + 3) <<  0) )
-#define put_be32(p, v)	do { \
-	unsigned int __v = (v); \
-	*((unsigned char *)(p) + 0) = __v >> 24; \
-	*((unsigned char *)(p) + 1) = __v >> 16; \
-	*((unsigned char *)(p) + 2) = __v >>  8; \
-	*((unsigned char *)(p) + 3) = __v >>  0; } while (0)
-
-#endif
-
 /* This "rolls" over the 512-bit array */
 #define W(x) (array[(x)&15])
 
compat/bswap.h +32 -0
index c18a78e..7d17953 100644
@@ -122,3 +122,35 @@ static inline uint64_t git_bswap64(uint64_t x)
 #endif
 
 #endif
+
+/*
+ * Performance might be improved if the CPU architecture is OK with
+ * unaligned 32-bit loads and a fast ntohl() is available.
+ * Otherwise fall back to byte loads and shifts which is portable,
+ * and is faster on architectures with memory alignment issues.
+ */
+
+#if defined(__i386__) || defined(__x86_64__) || \
+    defined(_M_IX86) || defined(_M_X64) || \
+    defined(__ppc__) || defined(__ppc64__) || \
+    defined(__powerpc__) || defined(__powerpc64__) || \
+    defined(__s390__) || defined(__s390x__)
+
+#define get_be32(p)	ntohl(*(unsigned int *)(p))
+#define put_be32(p, v)	do { *(unsigned int *)(p) = htonl(v); } while (0)
+
+#else
+
+#define get_be32(p)	( \
+	(*((unsigned char *)(p) + 0) << 24) | \
+	(*((unsigned char *)(p) + 1) << 16) | \
+	(*((unsigned char *)(p) + 2) <<  8) | \
+	(*((unsigned char *)(p) + 3) <<  0) )
+#define put_be32(p, v)	do { \
+	unsigned int __v = (v); \
+	*((unsigned char *)(p) + 0) = __v >> 24; \
+	*((unsigned char *)(p) + 1) = __v >> 16; \
+	*((unsigned char *)(p) + 2) = __v >>  8; \
+	*((unsigned char *)(p) + 3) = __v >>  0; } while (0)
+
+#endif
Signature · 1 line
1.8.5.2.500.g8060133
#30 lore raw

Re: [PATCH 1/3] block-sha1: factor out get_be and put_be wrappers

Quoted 2 lines · Jeff King

These short names might not be descriptive enough now that they are globals. However, they make sense to me.

Yeah, I think they're clear. And they match the Linux kernel's get_unaligned_be32() / put_unaligned_be32().

author
#31 lore raw

PATCH v2 2/3 read-cache: use get_be32 instead of hand-rolled ntoh_l

In reply to Jeff King

Commit d60c49c (read-cache.c: allow unaligned mapping of the index file, 2012-04-03) introduced helpers to access unaligned data. However, we already have get_be32, which has a few advantages:

1. It's already written, so we avoid duplication.

2. It's probably faster, since it does the endian conversion and the alignment fix at the same time.

3. The get_be32 code is well-tested, having been in block-sha1 for a long time. By contrast, our custom helpers were probably almost never used, since the user needed to manually define a macro to enable them.

We have to add a get_be16 implementation to the existing get_be32, but that is very simple to do.

---
This _might_ still suffer from the issue fixed in 5f6a112 (block-sha1:
avoid pointer conversion that violates alignment constraints, 2012-07-22), as we are taking the pointer of a uint32 in a struct. But if that is the case, then the original did, as well. It's not clear to me if the casting get_be32 does is sufficient, or if a sufficiently clever compiler might make assumptions based on the original pointer type.

I'm inclined to leave it for now, as we haven't made anything worse, and nobody has reported a problem.

 compat/bswap.h |  4 ++++
 read-cache.c   | 44 ++++++++++++--------------------------------
 2 files changed, 16 insertions(+), 32 deletions(-)
compat/bswap.h +4 -0
index 7d17953..120c6c1 100644
@@ -136,11 +136,15 @@ static inline uint64_t git_bswap64(uint64_t x)
     defined(__powerpc__) || defined(__powerpc64__) || \
     defined(__s390__) || defined(__s390x__)
 
+#define get_be16(p)	ntohs(*(unsigned short *)(p))
 #define get_be32(p)	ntohl(*(unsigned int *)(p))
 #define put_be32(p, v)	do { *(unsigned int *)(p) = htonl(v); } while (0)
 
 #else
 
+#define get_be16(p)	( \
+	(*((unsigned char *)(p) + 0) << 8) | \
+	(*((unsigned char *)(p) + 1) << 0) )
 #define get_be32(p)	( \
 	(*((unsigned char *)(p) + 0) << 24) | \
 	(*((unsigned char *)(p) + 1) << 16) | \
read-cache.c +12 -32

68 lines not on this page · raw message

Signature · 1 line
1.8.5.2.500.g8060133
#32 lore raw

Re: [PATCH 2/3] read-cache: use get_be32 instead of hand-rolled ntoh_l

Quoted 3 lines · Jeff King

This _might_ still suffer from the issue fixed in 5f6a112 (block-sha1:
avoid pointer conversion that violates alignment constraints, 2012-07-22), as we are taking the pointer of a uint32 in a struct.

No conversion, so no issue there.

Line 1484 looks more problematic:

		disk_ce = (struct ondisk_cache_entry *)((char *)mmap + src_offset);

In v4 indexes, src_offset doesn't have any particular alignment so this conversion has undefined behavior.

Do you know if any tests exercise this code with paths that don't have convenient length?

[...]

Quoted 2 lines

I'm inclined to leave it for now, as we haven't made anything worse, and nobody has reported a problem.

Yeah, agreed.

Probably the simplest fix would be to take a char *, memcpy into a new (aligned) buffer and then byteswap in place, but that's orthogonal to this series.

Thanks,
Jonathan

author
#33 lore raw

Re: [PATCH 2/3] read-cache: use get_be32 instead of hand-rolled ntoh_l

Quoted 9 lines · Jonathan Nieder

Line 1484 looks more problematic:

		disk_ce = (struct ondisk_cache_entry *)((char *)mmap + src_offset);

In v4 indexes, src_offset doesn't have any particular alignment so this conversion has undefined behavior.

Do you know if any tests exercise this code with paths that don't have convenient length?

My impression was that we are not testing v4 index at all (and grepping for --index-version, which I think is the only way to write it, supports that).

-Peff

author
#34 lore raw

PATCH v2 3/3 ewah: support platforms that require aligned reads

In reply to Jeff King

From: Vicent Marti <[email protected]>

The caller may hand us an unaligned buffer (e.g., because it is an mmap of a file with many ewah bitmaps). On some platforms (like SPARC) this can cause a bus error. We can fix it with a combination of get_be32 and moving the data into an aligned buffer (which we would do anyway, but we can move it before fixing the endianness).

---
Tested on the SPARC I have access to. Please double-check that it also works fine on ARM.

 ewah/ewah_io.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
ewah/ewah_io.c +24 -9
index aed0da6..4a7fae6 100644
@@ -112,23 +112,38 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
 
 int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
 {
-	uint32_t *read32 = map;
-	eword_t *read64;
-	size_t i;
+	uint8_t *ptr = map;
+
+	self->bit_size = get_be32(ptr);
+	ptr += sizeof(uint32_t);
+
+	self->buffer_size = self->alloc_size = get_be32(ptr);
+	ptr += sizeof(uint32_t);
 
-	self->bit_size = ntohl(*read32++);
-	self->buffer_size = self->alloc_size = ntohl(*read32++);
 	self->buffer = ewah_realloc(self->buffer,
 		self->alloc_size * sizeof(eword_t));
 
 	if (!self->buffer)
 		return -1;
 
-	for (i = 0, read64 = (void *)read32; i < self->buffer_size; ++i)
-		self->buffer[i] = ntohll(*read64++);
+	/*
+	 * Copy the raw data for the bitmap as a whole chunk;
+	 * if we're in a little-endian platform, we'll perform
+	 * the endianness conversion in a separate pass to ensure
+	 * we're loading 8-byte aligned words.
+	 */
+	memcpy(self->buffer, ptr, self->buffer_size * sizeof(uint64_t));
+	ptr += self->buffer_size * sizeof(uint64_t);
+
+#if __BYTE_ORDER != __BIG_ENDIAN
+	{
+		size_t i;
+		for (i = 0; i < self->buffer_size; ++i)
+			self->buffer[i] = ntohll(self->buffer[i]);
+	}
+#endif
 
-	read32 = (void *)read64;
-	self->rlw = self->buffer + ntohl(*read32++);
+	self->rlw = self->buffer + get_be32(ptr);
 
 	return (3 * 4) + (self->buffer_size * 8);
 }
Signature · 1 line
1.8.5.2.500.g8060133
Reviewed-by on v2 3/3
#35 lore raw

Re: [PATCH 3/3] ewah: support platforms that require aligned reads

Quoted 3 lines · Jeff King
ewah/ewah_io.c +0 -0
@@ -112,23 +112,38 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)

[...]

Quoted 1 line

+#if __BYTE_ORDER != __BIG_ENDIAN

Is this portable?

On a platform without __BYTE_ORDER or __BIG_ENDIAN defined, it is interpreted as

	#if 0 != 0

which means that such platforms are assumed to be big endian. Does Mingw define __BYTE_ORDER, for example?

ewah/ewah_io.c

Quoted 6 lines
ewah/ewah_io.c +6 -0
+	{
+		size_t i;
+		for (i = 0; i < self->buffer_size; ++i)
+			self->buffer[i] = ntohll(self->buffer[i]);
+	}
+#endif

It's tempting to guard with something like

	if (ntohl(1) != 1) {
		...
	}

The optimizer can tell if this is true or false at compile time, so it shouldn't slow anything down.

With that change,

Thanks for the quick fix.

ewah/ewah_io.c +1 -3
index 4a7fae6..5a527a4 100644
@@ -135,13 +135,11 @@ int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
 	memcpy(self->buffer, ptr, self->buffer_size * sizeof(uint64_t));
 	ptr += self->buffer_size * sizeof(uint64_t);
 
-#if __BYTE_ORDER != __BIG_ENDIAN
-	{
+	if (ntohl(1) != 1) {
 		size_t i;
 		for (i = 0; i < self->buffer_size; ++i)
 			self->buffer[i] = ntohll(self->buffer[i]);
 	}
-#endif
 
 	self->rlw = self->buffer + get_be32(ptr);
 
#36 lore raw

Re: [PATCH 3/3] ewah: support platforms that require aligned reads

Quoted 7 lines · Jonathan Nieder
Quoted 3 lines
ewah/ewah_io.c +0 -0
@@ -112,23 +112,38 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)

[...]

Quoted 1 line

+#if __BYTE_ORDER != __BIG_ENDIAN

Is this portable?

We explicitly set the __BYTE_ORDER macros in compat/bswap.h. In fact, this preprocessor conditional is the same one that we use when choosing what version of the ntohl macro to define, so that's why I decided to use it here.

#37 lore raw

Re: [PATCH 3/3] ewah: support platforms that require aligned reads

Quoted 10 lines · Vicent Martí
Quoted 3 lines · Jonathan Nieder
Quoted 1 line

+#if __BYTE_ORDER != __BIG_ENDIAN

Is this portable?

We explicitly set the __BYTE_ORDER macros in compat/bswap.h. In fact, this preprocessor conditional is the same one that we use when choosing what version of the ntohl macro to define, so that's why I decided to use it here.

Ah, thanks. Sorry I missed that. So feel free to add my reviewed-by to the patch without my tweak, too.

#39 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

In reply to Jeff King
Quoted 4 lines · Jeff King
Quoted 2 lines · Jonathan Nieder

Jeff King wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

EWAH 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).

I suspect that for some callers it's not word-aligned.

Yes, the mmap'd buffers aren't necessarily word-aligned. I don't think we can fix that easily without changing the on-disk format (which comes from JGit anyway).

Ouch, sorry about that. JGit doesn't mmap the file so we didn't think about the impact of words not being aligned. I should have caught that, but I didn't.

author
#40 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 7 lines · Shawn Pearce
Quoted 3 lines

Yes, the mmap'd buffers aren't necessarily word-aligned. I don't think we can fix that easily without changing the on-disk format (which comes from JGit anyway).

Ouch, sorry about that. JGit doesn't mmap the file so we didn't think about the impact of words not being aligned. I should have caught that, but I didn't.

Looking over the format, I think the only thing preventing 4-byte alignment is the 1-byte XOR-offset and 1-byte flags field for each bitmap. If we ever have a v2, we could pad the sum of those out to 4 bytes. Is 4-byte alignment enough? We do treat the actual data as 64-bit integers. I wonder if that would have problems on Sparc64, for example.

-Peff

#41 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 5 lines · Jeff King

Looking over the format, I think the only thing preventing 4-byte alignment is the 1-byte XOR-offset and 1-byte flags field for each bitmap. If we ever have a v2, we could pad the sum of those out to 4 bytes. Is 4-byte alignment enough? We do treat the actual data as 64-bit integers. I wonder if that would have problems on Sparc64, for example.

Yes, it will. SPARC requires all loads be naturally aligned (4-byte to an address that's a multiple of 4, 8-byte to a multiple of 8, and so on). In general, architectures that do not support unaligned access require natural alignment for all quantities.

Also, even on architectures where the kernel can fix these alignment issues up, the cost of doing so is a two context switches (in and out of the kernel), servicing the trap, two loads, some shifts and rotates, and a kernel message, so many people disable alignment fixups. I know it made things extremely slow on Alpha. ARM is even more fun since if you don't take the trap, it loads the data rotated, so the load happens, it just silently returns the wrong data.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
author
#42 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 11 lines · brian m. carlson
Quoted 5 lines · Jeff King

Looking over the format, I think the only thing preventing 4-byte alignment is the 1-byte XOR-offset and 1-byte flags field for each bitmap. If we ever have a v2, we could pad the sum of those out to 4 bytes. Is 4-byte alignment enough? We do treat the actual data as 64-bit integers. I wonder if that would have problems on Sparc64, for example.

Yes, it will. SPARC requires all loads be naturally aligned (4-byte to an address that's a multiple of 4, 8-byte to a multiple of 8, and so on). In general, architectures that do not support unaligned access require natural alignment for all quantities.

In that case, I think we cannot even blame Shawn. The ewah serialization format itself (which JGit inherited from the javaewah library) has 8 bytes of header and 4 bytes of trailer. So packed serialized ewahs wouldn't be 8-byte aligned (though of course he could have added his own padding to each when we have a sequence of them).

-Peff

#43 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 11 lines · Jeff King
Quoted 4 lines · brian m. carlson

Yes, it will. SPARC requires all loads be naturally aligned (4-byte to an address that's a multiple of 4, 8-byte to a multiple of 8, and so on). In general, architectures that do not support unaligned access require natural alignment for all quantities.

In that case, I think we cannot even blame Shawn. The ewah serialization format itself (which JGit inherited from the javaewah library) has 8 bytes of header and 4 bytes of trailer. So packed serialized ewahs wouldn't be 8-byte aligned

I don't think that's a big issue. A pair of 4-byte reads would not be too slow.

Even on x86, aligned reads are supposed to be faster than unaligned reads (though I haven't looked at benchmarks recently).

author
#44 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 8 lines · Jonathan Nieder
Quoted 7 lines · Jeff King
Quoted 4 lines · brian m. carlson

Yes, it will. SPARC requires all loads be naturally aligned (4-byte to an address that's a multiple of 4, 8-byte to a multiple of 8, and so on). In general, architectures that do not support unaligned access require natural alignment for all quantities.

Quoted 7 lines
Quoted 4 lines

In that case, I think we cannot even blame Shawn. The ewah serialization format itself (which JGit inherited from the javaewah library) has 8 bytes of header and 4 bytes of trailer. So packed serialized ewahs wouldn't be 8-byte aligned

I don't think that's a big issue. A pair of 4-byte reads would not be too slow.

The header is actually two separate 4-byte values, so that's fine. But between the header and trailer are a series of 8-byte data values, and that is what we need the 8-byte alignment for. So the _first_ ewah's data is 8-byte aligned, but then it offsets the alignment with a single 4-byte trailer. So the next ewah, if they are packed in a sequence, is will have its data misaligned.

You could solve it by putting an empty 4-byte pad at the end of each ewah (and of course making sure the first one is 8-byte aligned).

Anyway, this is all academic until we are designing bitmap v2, which I do not plan on doing anytime soon.

-Peff

#45 lore raw

Re: [PATCH v4 08/23] ewah: compressed bitmap implementation

Quoted 8 lines · Jeff King
Quoted 2 lines · Jonathan Nieder

I don't think that's a big issue. A pair of 4-byte reads would not be too slow.

The header is actually two separate 4-byte values, so that's fine. But between the header and trailer are a series of 8-byte data values, and that is what we need the 8-byte alignment for.

Sorry for the lack of clarity. What I meant is that a 4-byte aligned 8-byte value can be read using a pair of 4-byte reads, which is less of a performance issue than a completely unaligned value.

[...]

Quoted 2 lines

Anyway, this is all academic until we are designing bitmap v2, which I do not plan on doing anytime soon.

Sure, fair enough. :)

Jonathan

author
#46 lore raw

PATCH v4 9/23 documentation: add documentation for the bitmap format

In reply to Jeff King

From: Vicent Marti <[email protected]>

This is the technical documentation for the JGit-compatible Bitmap v1 on-disk format.

---
 Documentation/technical/bitmap-format.txt | 131 ++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 Documentation/technical/bitmap-format.txt
Documentation/technical/bitmap-format.txt new file +131 -0
new file mode 100644
index 0000000..7a86bd7
@@ -0,0 +1,131 @@
+GIT bitmap v1 format
+====================
+
+	- A header appears at the beginning:
+
+		4-byte signature: {'B', 'I', 'T', 'M'}
+
+		2-byte version number (network byte order)
+			The current implementation only supports version 1
+			of the bitmap index (the same one as JGit).
+
+		2-byte flags (network byte order)
+
+			The following 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.
+
+		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.
+
+	- 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 is of that type.
+
+		The obvious consequence is that the OR of all 4 bitmaps will result
+		in a full set (all bits set), and the AND of all 4 bitmaps will
+		result in an empty bitmap (no bits set).
+
+	- N entries with compressed bitmaps, one for each indexed commit
+
+		Where `N` is the total amount of entries in this bitmap index.
+		Each entry contains the following:
+
+		- 4-byte object position (network byte order)
+			The position **in the index for the packfile** where the
+			bitmap for this commit is found.
+
+		- 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 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 positive, 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.
+
+		- The compressed bitmap itself, see Appendix A.
+
+== Appendix A: Serialization format for an EWAH bitmap
+
+Ewah bitmaps are serialized in the same 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
+
+All words are stored in network byte order for their corresponding
+sizes.
+
+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
+pointer to the last RLW in the stream.
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#47 lore raw

PATCH v4 10/23 pack-bitmap: add support for bitmap indexes

In reply to Jeff King

From: Vicent Marti <[email protected]>

A 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 packfile; if it's set to 1, the object is reachable.

By using the bitmaps available in the index, this commit implements several new functions:

- prepare_bitmap_git
- prepare_bitmap_walk
- traverse_bitmap_commit_list
- reuse_partial_packfile_from_bitmap

The prepare_bitmap_walk 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.

As an extra optimization, when prepare_bitmap_walk succeeds, the reuse_partial_packfile_from_bitmap call can be attempted: it will find the amount of objects at the beginning of the on-disk packfile that can be reused as-is, and return an offset into the packfile. The source packfile can then be loaded and the bytes up to offset can be written directly to the result without having to consider the entires inside the packfile individually.

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 set 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 further patches, we'll use this bitmap traversal optimization to speed up the pack-objects and rev-list commands.

---
 Makefile      |   2 +
 khash.h       | 338 ++++++++++++++++++++
 pack-bitmap.c | 970 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pack-bitmap.h |  43 +++
 4 files changed, 1353 insertions(+)
 create mode 100644 khash.h
 create mode 100644 pack-bitmap.c
 create mode 100644 pack-bitmap.h
Makefile +2 -0
index 64a1ed7..b983d78 100644
@@ -699,6 +699,7 @@ LIB_H += object.h
 LIB_H += pack-objects.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
@@ -837,6 +838,7 @@ LIB_OBJS += notes-cache.o
 LIB_OBJS += notes-merge.o
 LIB_OBJS += notes-utils.o
 LIB_OBJS += object.o
+LIB_OBJS += pack-bitmap.o
 LIB_OBJS += pack-check.o
 LIB_OBJS += pack-objects.o
 LIB_OBJS += pack-revindex.o
khash.h new file +338 -0

338 lines not on this page · raw message

pack-bitmap.c new file +970 -0

970 lines not on this page · raw message

pack-bitmap.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
1.8.5.1.399.g900e7cd
author
#48 lore raw

PATCH v4 11/23 pack-objects: split add_object_entry

In reply to Jeff King

This function actually does three things:

1. Check whether we've already added the object to our packing list.

2. Check whether the object meets our criteria for adding.

3. Actually add the object to our packing list.

It's a little hard to see these three phases, because they happen linearly in the rather long function. Instead, this patch breaks them up into three separate helper functions.

The result is a little easier to follow, though it unfortunately suffers from some optimization interdependencies between the stages (e.g., during step 3 we use the packing list index from step 1 and the packfile information from step 2).

More importantly, though, the various parts can be composed differently, as they will be in the next patch.

---
 builtin/pack-objects.c | 98 +++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 78 insertions(+), 20 deletions(-)
builtin/pack-objects.c +78 -20
index faf746b..13b171d 100644
@@ -800,41 +800,69 @@ 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)
+/*
+ * When adding an object, check whether we have already added it
+ * to our packing list. If so, we can skip. However, if we are
+ * being asked to excludei t, but the previous mention was to include
+ * it, make sure to adjust its flags and tweak our numbers accordingly.
+ *
+ * As an optimization, we pass out the index position where we would have
+ * found the item, since that saves us from having to look it up again a
+ * few lines later when we want to add the new entry.
+ */
+static int have_duplicate_entry(const unsigned char *sha1,
+				int exclude,
+				uint32_t *index_pos)
 {
 	struct object_entry *entry;
-	struct packed_git *p, *found_pack = NULL;
-	off_t found_offset = 0;
-	uint32_t hash = pack_name_hash(name);
-	uint32_t index_pos;
 
-	entry = packlist_find(&to_pack, sha1, &index_pos);
-	if (entry) {
-		if (exclude) {
-			if (!entry->preferred_base)
-				nr_result--;
-			entry->preferred_base = 1;
-		}
+	entry = packlist_find(&to_pack, sha1, index_pos);
+	if (!entry)
 		return 0;
+
+	if (exclude) {
+		if (!entry->preferred_base)
+			nr_result--;
+		entry->preferred_base = 1;
 	}
 
+	return 1;
+}
+
+/*
+ * Check whether we want the object in the pack (e.g., we do not want
+ * objects found in non-local stores if the "--local" option was used).
+ *
+ * As a side effect of this check, we will find the packed version of this
+ * object, if any. We therefore pass out the pack information to avoid having
+ * to look it up again later.
+ */
+static int want_object_in_pack(const unsigned char *sha1,
+			       int exclude,
+			       struct packed_git **found_pack,
+			       off_t *found_offset)
+{
+	struct packed_git *p;
+
 	if (!exclude && local && has_loose_object_nonlocal(sha1))
 		return 0;
 
+	*found_pack = NULL;
+	*found_offset = 0;
+
 	for (p = packed_git; p; p = p->next) {
 		off_t offset = find_pack_entry_one(sha1, p);
 		if (offset) {
-			if (!found_pack) {
+			if (!*found_pack) {
 				if (!is_pack_valid(p)) {
 					warning("packfile %s cannot be accessed", p->pack_name);
 					continue;
 				}
-				found_offset = offset;
-				found_pack = p;
+				*found_offset = offset;
+				*found_pack = p;
 			}
 			if (exclude)
-				break;
+				return 1;
 			if (incremental)
 				return 0;
 			if (local && !p->pack_local)
@@ -844,6 +872,20 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
 		}
 	}
 
+	return 1;
+}
+
+static void create_object_entry(const unsigned char *sha1,
+				enum object_type type,
+				uint32_t hash,
+				int exclude,
+				int no_try_delta,
+				uint32_t index_pos,
+				struct packed_git *found_pack,
+				off_t found_offset)
+{
+	struct object_entry *entry;
+
 	entry = packlist_alloc(&to_pack, sha1, index_pos);
 	entry->hash = hash;
 	if (type)
@@ -857,11 +899,27 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
 		entry->in_pack_offset = found_offset;
 	}
 
-	display_progress(progress_state, to_pack.nr_objects);
+	entry->no_try_delta = no_try_delta;
+}
+
+static int add_object_entry(const unsigned char *sha1, enum object_type type,
+			    const char *name, int exclude)
+{
+	struct packed_git *found_pack;
+	off_t found_offset;
+	uint32_t index_pos;
 
-	if (name && no_try_delta(name))
-		entry->no_try_delta = 1;
+	if (have_duplicate_entry(sha1, exclude, &index_pos))
+		return 0;
 
+	if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset))
+		return 0;
+
+	create_object_entry(sha1, type, pack_name_hash(name),
+			    exclude, name && no_try_delta(name),
+			    index_pos, found_pack, found_offset);
+
+	display_progress(progress_state, to_pack.nr_objects);
 	return 1;
 }
 
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#49 lore raw

PATCH v4 12/23 pack-objects: use bitmaps when packing objects

In reply to Jeff King

From: Vicent Marti <[email protected]>

In this patch, we use the bitmap API to perform the Counting Objects phase in pack-objects, rather than a traditional walk through the object graph. For a reasonably-packed large repo, the time to fetch and clone is often dominated by the full-object revision walk during the Counting Objects phase. Using bitmaps can reduce the CPU time required on the server (and therefore start sending the actual pack data with less delay).

For bitmaps to be used, the following must be true:

1. We must be packing to stdout (as a normal pack-objects from upload-pack would do).

2. There must be a .bitmap index containing at least one of the "have" objects that the client is asking for.

3. Bitmaps must be enabled (they are enabled by default, but can be disabled by setting pack.usebitmaps to false, or by using --no-use-bitmap-index on the command-line).

If any of these is not true, we fall back to doing a normal walk of the object graph.

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) that show the speedup produced by various methods:

    [existing graph traversal]
    $ time git pack-objects --all --stdout --no-use-bitmap-index \
			    </dev/null >/dev/null
    Counting objects: 3237103, done.
    Compressing objects: 100% (508752/508752), done.
    Total 3237103 (delta 2699584), reused 3237103 (delta 2699584)

    real    0m44.111s
    user    0m42.396s
    sys     0m3.544s

    [bitmaps only, without partial pack reuse; note that
     pack reuse is automatic, so timing this required a
     patch to disable it]
    $ time git pack-objects --all --stdout </dev/null >/dev/null
    Counting objects: 3237103, done.
    Compressing objects: 100% (508752/508752), done.
    Total 3237103 (delta 2699584), reused 3237103 (delta 2699584)

    real    0m5.413s
    user    0m5.604s
    sys     0m1.804s

    [bitmaps with pack reuse (what you get with this patch)]
    $ time git pack-objects --all --stdout </dev/null >/dev/null
    Reusing existing pack: 3237103, done.
    Total 3237103 (delta 0), reused 0 (delta 0)

    real    0m1.636s
    user    0m1.460s
    sys     0m0.172s
---
 Documentation/config.txt |   6 +++
 builtin/pack-objects.c   | 107 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
Documentation/config.txt +6 -0
index ab26963..a981369 100644
@@ -1858,6 +1858,12 @@ pack.packSizeLimit::
 	Common unit suffixes of 'k', 'm', or 'g' are
 	supported.
 
+pack.useBitmaps::
+	When true, git will use pack bitmaps (if available) when packing
+	to stdout (e.g., during the server side of a fetch). Defaults to
+	true. You should not generally need to turn this off unless
+	you are debugging pack bitmaps.
+
 pager.<cmd>::
 	If the value is boolean, turns on or off pagination of the
 	output of a particular Git subcommand when writing to a tty.
builtin/pack-objects.c +107 -0

167 lines not on this page · raw message

Signature · 1 line
1.8.5.1.399.g900e7cd
author
#50 lore raw

PATCH v4 13/23 rev-list: add bitmap mode to speed up object lists

In reply to Jeff King

From: Vicent Marti <[email protected]>

The 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 (i.e., not the path names at which trees and blobs were found).

Calling git rev-list --objects --use-bitmap-index [committish] will perform an object iteration based on a bitmap result instead of actually walking the object graph.

These are some example timings for torvalds/linux (warm cache, best-of-five):

    $ time git rev-list --objects master > /dev/null
    real    0m34.191s
    user    0m33.904s
    sys     0m0.268s
    $ time git rev-list --objects --use-bitmap-index master > /dev/null
    real    0m1.041s
    user    0m0.976s
    sys     0m0.064s

Likewise, using git rev-list --count --use-bitmap-index will speed up the counting operation by building the resulting bitmap and performing a fast popcount (number of bits set on the bitmap) on the result.

Here are some sample timings of different ways to count commits in torvalds/linux:

    $ time git rev-list master | wc -l
        399882
        real    0m6.524s
        user    0m6.060s
        sys     0m3.284s
    $ time git rev-list --count master
        399882
        real    0m4.318s
        user    0m4.236s
        sys     0m0.076s
    $ time git rev-list --use-bitmap-index --count master
        399882
        real    0m0.217s
        user    0m0.176s
        sys     0m0.040s

This also respects negative refs, so you can use it to count a slice of history:

        $ time git rev-list --count v3.0..master
        144843
        real    0m1.971s
        user    0m1.932s
        sys     0m0.036s
        $ time git rev-list --use-bitmap-index --count v3.0..master
        real    0m0.280s
        user    0m0.220s
        sys     0m0.056s

Though note that the closer the endpoints, the less it helps. In the traversal case, we have fewer commits to cross, so we take less time. But the bitmap time is dominated by generating the pack revindex, which is constant with respect to the refs given.

Note that you cannot yet get a fast --left-right count of a symmetric difference (e.g., "--count --left-right master...topic"). The slow part of that walk actually happens during the merge-base determination when we parse "master...topic". Even though a count does not actually need to know the real merge base (it only needs to take the symmetric difference of the bitmaps), the revision code would require some refactoring to handle this case.

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. This can be used to exercise the bitmap code, and also to verify that the contents of the .bitmap file are sane.

---
 Documentation/git-rev-list.txt     |  1 +
 Documentation/rev-list-options.txt |  8 ++++++++
 builtin/rev-list.c                 | 39 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
Documentation/git-rev-list.txt +1 -0
index 045b37b..7a1585d 100644
@@ -55,6 +55,7 @@ SYNOPSIS
 	     [ \--reverse ]
 	     [ \--walk-reflogs ]
 	     [ \--no-walk ] [ \--do-walk ]
+	     [ \--use-bitmap-index ]
 	     <commit>... [ \-- <paths>... ]
 
 DESCRIPTION
Documentation/rev-list-options.txt +8 -0
index 5bdfb42..c236b85 100644
@@ -274,6 +274,14 @@ See also linkgit:git-reflog[1].
 	Output excluded boundary commits. Boundary commits are
 	prefixed with `-`.
 
+ifdef::git-rev-list[]
+--use-bitmap-index::
+
+	Try to speed up the traversal using the pack bitmap index (if
+	one is available). Note that when traversing with `--objects`,
+	trees and blobs will not have their associated path printed.
+endif::git-rev-list[]
+
 --
 
 History Simplification
builtin/rev-list.c +39 -0
index 4fc1616..5209255 100644
@@ -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"
@@ -257,6 +259,18 @@ 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,
+	int exclude,
+	uint32_t name_hash,
+	struct packed_git *found_pack,
+	off_t found_offset)
+{
+	fprintf(stdout, "%s\n", sha1_to_hex(sha1));
+	return 1;
+}
+
 int cmd_rev_list(int argc, const char **argv, const char *prefix)
 {
 	struct rev_info revs;
@@ -265,6 +279,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_bitmap_index = 0;
 
 	git_config(git_default_config, NULL);
 	init_revisions(&revs, prefix);
@@ -306,6 +321,14 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 			bisect_show_vars = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--use-bitmap-index")) {
+			use_bitmap_index = 1;
+			continue;
+		}
+		if (!strcmp(arg, "--test-bitmap")) {
+			test_bitmap_walk(&revs);
+			return 0;
+		}
 		usage(rev_list_usage);
 
 	}
@@ -333,6 +356,22 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 	if (bisect_list)
 		revs.limited = 1;
 
+	if (use_bitmap_index) {
+		if (revs.count && !revs.left_right && !revs.cherry_mark) {
+			uint32_t commit_count;
+			if (!prepare_bitmap_walk(&revs)) {
+				count_bitmap_commit_list(&commit_count, NULL, NULL, NULL);
+				printf("%d\n", commit_count);
+				return 0;
+			}
+		} else if (revs.tag_objects && revs.tree_objects && revs.blob_objects) {
+			if (!prepare_bitmap_walk(&revs)) {
+				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.8.5.1.399.g900e7cd
author
#51 lore raw

PATCH v4 14/23 pack-objects: implement bitmap writing

In reply to Jeff King

From: Vicent Marti <[email protected]>

This 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 bitmap writing is enabled for a given repository (either by calling pack-objects with the --write-bitmap-index flag or by having pack.writebitmaps 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_set_checksum: this call stores the partial checksum for the packfile being written; the checksum will be written in the resulting bitmap index to verify its integrity

2. bitmap_writer_build_type_index: this call uses the array of struct object_entry 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.

3. bitmap_writer_reuse_bitmaps: if there exists an existing bitmap index for one of the packfiles we're trying to repack, this call will efficiently rebuild the existing bitmaps so they can be reused on the new index. All the existing bitmaps will be stored in a reuse hash table, and the commit selection phase will prioritize these when selecting, as they can be written directly to the new index without having to perform a revision walk to fill the bitmap. This can greatly speed up the repack of a repository that already has bitmaps.

4. 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.

5. 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 can 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 gives good results in practice, because there is locality in the ordering of the objects (and therefore bitmaps) in the packfile.

6. 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.

---
 Documentation/config.txt |   8 +
 Makefile                 |   1 +
 builtin/pack-objects.c   |  53 +++++
 pack-bitmap-write.c      | 535 +++++++++++++++++++++++++++++++++++++++++++++++
 pack-bitmap.c            |  92 ++++++++
 pack-bitmap.h            |  19 ++
 pack-objects.h           |   1 +
 pack-write.c             |   2 +
 8 files changed, 711 insertions(+)
 create mode 100644 pack-bitmap-write.c
Documentation/config.txt +8 -0
index a981369..4b0c368 100644
@@ -1864,6 +1864,14 @@ pack.useBitmaps::
 	true. You should not generally need to turn this off unless
 	you are debugging pack bitmaps.
 
+pack.writebitmaps::
+	When true, git will write a bitmap index when packing all
+	objects to disk (e.g., when `git repack -a` is run).  This
+	index can speed up the "counting objects" phase of subsequent
+	packs created for clones and fetches, at the cost of some disk
+	space and extra time spent on the initial repack.  Defaults to
+	false.
+
 pager.<cmd>::
 	If the value is boolean, turns on or off pagination of the
 	output of a particular Git subcommand when writing to a tty.
Makefile +1 -0
index b983d78..555d44c 100644
@@ -839,6 +839,7 @@ LIB_OBJS += notes-merge.o
 LIB_OBJS += notes-utils.o
 LIB_OBJS += object.o
 LIB_OBJS += pack-bitmap.o
+LIB_OBJS += pack-bitmap-write.o
 LIB_OBJS += pack-check.o
 LIB_OBJS += pack-objects.o
 LIB_OBJS += pack-revindex.o
builtin/pack-objects.c +53 -0

104 lines not on this page · raw message

pack-bitmap-write.c new file +535 -0

535 lines not on this page · raw message

pack-bitmap.c +92 -0

95 lines not on this page · raw message

pack-bitmap.h +19 -0
index b4510d5..09acf02 100644
@@ -3,6 +3,7 @@
 
 #include "ewah/ewok.h"
 #include "khash.h"
+#include "pack-objects.h"
 
 struct bitmap_disk_entry {
 	uint32_t object_pos;
@@ -20,10 +21,16 @@ struct bitmap_disk_header {
 
 static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
 
+#define NEEDS_BITMAP (1u<<22)
+
 enum pack_bitmap_opts {
 	BITMAP_OPT_FULL_DAG = 1
 };
 
+enum pack_bitmap_flags {
+	BITMAP_FLAG_REUSE = 0x1
+};
+
 typedef int (*show_reachable_fn)(
 	const unsigned char *sha1,
 	enum object_type type,
@@ -39,5 +46,17 @@ void test_bitmap_walk(struct rev_info *revs);
 char *pack_bitmap_filename(struct packed_git *p);
 int prepare_bitmap_walk(struct rev_info *revs);
 int reuse_partial_packfile_from_bitmap(struct packed_git **packfile, uint32_t *entries, off_t *up_to);
+int rebuild_existing_bitmaps(struct packing_data *mapping, khash_sha1 *reused_bitmaps, int show_progress);
+
+void bitmap_writer_show_progress(int show);
+void bitmap_writer_set_checksum(unsigned char *sha1);
+void bitmap_writer_build_type_index(struct pack_idx_entry **index, uint32_t index_nr);
+void bitmap_writer_reuse_bitmaps(struct packing_data *to_pack);
+void bitmap_writer_select_commits(struct commit **indexed_commits,
+		unsigned int indexed_commits_nr, int max_bitmaps);
+void bitmap_writer_build(struct packing_data *to_pack);
+void bitmap_writer_finish(struct pack_idx_entry **index,
+			  uint32_t index_nr,
+			  const char *filename);
 
 #endif
pack-objects.h +1 -0
index 90ad0a8..d1b98b3 100644
@@ -17,6 +17,7 @@ struct object_entry {
 	enum object_type type;
 	enum object_type in_pack_type;	/* could be delta */
 	uint32_t hash;			/* name hint hash */
+	unsigned int in_pack_pos;
 	unsigned char in_pack_header_size;
 	unsigned preferred_base:1; /*
 				    * we do not pack this, but is available
pack-write.c +2 -0
index ca9e63b..6203d37 100644
@@ -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.8.5.1.399.g900e7cd
author
#52 lore raw

PATCH v4 15/23 repack: stop using magic number for ARRAY_SIZE(exts)

In reply to Jeff King

We have a static array of extensions, but hardcode the size of the array in our loops. Let's pull out this magic number, which will make it easier to change.

---
 builtin/repack.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/repack.c +4 -4
index a0ff5c7..2e88975 100644
@@ -115,7 +115,7 @@ static void remove_redundant_pack(const char *dir_name, const char *base_name)
 
 int cmd_repack(int argc, const char **argv, const char *prefix)
 {
-	const char *exts[2] = {".pack", ".idx"};
+	const char *exts[] = {".pack", ".idx"};
 	struct child_process cmd;
 	struct string_list_item *item;
 	struct argv_array cmd_args = ARGV_ARRAY_INIT;
@@ -258,7 +258,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	 */
 	failed = 0;
 	for_each_string_list_item(item, &names) {
-		for (ext = 0; ext < 2; ext++) {
+		for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
 			char *fname, *fname_old;
 			fname = mkpathdup("%s/%s%s", packdir,
 						item->string, exts[ext]);
@@ -315,7 +315,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
 	/* Now the ones with the same name are out of the way... */
 	for_each_string_list_item(item, &names) {
-		for (ext = 0; ext < 2; ext++) {
+		for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
 			char *fname, *fname_old;
 			struct stat statbuffer;
 			fname = mkpathdup("%s/pack-%s%s",
@@ -335,7 +335,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
 	/* Remove the "old-" files */
 	for_each_string_list_item(item, &names) {
-		for (ext = 0; ext < 2; ext++) {
+		for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
 			char *fname;
 			fname = mkpath("%s/old-pack-%s%s",
 					packdir,
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#53 lore raw

PATCH v4 16/23 repack: turn exts array into array-of-struct

In reply to Jeff King

This is slightly more verbose, but will let us annotate the extensions with further options in future commits.

---
 builtin/repack.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
builtin/repack.c +11 -6
index 2e88975..a176de2 100644
@@ -115,7 +115,12 @@ static void remove_redundant_pack(const char *dir_name, const char *base_name)
 
 int cmd_repack(int argc, const char **argv, const char *prefix)
 {
-	const char *exts[] = {".pack", ".idx"};
+	struct {
+		const char *name;
+	} exts[] = {
+		{".pack"},
+		{".idx"},
+	};
 	struct child_process cmd;
 	struct string_list_item *item;
 	struct argv_array cmd_args = ARGV_ARRAY_INIT;
@@ -261,14 +266,14 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 		for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
 			char *fname, *fname_old;
 			fname = mkpathdup("%s/%s%s", packdir,
-						item->string, exts[ext]);
+						item->string, exts[ext].name);
 			if (!file_exists(fname)) {
 				free(fname);
 				continue;
 			}
 
 			fname_old = mkpath("%s/old-%s%s", packdir,
-						item->string, exts[ext]);
+						item->string, exts[ext].name);
 			if (file_exists(fname_old))
 				if (unlink(fname_old))
 					failed = 1;
@@ -319,9 +324,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 			char *fname, *fname_old;
 			struct stat statbuffer;
 			fname = mkpathdup("%s/pack-%s%s",
-					packdir, item->string, exts[ext]);
+					packdir, item->string, exts[ext].name);
 			fname_old = mkpathdup("%s-%s%s",
-					packtmp, item->string, exts[ext]);
+					packtmp, item->string, exts[ext].name);
 			if (!stat(fname_old, &statbuffer)) {
 				statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
 				chmod(fname_old, statbuffer.st_mode);
@@ -340,7 +345,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 			fname = mkpath("%s/old-pack-%s%s",
 					packdir,
 					item->string,
-					exts[ext]);
+					exts[ext].name);
 			if (remove_path(fname))
 				warning(_("removing '%s' failed"), fname);
 		}
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#54 lore raw

PATCH v4 17/23 repack: handle optional files created by pack-objects

In reply to Jeff King

We ask pack-objects to pack to a set of temporary files, and then rename them into place. Some files that pack-objects creates may be optional (like a .bitmap file), in which case we would not want to call rename(). We already call stat() and make the chmod optional if the file cannot be accessed. We could simply skip the rename step in this case, but that would be a minor regression in noticing problems with non-optional files (like the .pack and .idx files).

Instead, we can now annotate extensions as optional, and skip them if they don't exist (and otherwise rely on rename() to barf).

---
 builtin/repack.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
builtin/repack.c +7 -2
index a176de2..8b7dfd0 100644
@@ -117,6 +117,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 {
 	struct {
 		const char *name;
+		unsigned optional:1;
 	} exts[] = {
 		{".pack"},
 		{".idx"},
@@ -323,6 +324,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 		for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
 			char *fname, *fname_old;
 			struct stat statbuffer;
+			int exists = 0;
 			fname = mkpathdup("%s/pack-%s%s",
 					packdir, item->string, exts[ext].name);
 			fname_old = mkpathdup("%s-%s%s",
@@ -330,9 +332,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 			if (!stat(fname_old, &statbuffer)) {
 				statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
 				chmod(fname_old, statbuffer.st_mode);
+				exists = 1;
+			}
+			if (exists || !exts[ext].optional) {
+				if (rename(fname_old, fname))
+					die_errno(_("renaming '%s' failed"), fname_old);
 			}
-			if (rename(fname_old, fname))
-				die_errno(_("renaming '%s' failed"), fname_old);
 			free(fname);
 			free(fname_old);
 		}
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#55 lore raw

PATCH v4 18/23 repack: consider bitmaps when performing repacks

In reply to Jeff King

From: Vicent Marti <[email protected]>

Since 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.writebitmaps set to true in its config file will generate bitmap indexes as part of the garbage collection process.

Alternatively, git repack can be called with the -b switch to explicitly generate bitmap indexes if you are experimenting and don't want them on all the time.

---
 Documentation/git-repack.txt | 9 ++++++++-
 builtin/repack.c             | 9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
Documentation/git-repack.txt +8 -1
index 4c1aff6..dad186c 100644
@@ -9,7 +9,7 @@ git-repack - Pack unpacked objects in a repository
 SYNOPSIS
 --------
 [verse]
-'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [--window=<n>] [--depth=<n>]
+'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [--window=<n>] [--depth=<n>]
 
 DESCRIPTION
 -----------
@@ -110,6 +110,13 @@ other objects in that pack they already have locally.
 	The default is unlimited, unless the config variable
 	`pack.packSizeLimit` is set.
 
+-b::
+--write-bitmap-index::
+	Write a reachability bitmap index as part of the repack. This
+	only makes sense when used with `-a` or `-A`, as the bitmaps
+	must be able to refer to all reachable objects. This option
+	overrides the setting of `pack.writebitmaps`.
+
 
 Configuration
 -------------
builtin/repack.c +8 -1
index 8b7dfd0..239f278 100644
@@ -94,7 +94,7 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list)
 
 static void remove_redundant_pack(const char *dir_name, const char *base_name)
 {
-	const char *exts[] = {".pack", ".idx", ".keep"};
+	const char *exts[] = {".pack", ".idx", ".keep", ".bitmap"};
 	int i;
 	struct strbuf buf = STRBUF_INIT;
 	size_t plen;
@@ -121,6 +121,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	} exts[] = {
 		{".pack"},
 		{".idx"},
+		{".bitmap", 1},
 	};
 	struct child_process cmd;
 	struct string_list_item *item;
@@ -143,6 +144,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	int no_update_server_info = 0;
 	int quiet = 0;
 	int local = 0;
+	int write_bitmap = -1;
 
 	struct option builtin_repack_options[] = {
 		OPT_BIT('a', NULL, &pack_everything,
@@ -161,6 +163,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 		OPT__QUIET(&quiet, N_("be quiet")),
 		OPT_BOOL('l', "local", &local,
 				N_("pass --local to git-pack-objects")),
+		OPT_BOOL('b', "write-bitmap-index", &write_bitmap,
+				N_("write bitmap index")),
 		OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
 				N_("with -A, do not loosen objects older than this")),
 		OPT_INTEGER(0, "window", &window,
@@ -202,6 +206,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 		argv_array_pushf(&cmd_args, "--no-reuse-delta");
 	if (no_reuse_object)
 		argv_array_pushf(&cmd_args, "--no-reuse-object");
+	if (write_bitmap >= 0)
+		argv_array_pushf(&cmd_args, "--%swrite-bitmap-index",
+				 write_bitmap ? "" : "no-");
 
 	if (pack_everything & ALL_INTO_ONE) {
 		get_non_kept_pack_filenames(&existing_packs);
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#56 lore raw

PATCH v4 19/23 count-objects: recognize .bitmap in garbage-checking

In reply to Jeff King

From: Nguyễn Thái Ngọc Duy <[email protected]>

Count-objects will report any "garbage" files in the packs directory, including files whose extensions it does not know (case 1), and files whose matching ".pack" file is missing (case 2). Without having learned about ".bitmap" files, the current code reports all such files as garbage (case 1), even if their pack exists. Instead, they should be treated as case 2.

---
 sha1_file.c | 1 +
 1 file changed, 1 insertion(+)
sha1_file.c +1 -0
index 4714bd8..1294962 100644
@@ -1194,6 +1194,7 @@ static void prepare_packed_git_one(char *objdir, int local)
 
 		if (has_extension(de->d_name, ".idx") ||
 		    has_extension(de->d_name, ".pack") ||
+		    has_extension(de->d_name, ".bitmap") ||
 		    has_extension(de->d_name, ".keep"))
 			string_list_append(&garbage, path);
 		else
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#57 lore raw

PATCH v4 20/23 t: add basic bitmap functionality tests

In reply to Jeff King

Now that we can read and write bitmaps, we can exercise them with some basic functionality tests. These tests aren't particularly useful for seeing the benefit, as the test repo is too small for it to make a difference. However, we can at least check that using bitmaps does not break anything.

---
 t/t5310-pack-bitmaps.sh | 138 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 138 insertions(+)
 create mode 100755 t/t5310-pack-bitmaps.sh
t/t5310-pack-bitmaps.sh new file +138 -0
new file mode 100755
index 0000000..d2b0c45
@@ -0,0 +1,138 @@
+#!/bin/sh
+
+test_description='exercise basic bitmap functionality'
+. ./test-lib.sh
+
+test_expect_success 'setup repo with moderate-sized history' '
+	for i in $(test_seq 1 10); do
+		test_commit $i
+	done &&
+	git checkout -b other HEAD~5 &&
+	for i in $(test_seq 1 10); do
+		test_commit side-$i
+	done &&
+	git checkout master &&
+	blob=$(echo tagged-blob | git hash-object -w --stdin) &&
+	git tag tagged-blob $blob &&
+	git config pack.writebitmaps true
+'
+
+test_expect_success 'full repack creates bitmaps' '
+	git repack -ad &&
+	ls .git/objects/pack/ | grep bitmap >output &&
+	test_line_count = 1 output
+'
+
+test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
+	git rev-list --test-bitmap HEAD
+'
+
+rev_list_tests() {
+	state=$1
+
+	test_expect_success "counting commits via bitmap ($state)" '
+		git rev-list --count HEAD >expect &&
+		git rev-list --use-bitmap-index --count HEAD >actual &&
+		test_cmp expect actual
+	'
+
+	test_expect_success "counting partial commits via bitmap ($state)" '
+		git rev-list --count HEAD~5..HEAD >expect &&
+		git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
+		test_cmp expect actual
+	'
+
+	test_expect_success "counting non-linear history ($state)" '
+		git rev-list --count other...master >expect &&
+		git rev-list --use-bitmap-index --count other...master >actual &&
+		test_cmp expect actual
+	'
+
+	test_expect_success "enumerate --objects ($state)" '
+		git rev-list --objects --use-bitmap-index HEAD >tmp &&
+		cut -d" " -f1 <tmp >tmp2 &&
+		sort <tmp2 >actual &&
+		git rev-list --objects HEAD >tmp &&
+		cut -d" " -f1 <tmp >tmp2 &&
+		sort <tmp2 >expect &&
+		test_cmp expect actual
+	'
+
+	test_expect_success "bitmap --objects handles non-commit objects ($state)" '
+		git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
+		grep $blob actual
+	'
+}
+
+rev_list_tests 'full bitmap'
+
+test_expect_success 'clone from bitmapped repository' '
+	git clone --no-local --bare . clone.git &&
+	git rev-parse HEAD >expect &&
+	git --git-dir=clone.git rev-parse HEAD >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'setup further non-bitmapped commits' '
+	for i in $(test_seq 1 10); do
+		test_commit further-$i
+	done
+'
+
+rev_list_tests 'partial bitmap'
+
+test_expect_success 'fetch (partial bitmap)' '
+	git --git-dir=clone.git fetch origin master:master &&
+	git rev-parse HEAD >expect &&
+	git --git-dir=clone.git rev-parse HEAD >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'incremental repack cannot create bitmaps' '
+	test_commit more-1 &&
+	test_must_fail git repack -d
+'
+
+test_expect_success 'incremental repack can disable bitmaps' '
+	test_commit more-2 &&
+	git repack -d --no-write-bitmap-index
+'
+
+test_expect_success 'full repack, reusing previous bitmaps' '
+	git repack -ad &&
+	ls .git/objects/pack/ | grep bitmap >output &&
+	test_line_count = 1 output
+'
+
+test_expect_success 'fetch (full bitmap)' '
+	git --git-dir=clone.git fetch origin master:master &&
+	git rev-parse HEAD >expect &&
+	git --git-dir=clone.git rev-parse HEAD >actual &&
+	test_cmp expect actual
+'
+
+test_lazy_prereq JGIT '
+	type jgit
+'
+
+test_expect_success JGIT 'we can read jgit bitmaps' '
+	git clone . compat-jgit &&
+	(
+		cd compat-jgit &&
+		rm -f .git/objects/pack/*.bitmap &&
+		jgit gc &&
+		git rev-list --test-bitmap HEAD
+	)
+'
+
+test_expect_success JGIT 'jgit can read our bitmaps' '
+	git clone . compat-us &&
+	(
+		cd compat-us &&
+		git repack -adb &&
+		# jgit gc will barf if it does not like our bitmaps
+		jgit gc
+	)
+'
+
+test_done
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#58 lore raw

PATCH v4 21/23 t/perf: add tests for pack bitmaps

In reply to Jeff King

This adds a few basic perf tests for the pack bitmap code to show off its improvements. The tests are:

1. How long does it take to do a repack (it gets slower with bitmaps, since we have to do extra work)?

2. How long does it take to do a clone (it gets faster with bitmaps)?

3. How does a small fetch perform when we've just repacked?

4. How does a clone perform when we haven't repacked since a week of pushes?

Here are results against linux.git:

Test origin/master this tree
-----------------------------------------------------------------------

5310.2: repack to disk    33.64(32.64+2.04)   67.67(66.75+1.84) +101.2%
5310.3: simulated clone   30.49(29.47+2.05)   1.20(1.10+0.10) -96.1%
5310.4: simulated fetch   3.49(6.79+0.06)     5.57(22.35+0.07) +59.6%
5310.6: partial bitmap    36.70(43.87+1.81)   8.18(21.92+0.73) -77.7%

You can see that we do take longer to repack, but we do way better for further clones. A small fetch performs a bit worse, as we spend way more time on delta compression (note the heavy user CPU time, as we have 8 threads) due to the lack of name hashes for the bitmapped objects.

The final test shows how the bitmaps degrade over time between packs. There's still a significant speedup over the non-bitmap case, but we don't do quite as well (we have to spend time accessing the "new" objects the old fashioned way, including delta compression).

---
 t/perf/p5310-pack-bitmaps.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100755 t/perf/p5310-pack-bitmaps.sh
t/perf/p5310-pack-bitmaps.sh new file +56 -0
new file mode 100755
index 0000000..8c6ae45
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+test_description='Tests pack performance using bitmaps'
+. ./perf-lib.sh
+
+test_perf_large_repo
+
+# note that we do everything through config,
+# since we want to be able to compare bitmap-aware
+# git versus non-bitmap git
+test_expect_success 'setup bitmap config' '
+	git config pack.writebitmaps true
+'
+
+test_perf 'repack to disk' '
+	git repack -ad
+'
+
+test_perf 'simulated clone' '
+	git pack-objects --stdout --all </dev/null >/dev/null
+'
+
+test_perf 'simulated fetch' '
+	have=$(git rev-list HEAD~100 -1) &&
+	{
+		echo HEAD &&
+		echo ^$have
+	} | git pack-objects --revs --stdout >/dev/null
+'
+
+test_expect_success 'create partial bitmap state' '
+	# pick a commit to represent the repo tip in the past
+	cutoff=$(git rev-list HEAD~100 -1) &&
+	orig_tip=$(git rev-parse HEAD) &&
+
+	# now kill off all of the refs and pretend we had
+	# just the one tip
+	rm -rf .git/logs .git/refs/* .git/packed-refs
+	git update-ref HEAD $cutoff
+
+	# and then repack, which will leave us with a nice
+	# big bitmap pack of the "old" history, and all of
+	# the new history will be loose, as if it had been pushed
+	# up incrementally and exploded via unpack-objects
+	git repack -Ad
+
+	# and now restore our original tip, as if the pushes
+	# had happened
+	git update-ref HEAD $orig_tip
+'
+
+test_perf 'partial bitmap' '
+	git pack-objects --stdout --all </dev/null >/dev/null
+'
+
+test_done
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#59 lore raw

PATCH v4 22/23 pack-bitmap: implement optional name_hash cache

In reply to Jeff King

From: Vicent Marti <[email protected]>

When we use pack bitmaps rather than walking the object graph, we end up with the list of objects to include in the packfile, but we do not know the path at which any tree or blob objects would be found.

In a recently packed repository, this is fine. A fetch would use the paths only as a heuristic in the delta compression phase, and a fully packed repository should not need to do much delta compression.

As time passes, though, we may acquire more objects on top of our large bitmapped pack. If clients fetch frequently, then they never even look at the bitmapped history, and all works as usual. However, a client who has not fetched since the last bitmap repack will have "have" tips in the bitmapped history, but "want" newer objects.

The bitmaps themselves degrade gracefully in this circumstance. We manually walk the more recent bits of history, and then use bitmaps when we hit them.

But we would also like to perform delta compression between the newer objects and the bitmapped objects (both to delta against what we know the user already has, but also between "new" and "old" objects that the user is fetching). The lack of pathnames makes our delta heuristics much less effective.

This patch adds an optional cache of the 32-bit name_hash values to the end of the bitmap file. If present, a reader can use it to match bitmapped and non-bitmapped names during delta compression.

Here are perf results for p5310:

Test origin/master HEAD^ HEAD
-------------------------------------------------------------------------------------------------

5310.2: repack to disk    36.81(37.82+1.43)   47.70(48.74+1.41) +29.6%   47.75(48.70+1.51) +29.7%
5310.3: simulated clone   30.78(29.70+2.14)   1.08(0.97+0.10) -96.5%     1.07(0.94+0.12) -96.5%
5310.4: simulated fetch   3.16(6.10+0.08)     3.54(10.65+0.06) +12.0%    1.70(3.07+0.06) -46.2%
5310.6: partial bitmap    36.76(43.19+1.81)   6.71(11.25+0.76) -81.7%    4.08(6.26+0.46) -88.9%

You can see that the time spent on an incremental fetch goes down, as our delta heuristics are able to do their work. And we save time on the partial bitmap clone for the same reason.

---
 Documentation/config.txt                  | 11 +++++++++++
 Documentation/technical/bitmap-format.txt | 33 +++++++++++++++++++++++++++++++
 builtin/pack-objects.c                    | 10 +++++++++-
 pack-bitmap-write.c                       | 21 ++++++++++++++++++--
 pack-bitmap.c                             | 11 +++++++++++
 pack-bitmap.h                             |  6 ++++--
 t/perf/p5310-pack-bitmaps.sh              |  3 ++-
 t/t5310-pack-bitmaps.sh                   |  3 ++-
 8 files changed, 91 insertions(+), 7 deletions(-)
Documentation/config.txt +11 -0
index 4b0c368..499a3c4 100644
@@ -1872,6 +1872,17 @@ pack.writebitmaps::
 	space and extra time spent on the initial repack.  Defaults to
 	false.
 
+pack.writeBitmapHashCache::
+	When true, git will include a "hash cache" section in the bitmap
+	index (if one is written). This cache can be used to feed git's
+	delta heuristics, potentially leading to better deltas between
+	bitmapped and non-bitmapped objects (e.g., when serving a fetch
+	between an older, bitmapped pack and objects that have been
+	pushed since the last gc). The downside is that it consumes 4
+	bytes per object of disk space, and that JGit's bitmap
+	implementation does not understand it, causing it to complain if
+	Git and JGit are used on the same repository. Defaults to false.
+
 pager.<cmd>::
 	If the value is boolean, turns on or off pagination of the
 	output of a particular Git subcommand when writing to a tty.
Documentation/technical/bitmap-format.txt +33 -0
index 7a86bd7..f8c18a0 100644
@@ -21,6 +21,12 @@ GIT bitmap v1 format
 			requirement for the bitmap index format, also present in JGit,
 			that greatly reduces the complexity of the implementation.
 
+			- BITMAP_OPT_HASH_CACHE (0x4)
+			If present, the end of the bitmap file contains
+			`N` 32-bit name-hash values, one per object in the
+			pack. The format and meaning of the name-hash is
+			described below.
+
 		4-byte entry count (network byte order)
 
 			The total count of entries (bitmapped commits) in this bitmap index.
@@ -129,3 +135,30 @@ The bitstream represented by the above chunk is then:
 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
 pointer to the last RLW in the stream.
+
+
+== Appendix B: Optional Bitmap Sections
+
+These sections may or may not be present in the `.bitmap` file; their
+presence is indicated by the header flags section described above.
+
+Name-hash cache
+---------------
+
+If the BITMAP_OPT_HASH_CACHE flag is set, the end of the bitmap contains
+a cache of 32-bit values, one per object in the pack. The value at
+position `i` is the hash of the pathname at which the `i`th object
+(counting in index order) in the pack can be found.  This can be fed
+into the delta heuristics to compare objects with similar pathnames.
+
+The hash algorithm used is:
+
+    hash = 0;
+    while ((c = *name++))
+	    if (!isspace(c))
+		    hash = (hash >> 2) + (c << 24);
+
+Note that this hashing scheme is tied to the BITMAP_OPT_HASH_CACHE flag.
+If implementations want to choose a different hashing scheme, they are
+free to do so, but MUST allocate a new header flag (because comparing
+hashes made under two different schemes would be pointless).
builtin/pack-objects.c +9 -1
index fd6ae01..fd74197 100644
@@ -64,6 +64,7 @@ static off_t reuse_packfile_offset;
 
 static int use_bitmap_index = 1;
 static int write_bitmap_index;
+static uint16_t write_bitmap_options;
 
 static unsigned long delta_cache_size = 0;
 static unsigned long max_delta_cache_size = 256 * 1024 * 1024;
@@ -851,7 +852,8 @@ static void write_pack_file(void)
 				bitmap_writer_reuse_bitmaps(&to_pack);
 				bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
 				bitmap_writer_build(&to_pack);
-				bitmap_writer_finish(written_list, nr_written, tmpname);
+				bitmap_writer_finish(written_list, nr_written,
+						     tmpname, write_bitmap_options);
 				write_bitmap_index = 0;
 			}
 
@@ -2201,6 +2203,12 @@ static int git_pack_config(const char *k, const char *v, void *cb)
 		write_bitmap_index = git_config_bool(k, v);
 		return 0;
 	}
+	if (!strcmp(k, "pack.writebitmaphashcache")) {
+		if (git_config_bool(k, v))
+			write_bitmap_options |= BITMAP_OPT_HASH_CACHE;
+		else
+			write_bitmap_options &= ~BITMAP_OPT_HASH_CACHE;
+	}
 	if (!strcmp(k, "pack.usebitmaps")) {
 		use_bitmap_index = git_config_bool(k, v);
 		return 0;
pack-bitmap-write.c +19 -2
index 954a74d..1218bef 100644
@@ -490,6 +490,19 @@ static void write_selected_commits_v1(struct sha1file *f,
 	}
 }
 
+static void write_hash_cache(struct sha1file *f,
+			     struct pack_idx_entry **index,
+			     uint32_t index_nr)
+{
+	uint32_t i;
+
+	for (i = 0; i < index_nr; ++i) {
+		struct object_entry *entry = (struct object_entry *)index[i];
+		uint32_t hash_value = htonl(entry->hash);
+		sha1write(f, &hash_value, sizeof(hash_value));
+	}
+}
+
 void bitmap_writer_set_checksum(unsigned char *sha1)
 {
 	hashcpy(writer.pack_checksum, sha1);
@@ -497,7 +510,8 @@ void bitmap_writer_set_checksum(unsigned char *sha1)
 
 void bitmap_writer_finish(struct pack_idx_entry **index,
 			  uint32_t index_nr,
-			  const char *filename)
+			  const char *filename,
+			  uint16_t options)
 {
 	static char tmp_file[PATH_MAX];
 	static uint16_t default_version = 1;
@@ -514,7 +528,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
 
 	memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));
 	header.version = htons(default_version);
-	header.options = htons(flags);
+	header.options = htons(flags | options);
 	header.entry_count = htonl(writer.selected_nr);
 	memcpy(header.checksum, writer.pack_checksum, 20);
 
@@ -525,6 +539,9 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
 	dump_bitmap(f, writer.tags);
 	write_selected_commits_v1(f, index, index_nr);
 
+	if (options & BITMAP_OPT_HASH_CACHE)
+		write_hash_cache(f, index, index_nr);
+
 	sha1close(f, NULL, CSUM_FSYNC);
 
 	if (adjust_shared_perm(tmp_file))
pack-bitmap.c +11 -0
index 82090a6..ae0b57b 100644
@@ -66,6 +66,9 @@ static struct bitmap_index {
 	/* Number of bitmapped commits */
 	uint32_t entry_count;
 
+	/* Name-hash cache (or NULL if not present). */
+	uint32_t *hashes;
+
 	/*
 	 * Extended index.
 	 *
@@ -152,6 +155,11 @@ static int load_bitmap_header(struct bitmap_index *index)
 		if ((flags & BITMAP_OPT_FULL_DAG) == 0)
 			return error("Unsupported options for bitmap index file "
 				"(Git requires BITMAP_OPT_FULL_DAG)");
+
+		if (flags & BITMAP_OPT_HASH_CACHE) {
+			unsigned char *end = index->map + index->map_size - 20;
+			index->hashes = ((uint32_t *)end) - index->pack->num_objects;
+		}
 	}
 
 	index->entry_count = ntohl(header->entry_count);
@@ -626,6 +634,9 @@ static void show_objects_for_type(
 			entry = &bitmap_git.reverse_index->revindex[pos + offset];
 			sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr);
 
+			if (bitmap_git.hashes)
+				hash = ntohl(bitmap_git.hashes[entry->nr]);
+
 			show_reach(sha1, object_type, 0, hash, bitmap_git.pack, entry->offset);
 		}
 
pack-bitmap.h +4 -2
index 09acf02..8b7f4e9 100644
@@ -24,7 +24,8 @@ static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
 #define NEEDS_BITMAP (1u<<22)
 
 enum pack_bitmap_opts {
-	BITMAP_OPT_FULL_DAG = 1
+	BITMAP_OPT_FULL_DAG = 1,
+	BITMAP_OPT_HASH_CACHE = 4,
 };
 
 enum pack_bitmap_flags {
@@ -57,6 +58,7 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
 void bitmap_writer_build(struct packing_data *to_pack);
 void bitmap_writer_finish(struct pack_idx_entry **index,
 			  uint32_t index_nr,
-			  const char *filename);
+			  const char *filename,
+			  uint16_t options);
 
 #endif
t/perf/p5310-pack-bitmaps.sh +2 -1
index 8c6ae45..685d46f 100755
@@ -9,7 +9,8 @@ test_perf_large_repo
 # since we want to be able to compare bitmap-aware
 # git versus non-bitmap git
 test_expect_success 'setup bitmap config' '
-	git config pack.writebitmaps true
+	git config pack.writebitmaps true &&
+	git config pack.writebitmaphashcache true
 '
 
 test_perf 'repack to disk' '
t/t5310-pack-bitmaps.sh +2 -1
index d2b0c45..d3a3afa 100755
@@ -14,7 +14,8 @@ test_expect_success 'setup repo with moderate-sized history' '
 	git checkout master &&
 	blob=$(echo tagged-blob | git hash-object -w --stdin) &&
 	git tag tagged-blob $blob &&
-	git config pack.writebitmaps true
+	git config pack.writebitmaps true &&
+	git config pack.writebitmaphashcache true
 '
 
 test_expect_success 'full repack creates bitmaps' '
Signature · 1 line
1.8.5.1.399.g900e7cd
author
#60 lore raw

PATCH v4 23/23 compat/mingw.h: Fix the MinGW and msvc builds

In reply to Jeff King

From: Ramsay Jones <[email protected]>

---
 compat/mingw.h | 1 +
 1 file changed, 1 insertion(+)
compat/mingw.h +1 -0
index 92cd728..8828ede 100644
@@ -345,6 +345,7 @@ static inline char *mingw_find_last_dir_sep(const char *path)
 #define PATH_SEP ';'
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
+#define PRIx64 "I64x"
 
 void mingw_open_html(const char *path);
 #define open_html mingw_open_html
Signature · 1 line
1.8.5.1.399.g900e7cd
#61 lore raw

Re: [PATCH v4 23/23] compat/mingw.h: Fix the MinGW and msvc builds

Quoted 14 lines · Jeff King

From: Ramsay Jones <[email protected]>

---
 compat/mingw.h | 1 +
 1 file changed, 1 insertion(+)
compat/mingw.h +0 -0
index 92cd728..8828ede 100644

compat/mingw.h static inline char *mingw_find_last_dir_sep(const char *path) · line 349

Quoted 5 lines
compat/mingw.h +1 -0
@@ -345,6 +345,7 @@ static inline char *mingw_find_last_dir_sep(const char *path)
 #define PATH_SEP ';'
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
+#define PRIx64 "I64x"
 

Please, move this before patch #8, and adjust the commit message.

author
#62 lore raw

Re: [PATCH v4 23/23] compat/mingw.h: Fix the MinGW and msvc builds

Quoted 10 lines · Erik Faye-Lund
Quoted 9 lines · Jeff King

From: Ramsay Jones <[email protected]>

---
 compat/mingw.h | 1 +
 1 file changed, 1 insertion(+)
Quoted 12 lines

compat/mingw.h static inline char *mingw_find_last_dir_sep(const char *path) · line 349

Quoted 10 lines
compat/mingw.h +1 -0
index 92cd728..8828ede 100644
@@ -345,6 +345,7 @@ static inline char *mingw_find_last_dir_sep(const char *path)
 #define PATH_SEP ';'
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
+#define PRIx64 "I64x"
 

Please, move this before patch #8, and adjust the commit message.

Yeah, that makes sense. Though I think we can do one better and simply remove the need for it entirely. The only use of PRIx64 is in a debugging function that does not get called.

How about squashing the patch below into patch 8 ("ewah: compressed bitmap implementation"):

ewah/ewah_bitmap.c +0 -12
index f104b87..9ced2da 100644
@@ -381,18 +381,6 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent)
 		read_new_rlw(it);
 }
 
-void ewah_dump(struct ewah_bitmap *self)
-{
-	size_t i;
-	fprintf(stderr, "%"PRIuMAX" bits | %"PRIuMAX" words | ",
-		(uintmax_t)self->bit_size, (uintmax_t)self->buffer_size);
-
-	for (i = 0; i < self->buffer_size; ++i)
-		fprintf(stderr, "%016"PRIx64" ", (uint64_t)self->buffer[i]);
-
-	fprintf(stderr, "\n");
-}
-
 void ewah_not(struct ewah_bitmap *self)
 {
 	size_t pointer = 0;
ewah/ewok.h +0 -2
index 619afaa..43adeb5 100644
@@ -193,8 +193,6 @@ void ewah_and(
 	struct ewah_bitmap *ewah_j,
 	struct ewah_bitmap *out);
 
-void ewah_dump(struct ewah_bitmap *self);
-
 /**
  * Direct word access
  */
#63 lore raw

Re: [PATCH v4 23/23] compat/mingw.h: Fix the MinGW and msvc builds

Quoted 60 lines · Jeff King
Quoted 10 lines · Erik Faye-Lund
Quoted 9 lines · Jeff King

From: Ramsay Jones <[email protected]>

---
 compat/mingw.h | 1 +
 1 file changed, 1 insertion(+)
Quoted 12 lines

compat/mingw.h static inline char *mingw_find_last_dir_sep(const char *path) · line 349

Quoted 10 lines
compat/mingw.h +1 -0
index 92cd728..8828ede 100644
@@ -345,6 +345,7 @@ static inline char *mingw_find_last_dir_sep(const char *path)
 #define PATH_SEP ';'
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
+#define PRIx64 "I64x"
 

Please, move this before patch #8, and adjust the commit message.

Yeah, that makes sense. Though I think we can do one better and simply remove the need for it entirely. The only use of PRIx64 is in a debugging function that does not get called.

How about squashing the patch below into patch 8 ("ewah: compressed bitmap implementation"):

ewah/ewah_bitmap.c +0 -12
index f104b87..9ced2da 100644
@@ -381,18 +381,6 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent)
 		read_new_rlw(it);
 }
 
-void ewah_dump(struct ewah_bitmap *self)
-{
-	size_t i;
-	fprintf(stderr, "%"PRIuMAX" bits | %"PRIuMAX" words | ",
-		(uintmax_t)self->bit_size, (uintmax_t)self->buffer_size);
-
-	for (i = 0; i < self->buffer_size; ++i)
-		fprintf(stderr, "%016"PRIx64" ", (uint64_t)self->buffer[i]);
-
-	fprintf(stderr, "\n");
-}
-
 void ewah_not(struct ewah_bitmap *self)
 {
 	size_t pointer = 0;
ewah/ewok.h +0 -0
index 619afaa..43adeb5 100644

ewah/ewok.h void ewah_and( · line 198

Quoted 8 lines
ewah/ewok.h +0 -2
@@ -193,8 +193,6 @@ void ewah_and(
 	struct ewah_bitmap *ewah_j,
 	struct ewah_bitmap *out);
 
-void ewah_dump(struct ewah_bitmap *self);
-
 /**
  * Direct word access
  */

I'm always in favour of removing unused (or unwanted) code! :-D

ATB,
Ramsay Jones

#64 lore raw

Re: [PATCH v4 23/23] compat/mingw.h: Fix the MinGW and msvc builds

In reply to Jeff King

Sounds good. We don't really need the dump anyway.

Quoted 72 lines · Jeff King
Quoted 10 lines · Erik Faye-Lund
Quoted 9 lines · Jeff King

From: Ramsay Jones <[email protected]>

---
 compat/mingw.h | 1 +
 1 file changed, 1 insertion(+)
Quoted 12 lines

compat/mingw.h static inline char *mingw_find_last_dir_sep(const char *path) · line 349

Quoted 10 lines
compat/mingw.h +1 -0
index 92cd728..8828ede 100644
@@ -345,6 +345,7 @@ static inline char *mingw_find_last_dir_sep(const char *path)
 #define PATH_SEP ';'
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
+#define PRIx64 "I64x"
 

Please, move this before patch #8, and adjust the commit message.

Yeah, that makes sense. Though I think we can do one better and simply remove the need for it entirely. The only use of PRIx64 is in a debugging function that does not get called.

How about squashing the patch below into patch 8 ("ewah: compressed bitmap implementation"):

ewah/ewah_bitmap.c +0 -12
index f104b87..9ced2da 100644
@@ -381,18 +381,6 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent)
                read_new_rlw(it);
 }
 
-void ewah_dump(struct ewah_bitmap *self)
-{
-       size_t i;
-       fprintf(stderr, "%"PRIuMAX" bits | %"PRIuMAX" words | ",
-               (uintmax_t)self->bit_size, (uintmax_t)self->buffer_size);
-
-       for (i = 0; i < self->buffer_size; ++i)
-               fprintf(stderr, "%016"PRIx64" ", (uint64_t)self->buffer[i]);
-
-       fprintf(stderr, "\n");
-}
-
 void ewah_not(struct ewah_bitmap *self)
 {
        size_t pointer = 0;
ewah/ewok.h +0 -3
index 619afaa..43adeb5 100644
@@ -193,8 +193,6 @@ void ewah_and(
        struct ewah_bitmap *ewah_j,
        struct ewah_bitmap *out);
 
-void ewah_dump(struct ewah_bitmap *self);
-
 /**
  * Direct word access
  */
--

To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#65 lore raw
In reply to Jeff King
Quoted 11 lines · Jeff King

Interdiff is below.

[01/23]: sha1write: make buffer const-correct [02/23]: revindex: Export new APIs
[03/23]: pack-objects: Refactor the packing list [04/23]: pack-objects: factor out name_hash
[05/23]: revision: allow setting custom limiter function [06/23]: sha1_file: export git_open_noatime [07/23]: compat: add endianness helpers
[08/23]: ewah: compressed bitmap implementation [09/23]: documentation: add documentation for the bitmap format

By the way, the patches are identical up through 09/23. I think the first one is already merged into another topic, too, so it may be worth building on that instead of re-applying.

-Peff

author
#66 lore raw
In reply to Jeff King
Quoted 5 lines · Jeff King

The changes from v3 are:

- reworked add_object_entry refactoring (see patch 11, which is new, and patch 12 which builds on it in a more natural way)

Quoted 7 lines

- better error/die reporting from write_reused_pack

- added Ramsay's PRIx64 compat fix

- fixed a user-after-free in the warning message of open_pack_bitmap_1

- minor typo/thinko fixes from Thomas in docs and tests

One thing explicitly _not_ here is ripping out khash in favor of Karsten's hash system. That is still on the table, but I'd much rather do it on top if we are going to.

-Peff

#67 lore raw
In reply to Jeff King
Quoted 6 lines · Jeff King

Here's the v4 re-roll of the pack bitmap series.

The changes from v3 are:

- reworked add_object_entry refactoring (see patch 11, which is new, and patch 12 which builds on it in a more natural way)

This now looks like this (pasting because it is hard to see in the diffs):

static int add_object_entry(const unsigned char *sha1, enum object_type type,
const char *name, int exclude)

  {
          struct packed_git *found_pack;
          off_t found_offset;
          uint32_t index_pos;

          if (have_duplicate_entry(sha1, exclude, &index_pos))
                  return 0;

          if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset))
                  return 0;

          create_object_entry(sha1, type, pack_name_hash(name),
                              exclude, name && no_try_delta(name),
                              index_pos, found_pack, found_offset);

          display_progress(progress_state, to_pack.nr_objects);
          return 1;

}

static int add_object_entry_from_bitmap(const unsigned char *sha1,
enum object_type type, int flags, uint32_t name_hash, struct packed_git *pack, off_t offset)

  {
          uint32_t index_pos;

          if (have_duplicate_entry(sha1, 0, &index_pos))
                  return 0;

          create_object_entry(sha1, type, name_hash, 0, 0, index_pos, pack, offset);

          display_progress(progress_state, to_pack.nr_objects);
          return 1;

}

Much nicer. Thanks for going the extra mile!

Signature · 2 lines
Thomas Rast
[email protected]