Skip to contentSkip to conversation

administrative functions for rev-cache, and start of integration into git

PATCH In review Nick Edelen 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 4/6 administrative functions for rev-cache, and start of integration into git

This patch contains miscellaneous (maintenance) features:
- support for cache slice fusion, index regeneration and object size caching
- extra 'size' field added to commit, tag and blob objects, initialized in parse_* functions and cache traversal
- non-commit object generation refactored to take advantage of 'size' field
- porcelain updated to support feature additions

The beginnings of integration into git are present in this patch, mainly centered on caching object size; the object generation is refactored to more elegantly exploit this. Fusion allows smaller (incremental) slices to be coagulated into a larger slice, reducing overhead, while index regeneration enables repair or cleaning of the cache index.

Note that tests for these features are included in the following patch, as they take advantage of the rev-cache's integration into the revision walker.

---
4/5 previously. Small adjustment in parsing of --ignore-size field in porcelain.

 blob.c              |    1 +
 blob.h              |    1 +
 builtin-rev-cache.c |   73 +++++++++-
 commit.c            |    1 +
 commit.h            |    1 +
 rev-cache.c         |  417 +++++++++++++++++++++++++++++++++++++++++---------
 revision.h          |    4 +-
 7 files changed, 421 insertions(+), 77 deletions(-)
blob.c +1 -0
index bd7d078..e1bab3f 100644
@@ -21,6 +21,7 @@ struct blob *lookup_blob(const unsigned char *sha1)
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
 {
 	item->object.parsed = 1;
+	item->size = size;
 	return 0;
 }
 
blob.h +1 -0
index ea5d9e9..d8db96a 100644
@@ -7,6 +7,7 @@ extern const char *blob_type;
 
 struct blob {
 	struct object object;
+	unsigned long size;
 };
 
 struct blob *lookup_blob(const unsigned char *sha1);
builtin-rev-cache.c +72 -1

99 lines not on this page · raw message

commit.c +1 -0
index 65d223e..afe504f 100644
@@ -243,6 +243,7 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
 	if (item->object.parsed)
 		return 0;
 	item->object.parsed = 1;
+	item->size = size;
 	tail += size;
 	if (tail <= bufptr + 46 || memcmp(bufptr, "tree ", 5) || bufptr[45] != '\n')
 		return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
commit.h +1 -0
index ba9f638..0529fcf 100644
@@ -19,6 +19,7 @@ struct commit {
 	struct commit_list *parents;
 	struct tree *tree;
 	char *buffer;
+	unsigned long size;
 };
 
 extern int save_commit_buffer;
rev-cache.c +342 -75

596 lines not on this page · raw message

