{"thread":{"id":"17383","subject":"[PATCH/RFC v1 6/6] lstat_cache(): print a warning if doing ping-pong between cache types","startedAt":"2009-01-26T21:18:42Z","lastAt":"2009-01-26T21:18:42Z","messageCount":1,"participants":["Kjetil Barvik"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"102059","messageId":"1233004722-15142-1-git-send-email-barvik@broadpark.no","threadId":"17383","inReplyTo":null,"subject":"[PATCH/RFC v1 6/6] lstat_cache(): print a warning if doing ping-pong between cache types","fromName":"Kjetil Barvik","fromEmail":"barvik@broadpark.no","sentAt":"2009-01-26T21:18:42Z","receivedAt":"2009-01-26T21:18:42Z","isPatch":true,"sender":{"key":"barvik@broadpark.no","avatar":null},"body":"This is a debug patch which is only to be used while the lstat_cache()\nis in the test stage, and should be removed/reverted before the final\nrelase.\n\nI think it should be useful to catch these warnings, as I it could be\nan indication of that the cache would not be very effective if it is\ndoing ping-pong by switching between different cache types too many\ntimes.\n\nAlso, if someone is experimenting with the lstat_cache(), this patch\nwill maybe be useful while debugging.\n\nIf someone is able to trigger the warning, then send a mail to the GIT\nmailing list, containing the first 15 lines of the warning, and a\nshort description of the GIT commands to trigger the warnings.\n\nThis patch is against the 'next' branch.  I hope someone is willing to\nuse this patch for a while, to be able to catch possible ping-pong's.\n\nSigned-off-by: Kjetil Barvik <barvik@broadpark.no>\n---\n\nHmmm, it seems that 'git send-email' always fails for this mail, with\nthe following error message:\n\n   Died at /usr/local/libexec/git-core/git-send-email line 882.\n\nSo I send this as a separate command from 'git send-email', sorry\nabouth that.\n\n\n symlinks.c |   23 +++++++++++++++++++++++\n 1 files changed, 23 insertions(+), 0 deletions(-)\n\ndiff --git a/symlinks.c b/symlinks.c\nindex 81f490c..1c07ae0 100644\n--- a/symlinks.c\n+++ b/symlinks.c\n@@ -49,6 +49,11 @@ static inline void reset_lstat_cache(int track_flags, int prefix_len_stat_func)\n \tcache.prefix_len_stat_func = prefix_len_stat_func;\n }\n \n+#define SWITCHES_BEFORE_WARNING 10\n+static unsigned int cache_switches = 0, number_of_warnings = 0;\n+static unsigned int current_cache_func = 0, last_cache_func = 0;\n+static unsigned int total_calls = 0;\n+\n #define FL_DIR      (1 << 0)\n #define FL_NOENT    (1 << 1)\n #define FL_SYMLINK  (1 << 2)\n@@ -75,6 +80,7 @@ static int lstat_cache(int len, const char *name,\n \tint match_flags, ret_flags, save_flags, max_len, ret;\n \tstruct stat st;\n \n+\ttotal_calls++;\n \tif (cache.track_flags != track_flags ||\n \t    cache.prefix_len_stat_func != prefix_len_stat_func) {\n \t\t/*\n@@ -84,6 +90,17 @@ static int lstat_cache(int len, const char *name,\n \t\t */\n \t\treset_lstat_cache(track_flags, prefix_len_stat_func);\n \t\tmatch_len = last_slash = 0;\n+\t\tcache_switches++;\n+\t\tif (cache_switches > SWITCHES_BEFORE_WARNING) {\n+\t\t\tif (number_of_warnings < 10 || number_of_warnings % 1000 == 0)\n+\t\t\t\tprintf(\"warning from %s:%d cache_switches:%u > %u \"\\\n+\t\t\t\t       \"(current:%u last:%u total:%u)\\n\",\n+\t\t\t\t       __FILE__, __LINE__,\n+\t\t\t\t       cache_switches, SWITCHES_BEFORE_WARNING,\n+\t\t\t\t       current_cache_func, last_cache_func,\n+\t\t\t\t       total_calls);\n+\t\t\tnumber_of_warnings++;\n+\t\t}\n \t} else {\n \t\t/*\n \t\t * Check to see if we have a match from the cache for\n@@ -211,6 +228,8 @@ void clear_lstat_cache(void)\n  */\n int has_symlink_leading_path(int len, const char *name)\n {\n+\tlast_cache_func = current_cache_func;\n+\tcurrent_cache_func = 1;\n \treturn lstat_cache(len, name,\n \t\t\t   FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) &\n \t\tFL_SYMLINK;\n@@ -222,6 +241,8 @@ int has_symlink_leading_path(int len, const char *name)\n  */\n int has_symlink_or_noent_leading_path(int len, const char *name)\n {\n+\tlast_cache_func = current_cache_func;\n+\tcurrent_cache_func = 2;\n \treturn lstat_cache(len, name,\n \t\t\t   FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT) &\n \t\t(FL_SYMLINK|FL_NOENT);\n@@ -236,6 +257,8 @@ int has_symlink_or_noent_leading_path(int len, const char *name)\n  */\n int has_dirs_only_path(int len, const char *name, int prefix_len)\n {\n+\tlast_cache_func = current_cache_func;\n+\tcurrent_cache_func = 3;\n \treturn lstat_cache(len, name,\n \t\t\t   FL_DIR|FL_FULLPATH, prefix_len) &\n \t\tFL_DIR;\n-- \n1.6.1.349.g99fa5\n"}]}