Skip to contentSkip to conversation

rev-cache

RFC/PATCH INTRO Nick Edelen 1 participant 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi everyone,

I've been working on a revision caching system (with gsoc), and would be curious to get some feedback on it and it's (potential) installation into git. I believe the core mechanics of it are largely finished, but integration is still rather rough. I've tried to divide it into 4 self-contained patches -- each representing a working implemenation with incremental featuresets. The patchset is seperated as:
* basic - the simplest working revision cache implementation, with full docs and relavant tests
* objects - non-commit object caching + tests
* misc - extra (maintenance) features and refactor of object caching (requiring slight modification of some object structures)
* integration - (proof of concept) integration of rev-cache into rev-list, along with extensive tests

I'm afraid the first patch is rather big, as the topo-data encoding scheme is a smidgen complicated, but its effect on git's internals is very small -- it's less of a patch and more an addition of a few files. I know you guys prefer inline patches, but in view of the patchfile size I decided it'd be more prudent to include that seperately as an attachment. The only other caveat I can think of is that the tests currently require python, although that could change in future.

So yeah, I hope you find it interesting. Apologies if I'm breaking protocol...

- Nick

#1 lore raw

hi all,

understandably, someone dumping a load of source without much comment on you guys didn't exactly enthrall you. this project feels pretty finished, so I'm not in desperate need of feedback, but I figured you guys might like some high-level info on my part. I've modified the integration bit slightly, and performance is now reasonably satisfactory. here are some stats for the linux repo (~270MB) on my laptop:

