From 08e5803cd1441e358e97470206182bfd7ee59ee8 Mon Sep 17 00:00:00 2001 From: Frank Liepold Date: Mon, 16 Sep 2013 12:53:22 +0200 Subject: [PATCH] light: workaround flying IO before reporting memory leaks We report an error if there are unfreed mrefs after the device brick has been switched to power off. Instead of reporting an error at once, we report only warnings in the first 20 seconds. If there are still unfreed mrefs after that time an error is reported. --- kernel/sy_old/sy_generic.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/kernel/sy_old/sy_generic.c b/kernel/sy_old/sy_generic.c index d442cb4c..045e09e9 100644 --- a/kernel/sy_old/sy_generic.c +++ b/kernel/sy_old/sy_generic.c @@ -1044,6 +1044,8 @@ int mars_free_brick(struct mars_brick *brick) int i; int count; int status; + int sleeptime; + int maxsleep; if (!brick) { MARS_ERR("bad brick parameter\n"); @@ -1067,9 +1069,22 @@ int mars_free_brick(struct mars_brick *brick) } } - count = atomic_read(&brick->mref_object_layout.alloc_count); - if (count > 0) { - MARS_ERR("MEMLEAK: brick '%s' has %d mrefs allocated (total = %d)\n", brick->brick_path, count, atomic_read(&brick->mref_object_layout.total_alloc_count)); + // Should not happen, but workaround: wait until flying IO has vanished + maxsleep = 20000; + sleeptime = 1000; + for (;;) { + count = atomic_read(&brick->mref_object_layout.alloc_count); + if (likely(!count)) { + break; + } + if (maxsleep > 0) { + MARS_WRN("MEMLEAK: brick '%s' has %d mrefs allocated (total = %d, maxsleep = %d)\n", brick->brick_path, count, atomic_read(&brick->mref_object_layout.total_alloc_count), maxsleep); + } else { + MARS_ERR("MEMLEAK: brick '%s' has %d mrefs allocated (total = %d)\n", brick->brick_path, count, atomic_read(&brick->mref_object_layout.total_alloc_count)); + break; + } + brick_msleep(sleeptime); + maxsleep -= sleeptime; } MARS_DBG("===> freeing brick name = '%s' path = '%s'\n", brick->brick_name, brick->brick_path);