From f4e92259b63e978bf027de2aac9e277ba951f91f Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 21 Jul 2010 00:13:39 +0200 Subject: [PATCH] Always update a stats file in a subdirectory to reduce lock contention --- stats.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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); -- 2.47.3