From: Joel Rosdahl Date: Tue, 20 Jul 2010 22:13:39 +0000 (+0200) Subject: Always update a stats file in a subdirectory to reduce lock contention X-Git-Tag: v3.1~136 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f4e92259b63e978bf027de2aac9e277ba951f91f;p=thirdparty%2Fccache.git Always update a stats file in a subdirectory to reduce lock contention --- diff --git a/stats.c b/stats.c index 2c854c27e..841e97c5d 100644 --- a/stats.c +++ b/stats.c @@ -23,6 +23,7 @@ */ #include "ccache.h" +#include "hashutil.h" #include #include @@ -176,13 +177,17 @@ void stats_flush(void) if (!should_flush) return; if (!stats_file) { + char *stats_dir; + /* * A NULL stats_file means that we didn't get past calculate_object_hash(), - * so we update the counter in the cache-wide statistics file - * CCACHE_DIR/stats instead of a subdirectory stats file. + * so we just choose one of stats files in the 16 subdirectories. */ if (!cache_dir) return; - stats_file = format("%s/stats", cache_dir); + stats_dir = format("%s/%x", cache_dir, hash_from_int(getpid()) % 16); + stats_file = format("%s/stats", stats_dir); + create_dir(stats_dir); + free(stats_dir); } fd = safe_open(stats_file);