From: Joel Rosdahl Date: Wed, 6 Jan 2010 14:24:24 +0000 (+0100) Subject: Truncate the manifest if there are too many object entries X-Git-Tag: v3.0pre0~112 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=47a89259f20065656e2a4d48228e3fce56dd8821;p=thirdparty%2Fccache.git Truncate the manifest if there are too many object entries Normally, there shouldn't be many object entries in the manifest since new entries are added only if an include file has changed but not the source file, and you typically change source files more often than header files. However, it's certainly possible to imagine cases where the manifest will grow large (for instance, a generated header file that changes for every build), and this must be taken care of since processing an ever growing manifest eventually will take too much time. A good way of solving this would be to maintain the object entries in LRU order and discarding the old ones. An easy way is to throw away all entries when there are too many. Let's do that for now. --- diff --git a/manifest.c b/manifest.c index 628ae0955..3265e87cf 100644 --- a/manifest.c +++ b/manifest.c @@ -69,6 +69,7 @@ static const uint32_t MAGIC = 0x63436d46U; static const uint32_t VERSION = 0; +static const uint32_t MAX_MANIFEST_ENTRIES = 100; #define static_assert(e) do { enum { static_assert__ = 1/(e) }; } while (0) @@ -606,6 +607,27 @@ int manifest_put(const char *manifest_path, struct file_hash *object_hash, } } + if (mf->n_objects > MAX_MANIFEST_ENTRIES) { + /* + * Normally, there shouldn't be many object entries in the + * manifest since new entries are added only if an include file + * has changed but not the source file, and you typically + * change source files more often than header files. However, + * it's certainly possible to imagine cases where the manifest + * will grow large (for instance, a generated header file that + * changes for every build), and this must be taken care of + * since processing an ever growing manifest eventually will + * take too much time. A good way of solving this would be to + * maintain the object entries in LRU order and discarding the + * old ones. An easy way is to throw away all entries when + * there are too many. Let's do that for now. + */ + cc_log("More than %u entries in %s; discarding\n", + MAX_MANIFEST_ENTRIES, manifest_path); + free_manifest(mf); + mf = create_empty_manifest(); + } + x_asprintf(&tmp_file, "%s.tmp.%s", manifest_path, tmp_string()); fd2 = safe_open(tmp_file); if (fd2 == -1) {