revision.h +3 -1
index 200042a..d97ac8c 100644
@@ -207,6 +207,8 @@ extern int make_cache_slice(struct rev_cache_info *rci,
 extern int make_cache_index(struct rev_cache_info *rci, unsigned char *cache_sha1, 
 	int fd, unsigned int size);
 
-extern void starts_from_slices(struct rev_info *revs, unsigned int flags);
+extern void starts_from_slices(struct rev_info *revs, unsigned int flags, unsigned char *which, int n);
+extern int coagulate_cache_slices(struct rev_cache_info *rci, struct rev_info *revs);
+extern int regenerate_cache_index(struct rev_cache_info *rci);
 
 #endif
Signature · 1 line
tg: (9861015..) t/revcache/misc (depends on: t/revcache/objects)
#1 lore raw

"Nick Edelen" <[email protected]> writes:

Note that I didn't read the entire patch, so the parts I did not comment on in this message may or may not have problematic parts.

Quoted 2 lines

- extra 'size' field added to commit, tag and blob objects, initialized in parse_* functions and cache traversal

It is unclear which "size" this field refers to without comment.

I do not know if this change is justifiable. We (mostly Linus) spent considerble effort to shrink the memory footprint of struct commit (and struct object in general) exactly because revision traversal needs to inspect tons of them.

Quoted 11 lines
builtin-rev-cache.c +11 -0
+static unsigned int parse_size(const char *name)
+{
+	unsigned int size;
+	char *p;
+	
+	size = strtol(name, &p, 10);
+	switch (*p) {
+	case 'k' : 
+	case 'K' : 
+		size *= 0x400;
+		break;

builtin-rev-cache.c static int handle_walk(int argc, const char *argv[]) · line 166

Quoted 10 lines
builtin-rev-cache.c +10 -0
+	case 'm' : 
+	case 'M' : 
+		size *= 0x100000;
+		break;
+	default : 
+		break;
+	}
+	
+	return size;
+}

Looks vaguely familiar.

The configuration parser already knows about these size suffixes when told to read "int". Can't that code, e.g. git_parse_ulong(), be reused here?

rev-cache.c unsigned char *get_cache_slice(struct commit *commit) · line 225

Quoted 7 lines
rev-cache.c +0 -1
@@ -219,7 +221,6 @@ unsigned char *get_cache_slice(struct commit *commit)
 		return 0;
 
 	ie = search_index(commit->object.sha1);
-	
 	if (ie && ie->cache_index < idx_head.cache_nr)
 		return idx_caches + ie->cache_index * 20;

"Oops, fix an earlier mistake"...

rev-cache.c static int setup_traversal(struct cache_slice_header *head, unsigned char *map, · line 265

Quoted 5 lines
rev-cache.c +0 -1
@@ -262,7 +282,6 @@ static int setup_traversal(struct cache_slice_header *head, unsigned char *map,
 	struct commit_list *prev, *wp, **wpp;
 	int retval;
 
-	/* printf("adding %s\n", sha1_to_hex(commit->object.sha1)); */

Likewise.

#2 lore raw
Quoted 6 lines

It is unclear which "size" this field refers to without comment.

I do not know if this change is justifiable.  We (mostly Linus) spent considerble effort to shrink the memory footprint of struct commit (and struct object in general) exactly because revision traversal needs to inspect tons of them.

I originally added a size field to objects, a unique field to commits and name ones to blobs/trees. This was (I reasoned) partly for applications to take fuller advantage of rev-cache's abilities, but largely to ease re-use of its information in slice regeneration.

However, in retrospect I think you're probably right. Not only do I not really need to load the information into memory to re-use it, but applications using rev-cache would probably have sufficiently specialized needs to warrant direct access. In light of this I've rewritten the fuse command to re-use data directly from the slice, rather than requiring it to be loaded into memory first (hence eliminating the all those extra fields). Furthermore I'll put all the (renamed) structures and definitions in a seperate header, to allow easy direct access to slices by third-parties.

Quoted 4 lines

Looks vaguely familiar.

The configuration parser already knows about these size suffixes when told to read "int".  Can't that code, e.g. git_parse_ulong(), be reused here?

You're also right here. I wrote it fast and hadn't checked if git had already implemented it. I've changed it to use git_parse_ulong().

Sorry I haven't uploaded anything yet. I keep seeing new things that could updated or revised; so far I've
- rewritten and added much to the documentation
- added support for an alternates-like mechanism
- changed --noobjects to --no-objects
- changed init_rci to init_rev_cache_info
- modified make_cache_slice to return actual start/end commits
- changed coagulate_ to fuse_
- added an (admittedly crude) escape plan in case of obscenely large
merges/branches
- cleaned up path generation
- replace parse_size with git_parse_ulong
- rewritten fuse to reuse objects verbatim, rather than via memory access

And on my todo list I've still got things such as renaming all the structures/definitions, adding a more portable _ondisk version of bitfield'ed structs and obviously cleanup the patchset (eliminating fixes of earlier patches, etc.).

I hope to get everything finished in the next couple days, and upload a v3 by friday at the latest.

- Nick

#3 lore raw
In reply to Nick Edelen

This patch, fourth, contains miscellaneous (maintenance) features:
- support for cache slice fusion, index regeneration and object size caching
- non-commit object generation refactored to take advantage of 'size' field
- porcelain updated to support feature additions

The beginnings of integration into git are present in this patch, mainly centered on caching object size; the object generation is refactored to more elegantly exploit this. Fusion allows smaller (incremental) slices to be coagulated into a larger slice, reducing overhead, while index regeneration enables repair or cleaning of the cache index.

Note that tests for these features are included in the following patch, as they take advantage of the rev-cache's integration into the revision walker.

---
 builtin-gc.c        |    9 +
 builtin-rev-cache.c |   77 ++++++-
 rev-cache.c         |  717 +++++++++++++++++++++++++++++++++++++++++++++------
 rev-cache.h         |    9 +-
 revision.h          |   16 +-
 5 files changed, 749 insertions(+), 79 deletions(-)
builtin-gc.c +9 -0
index 7d3e9cc..c92511a 100644
@@ -22,6 +22,7 @@ static const char * const builtin_gc_usage[] = {
 	NULL
 };
 
+static char do_rev_cache = 0;
 static int pack_refs = 1;
 static int aggressive_window = 250;
 static int gc_auto_threshold = 6700;
@@ -34,9 +35,14 @@ static const char *argv_reflog[] = {"reflog", "expire", "--all", NULL};
 static const char *argv_repack[MAX_ADD] = {"repack", "-d", "-l", NULL};
 static const char *argv_prune[] = {"prune", "--expire", NULL, NULL};
 static const char *argv_rerere[] = {"rerere", "gc", NULL};
+static const char *argv_rev_cache[] = {"rev-cache", "fuse", "--all", "--ignore-size", NULL};
 
 static int gc_config(const char *var, const char *value, void *cb)
 {
+	if (!strcmp(var, "gc.revcache")) {
+		do_rev_cache = 1;
+		return 0;
+	}
 	if (!strcmp(var, "gc.packrefs")) {
 		if (value && !strcmp(value, "notbare"))
 			pack_refs = -1;
@@ -244,6 +250,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 	if (run_command_v_opt(argv_rerere, RUN_GIT_CMD))
 		return error(FAILED_RUN, argv_rerere[0]);
 
+	if (do_rev_cache && run_command_v_opt(argv_rev_cache, RUN_GIT_CMD))
+		return error(FAILED_RUN, argv_rev_cache[0]);
+
 	if (auto_gc && too_many_loose_objects())
 		warning("There are too many unreachable loose objects; "
 			"run 'git prune' to remove them.");
builtin-rev-cache.c +76 -1

115 lines not on this page · raw message

rev-cache.c +641 -76

901 lines not on this page · raw message

rev-cache.h +8 -1
index a471fbf..14437d8 100644
@@ -3,6 +3,7 @@
 
 #define SUPPORTED_REVCACHE_VERSION 		1
 #define SUPPORTED_REVINDEX_VERSION		1
+#define SUPPORTED_REVCOPTR_VERSION		1
 
 #define RC_PATH_SIZE(x)	(sizeof(uint16_t) * (x))
 
@@ -10,6 +11,7 @@
 #define RC_OBTAIN_INDEX_ENTRY(p)			from_disked_rc_index_entry((struct rc_index_entry_ondisk *)(p), 0)
 
 #define RC_ACTUAL_OBJECT_ENTRY_SIZE(e)		(sizeof(struct rc_object_entry_ondisk) + RC_PATH_SIZE((e)->merge_nr + (e)->split_nr) + (e)->size_size)
+#define RC_ENTRY_SIZE_OFFSET(e)				(RC_ACTUAL_OBJECT_ENTRY_SIZE(e) - (e)->size_size)
 
 /* single index maps objects to cache files */
 struct rc_index_header {
@@ -90,6 +92,7 @@ struct rc_object_entry *from_disked_rc_object_entry(struct rc_object_entry_ondis
 struct rc_object_entry_ondisk *to_disked_rc_object_entry(struct rc_object_entry *src, struct rc_object_entry_ondisk *dst);
 
 extern unsigned char *get_cache_slice(struct commit *commit);
+extern int open_cache_slice(unsigned char *sha1, int flags);
 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,
@@ -102,6 +105,10 @@ extern int make_cache_slice(struct rev_cache_info *rci,
 extern int make_cache_index(struct rev_cache_info *rci, unsigned char *cache_sha1,
 	int fd, unsigned int size);
 
-extern void starts_from_slices(struct rev_info *revs, unsigned int flags);
+extern void starts_from_slices(struct rev_info *revs, unsigned int flags, unsigned char *which, int n);
+extern int fuse_cache_slices(struct rev_cache_info *rci, struct rev_info *revs);
+extern int regenerate_cache_index(struct rev_cache_info *rci);
+extern int make_cache_slice_pointer(struct rev_cache_info *rci, const char *slice_path);
 
 #endif
+
revision.h +15 -1
index e767a43..c3ec1b3 100644
@@ -19,17 +19,31 @@
 struct rev_info;
 struct log_info;
 
+struct rev_cache_slice_map {
+	unsigned char *map;
+	int size;
+	int last_index;
+};
+
 struct rev_cache_info {
 	/* generation flags */
 	unsigned objects : 1,
 		legs : 1,
-		make_index : 1;
+		make_index : 1,
+		fuse_me : 1;
+
+	/* index inclusion */
+	unsigned overwrite_all : 1;
 
 	/* traversal flags */
 	unsigned add_to_pending : 1;
 
 	/* fuse options */
 	unsigned int ignore_size;
+
+	/* reserved */
+	struct rev_cache_slice_map *maps,
+		*last_map;
 };
 
 struct rev_info {
Signature · 1 line
tg: (e07ed0b..) t/revcache/misc (depends on: t/revcache/objects)