Commit 4307e57760075c91b0b75b4cfa4fcf57d4c87c2d

Stefan Sperling 2018-06-22T11:04:15

size object caches independently of each other

diff --git a/lib/got_lib_repository.h b/lib/got_lib_repository.h
index f25073b..5d18ab9 100644
--- a/lib/got_lib_repository.h
+++ b/lib/got_lib_repository.h
@@ -17,7 +17,9 @@
 #define GOT_PACKIDX_CACHE_SIZE	64
 #define GOT_PACK_CACHE_SIZE	GOT_PACKIDX_CACHE_SIZE
 
-#define GOT_OBJECT_CACHE_SIZE	8192
+#define GOT_OBJECT_CACHE_SIZE_OBJ	8192
+#define GOT_OBJECT_CACHE_SIZE_TREE	4096
+#define GOT_OBJECT_CACHE_SIZE_COMMIT	2048
 
 enum got_object_chache_type {
 	GOT_OBJECT_CACHE_TYPE_OBJ,
@@ -37,6 +39,7 @@ struct got_object_cache_entry {
 struct got_object_cache {
 	enum got_object_chache_type type;
 	struct got_object_idset *set;
+	size_t size;
 	int cache_hit;
 	int cache_miss;
 };
diff --git a/lib/repository.c b/lib/repository.c
index 73293f2..098c270 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -157,7 +157,7 @@ cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
 	int nelem;
 
 	nelem = got_object_idset_num_elements(cache->set);
-	if (nelem >= GOT_OBJECT_CACHE_SIZE) {
+	if (nelem >= cache->size) {
 		err = got_object_idset_remove_random((void **)&ce,
 		    cache->set);
 		if (err)
@@ -318,6 +318,7 @@ got_repo_open(struct got_repository **ret, const char *path)
 		goto done;
 	}
 	repo->objcache.type = GOT_OBJECT_CACHE_TYPE_OBJ;
+	repo->objcache.size = GOT_OBJECT_CACHE_SIZE_OBJ;
 
 	repo->treecache.set = got_object_idset_alloc();
 	if (repo->treecache.set == NULL) {
@@ -325,6 +326,7 @@ got_repo_open(struct got_repository **ret, const char *path)
 		goto done;
 	}
 	repo->treecache.type = GOT_OBJECT_CACHE_TYPE_TREE;
+	repo->treecache.size = GOT_OBJECT_CACHE_SIZE_TREE;
 
 	repo->commitcache.set = got_object_idset_alloc();
 	if (repo->commitcache.set == NULL) {
@@ -332,6 +334,7 @@ got_repo_open(struct got_repository **ret, const char *path)
 		goto done;
 	}
 	repo->commitcache.type = GOT_OBJECT_CACHE_TYPE_COMMIT;
+	repo->commitcache.size = GOT_OBJECT_CACHE_SIZE_COMMIT;
 
 	repo->path = got_path_normalize(abspath);
 	if (repo->path == NULL) {