size object caches independently of each other
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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) {