Whamcloud - gitweb
LU-1282 lprocfs: free stat memory as it is cleared
authorBobi Jam <bobijam@whamcloud.com>
Mon, 4 Jun 2012 15:38:17 +0000 (23:38 +0800)
committerOleg Drokin <green@whamcloud.com>
Thu, 7 Jun 2012 17:58:22 +0000 (13:58 -0400)
Clear stats also free the stat memory occupation.

Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Change-Id: Ie0050eb716883aaeca08f4b3bacc772e83b87679
Reviewed-on: http://review.whamcloud.com/3026
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/lprocfs_status.c

index 765d017..4b957f7 100644 (file)
@@ -1272,24 +1272,36 @@ void lprocfs_clear_stats(struct lprocfs_stats *stats)
        int                     i;
        int                     j;
        unsigned int            num_entry;
+       unsigned int            percpusize;
        unsigned long           flags = 0;
 
        num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
 
+       percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
+       if (num_entry > 1)
+               percpusize = CFS_L1_CACHE_ALIGN(percpusize);
+
        for (i = 0; i < num_entry; i++) {
                if (stats->ls_percpu[i] == NULL)
                        continue;
-                for (j = 0; j < stats->ls_num; j++) {
-                        percpu_cntr = &(stats->ls_percpu[i])->lp_cntr[j];
-                        cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry);
-                        percpu_cntr->lc_count = 0;
-                        percpu_cntr->lc_sum = 0;
-                        percpu_cntr->lc_min = LC_MIN_INIT;
-                        percpu_cntr->lc_max = 0;
-                        percpu_cntr->lc_sumsquare = 0;
-                        cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit);
-                }
-        }
+               /* the 1st percpu entry was statically allocated in
+                * lprocfs_alloc_stats() */
+               if (i > 0) {
+                       OBD_FREE(stats->ls_percpu[i], percpusize);
+                       stats->ls_percpu[i] = NULL;
+                       continue;
+               }
+               for (j = 0; j < stats->ls_num; j++) {
+                       percpu_cntr = &(stats->ls_percpu[i])->lp_cntr[j];
+                       cfs_atomic_inc(&percpu_cntr->lc_cntl.la_entry);
+                       percpu_cntr->lc_count = 0;
+                       percpu_cntr->lc_sum = 0;
+                       percpu_cntr->lc_min = LC_MIN_INIT;
+                       percpu_cntr->lc_max = 0;
+                       percpu_cntr->lc_sumsquare = 0;
+                       cfs_atomic_inc(&percpu_cntr->lc_cntl.la_exit);
+               }
+       }
 
        lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
 }