( note that I've edited the last patch (integration) a bit, so I've attached the new patch. I've also, in a seperate patch, tweaked builtin-pack-objects to reduce a bottleneck in object checking/writing (also attached). )

git-rev-list --all --objects >/dev/null
default : ~55s
w/ rev-cache: ~8s

git-pack-objects --revs --all --stdout >/dev/null
default : 4m 48s (cold); 3m 41s (warm)
w/ rev-cache : ~58s
w/ rev-cache + tweak: ~36s

I tested these on cygwin on a dual-core laptop with 1gb ram, with a few apps running in the background. times could vary a bit, depending on what's been run how many times with what in the background, etc., but I tried to capture the general trend.

- Nick

Quoted 8 lines · Nick Edelen

Hi everyone,

I've been working on a revision caching system (with gsoc), and would be curious to get some feedback on it and it's (potential) installation into git.  I believe the core mechanics of it are largely finished, but integration is still rather rough.  I've tried to divide it into 4 self-contained patches -- each representing a working implemenation with incremental featuresets.  The patchset is seperated as:
 * basic - the simplest working revision cache implementation, with full docs and relavant tests
 * objects - non-commit object caching + tests
 * misc - extra (maintenance) features and refactor of object caching (requiring slight modification of some object structures)
 * integration - (proof of concept) integration of rev-cache into rev-list, along with extensive tests

Quoted 6 lines

I'm afraid the first patch is rather big, as the topo-data encoding scheme is a smidgen complicated, but its effect on git's internals is very small -- it's less of a patch and more an addition of a few files.  I know you guys prefer inline patches, but in view of the patchfile size I decided it'd be more prudent to include that seperately as an attachment.  The only other caveat I can think of is that the tests currently require python, although that could change in future.

So yeah, I hope you find it interesting.  Apologies if I'm breaking protocol...

 - Nick

From: Nick Edelen <[email protected]>
Subject: [PATCH] t/revcache/integration

This patch introduces a tentative step towards integrating rev-cache into the internal revision walker. Cache traversal is added to both limited and unlimited revision walks, and FACE_VALUEd objects are handled in list-objects. Furthermore the unique object_list field is added to commit objects, to allow runtime association with a commit's cached 'unique' object list.

The traversal mechanism in rev-cache is updated to reflect the limiting methods used in rev-list. Tests for coagulation and index generation are included, in addition to several verifying the correctness of integration.

---
 builtin-rev-cache.c       |   50 +++++++-
 commit.c                  |    2 +-
 commit.h                  |    1 +
 list-objects.c            |   49 ++++++-
 rev-cache.c               |  319 ++++++++++++++++++++++++++++++++++++++-------
 revision.c                |   87 ++++++++++---
 revision.h                |   35 +++---
 t/t6015-rev-cache-list.sh |  120 ++++++++++++++++--
 8 files changed, 563 insertions(+), 100 deletions(-)
builtin-rev-cache.c +45 -5
index 380818f..38a6c85 100755
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
+#include "list-objects.h"
 
 #define DEFAULT_IGNORE_SLICE_SIZE		5000000 /* in bytes */
 
@@ -69,6 +70,43 @@ static int handle_add(int argc, const char *argv[]) /* args beyond this command
 	return 0;
 }
 
+static void show_commit(struct commit *commit, void *data)
+{
+	printf("%s\n", sha1_to_hex(commit->object.sha1));
+}
+
+static void show_object(struct object *obj, const struct name_path *path, const char *last)
+{
+	printf("%s\n", sha1_to_hex(obj->sha1));
+}
+
+static int test_rev_list(int argc, const char *argv[])
+{
+	struct rev_info revs;
+	unsigned int flags = 0;
+	int i;
+	
+	init_revisions(&revs, 0);
+	
+	for (i = 0; i < argc; i++) {
+		if (!strcmp(argv[i], "--not"))
+			flags ^= UNINTERESTING;
+		else if (!strcmp(argv[i], "--objects"))
+			revs.tree_objects = revs.blob_objects = 1;
+		else
+			handle_revision_arg(argv[i], &revs, flags, 1);
+	}
+	
+	setup_revisions(0, 0, &revs, 0);
+	revs.topo_order = 1;
+	revs.lifo = 1;
+	prepare_revision_walk(&revs);
+	
+	traverse_commit_list(&revs, show_commit, show_object, 0);
+	
+	return 0;
+}
+
 static int handle_walk(int argc, const char *argv[])
 {
 	struct commit *commit;
@@ -113,21 +151,21 @@ static int handle_walk(int argc, const char *argv[])
 	queue = 0;
 	qp = &queue;
 	commit = pop_commit(&work);
-	retval = traverse_cache_slice(0, sha1p, &revs, commit, &date, &slop, &qp, &work);
+	retval = traverse_cache_slice(&revs, sha1p, commit, &date, &slop, &qp, &work);
 	if (retval < 0)
 		return retval;
 	
-	printf("queue:\n");
+	fprintf(stderr, "queue:\n");
 	while ((commit = pop_commit(&queue)) != 0) {
 		printf("%s\n", sha1_to_hex(commit->object.sha1));
 	}
 	
-	printf("work:\n");
+	fprintf(stderr, "work:\n");
 	while ((commit = pop_commit(&work)) != 0) {
 		printf("%s\n", sha1_to_hex(commit->object.sha1));
 	}
 	
-	printf("pending:\n");
+	fprintf(stderr, "pending:\n");
 	for (i = 0; i < revs.pending.nr; i++) {
 		struct object *obj = revs.pending.objects[i].item;
 		
@@ -181,7 +219,7 @@ static int handle_fuse(int argc, const char *argv[])
 
 static int handle_index(int argc, const char *argv[])
 {
-	return regenerate_cache_index();
+	return regenerate_cache_index(0);
 }
 
 static int handle_help(void)
@@ -235,6 +273,8 @@ int cmd_rev_cache(int argc, const char *argv[], const char *prefix)
 		r = handle_walk(argc, argv);
 	else if (!strcmp(arg, "index"))
 		r = handle_index(argc, argv);
+	else if (!strcmp(arg, "test"))
+		r = test_rev_list(argc, argv);
 	else
 		return handle_help();
 	
commit.c +1 -1
index d9778ba..92459bd 100644
@@ -256,7 +256,7 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
 			     sha1_to_hex(item->object.sha1));
 	item->tree = lookup_tree(parent);
 	bufptr += 46; /* "tree " + "hex sha1" + "\n" */
- 	pptr = &item->parents;
+	pptr = &item->parents;
 	while (pop_commit(pptr))
 		; /* clear anything from cache */
 
commit.h +1 -0
index 0529fcf..7c50a7f 100644
@@ -20,6 +20,7 @@ struct commit {
 	struct tree *tree;
 	char *buffer;
 	unsigned long size;
+	struct object_list *unique;
 };
 
 extern int save_commit_buffer;
list-objects.c +42 -7

93 lines not on this page · raw message

rev-cache.c +274 -45

564 lines not on this page · raw message

revision.c +71 -16

136 lines not on this page · raw message

revision.h +19 -16
index 5269602..f858006 100644
@@ -19,6 +19,20 @@
 struct rev_info;
 struct log_info;
 
+struct rev_cache_info {
+	/* generation flags */
+	unsigned objects : 1, 
+		legs : 1, 
+		make_index : 1;
+	
+	/* traversal flags */
+	unsigned save_unique : 1, 
+		add_to_pending : 1;
+	
+	/* fuse options */
+	unsigned int ignore_size;
+};
+
 struct rev_info {
 	/* Starting list */
 	struct commit_list *commits;
@@ -121,6 +135,9 @@ struct rev_info {
 	struct reflog_walk_info *reflog_info;
 	struct decoration children;
 	struct decoration merge_simplification;
+	
+	/* caching info, used ONLY by traverse_cache_slice */
+	struct rev_cache_info rev_cache_info;
 };
 
 #define REV_TREE_SAME		0
@@ -177,23 +194,9 @@ extern void insert_by_date_cached(struct commit *p, struct commit_list **head,
 
 /* rev-cache.c */
 
-struct rev_cache_info {
-	/* generation flags */
-	unsigned objects : 1, 
-		legs : 1, 
-		make_index : 1;
-	
-	/* traversal flags */
-	unsigned save_unique : 1, 
-		add_to_pending : 1;
-	
-	/* fuse options */
-	unsigned int ignore_size;
-};
-
 extern unsigned char *get_cache_slice(struct commit *commit);
-extern int traverse_cache_slice(struct rev_cache_info *rci, unsigned char *cache_sha1, 
-	struct rev_info *revs, struct commit *commit, 
+extern int traverse_cache_slice(struct rev_info *revs, 
+	unsigned char *cache_sha1, struct commit *commit, 
 	unsigned long *date_so_far, int *slop_so_far, 
 	struct commit_list ***queue, struct commit_list **work);
 
t/t6015-rev-cache-list.sh +110 -10

166 lines not on this page · raw message

Signature · 1 line
tg: (de9a466..) t/revcache/integration (depends on: t/revcache/misc)

From: Nick Edelen <[email protected]>
Subject: [PATCH] t/pack/tweak

builtin-pack-objects checks/writes packed objects by mapping a portion of the pack, then either verifying an object's integrity or copying the data. currently, using use_pack() it maps only a small portion (a 'window') at a time, and consequently calls mmap() many times. as most packs will contain many consecutive objects, mmap()ing larger portions fewer can noticeably speed up packing. this is an experimental patch to implement said idea.

---
 builtin-pack-objects.c |   27 ++++++++++++++++++++++++++-
 cache.h                |    1 +
 sha1_file.c            |    2 +-
 3 files changed, 28 insertions(+), 2 deletions(-)
builtin-pack-objects.c +26 -1
index 941cc2d..c68c6b8 100644
@@ -210,6 +210,28 @@ static int check_pack_inflate(struct packed_git *p,
 		stream.total_in == len) ? 0 : -1;
 }
 
+static void make_large_pack_map(struct packed_git *p, off_t ofs, struct pack_window **w_curs)
+{
+	struct pack_window *w;
+	
+	for (w = p->windows; w; w = w->next) {
+		if (in_window(w, ofs))
+			break;
+	}
+
+	/* admittedly this is a bit of a hack,  but we need to be able
+	 * to reuse the mapping per packfile */
+	if (!w) {
+		size_t temp_window_size = packed_git_window_size;
+		packed_git_window_size = 80000000; /* a more intelligent number might be better... */
+
+		use_pack(p, &w, ofs, 0);
+		packed_git_window_size = temp_window_size;
+	}
+	
+	*w_curs = w;
+}
+
 static void copy_pack_data(struct sha1file *f,
 		struct packed_git *p,
 		struct pack_window **w_curs,
@@ -422,6 +444,8 @@ static unsigned long write_object(struct sha1file *f,
 			}
 			sha1write(f, header, hdrlen);
 		}
+
+		make_large_pack_map(p, offset, &w_curs);
 		copy_pack_data(f, p, &w_curs, offset, datalen);
 		unuse_pack(&w_curs);
 		reused++;
@@ -1016,7 +1040,7 @@ static void check_object(struct object_entry *entry)
 {
 	if (entry->in_pack) {
 		struct packed_git *p = entry->in_pack;
-		struct pack_window *w_curs = NULL;
+		struct pack_window *w_curs;
 		const unsigned char *base_ref = NULL;
 		struct object_entry *base_entry;
 		unsigned long used, used_0;
@@ -1024,6 +1048,7 @@ static void check_object(struct object_entry *entry)
 		off_t ofs;
 		unsigned char *buf, c;
 
+		make_large_pack_map(p, entry->in_pack_offset, &w_curs);
 		buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail);
 
 		/*
cache.h +1 -0
index 871c984..bbdff9a 100644
@@ -846,6 +846,7 @@ extern void install_packed_git(struct packed_git *pack);
 extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
 					 struct packed_git *packs);
 
+extern int in_window(struct pack_window *, off_t);
 extern void pack_report(void);
 extern int open_pack_index(struct packed_git *);
 extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
sha1_file.c +1 -1
index 8f5fe62..2d105eb 100644
@@ -780,7 +780,7 @@ static int open_packed_git(struct packed_git *p)
 	return -1;
 }
 
-static int in_window(struct pack_window *win, off_t offset)
+int in_window(struct pack_window *win, off_t offset)
 {
 	/* We must promise at least 20 bytes (one hash) after the
 	 * offset is available from this window, otherwise the offset
Signature · 1 line
tg: (677cb21..) t/pack/tweak (depends on: t/revcache/integration)