From 34fdece4b200d2868b07dfe4ae234533c9274c3f Mon Sep 17 00:00:00 2001 From: bwzhou <bwzhou> Date: Fri, 9 May 2008 17:44:57 +0000 Subject: [PATCH] Branch HEAD b=14740 r=johann, bobijam allocating one percpu struct each time instead of all in one time --- lustre/include/lprocfs_status.h | 1 - lustre/obdclass/lprocfs_status.c | 29 +++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 45ef4a7971..07f5c8fdc5 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -158,7 +158,6 @@ enum lprocfs_fields_flags { struct lprocfs_stats { unsigned int ls_num; /* # of counters */ - unsigned int ls_percpu_size; int ls_flags; /* See LPROCFS_STATS_FLAG_* */ spinlock_t ls_lock; /* Lock used only when there are * no percpu stats areas */ diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index adfd37428a..002b4ae816 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -758,9 +758,8 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags) { struct lprocfs_stats *stats; - struct lprocfs_percpu *percpu; unsigned int percpusize; - unsigned int i; + unsigned int i, j; unsigned int num_cpu; if (num == 0) @@ -783,12 +782,20 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num, stats->ls_flags = 0; } - percpusize = offsetof(typeof(*percpu), lp_cntr[num]); + percpusize = offsetof(struct lprocfs_percpu, lp_cntr[num]); if (num_cpu > 1) percpusize = L1_CACHE_ALIGN(percpusize); - stats->ls_percpu_size = num_cpu * percpusize; - OBD_ALLOC(stats->ls_percpu[0], stats->ls_percpu_size); + for (i = 0; i < num_cpu; i++) { + OBD_ALLOC(stats->ls_percpu[i], percpusize); + if (stats->ls_percpu[i] == NULL) { + for (j = 0; j < i; j++) { + OBD_FREE(stats->ls_percpu[j], percpusize); + stats->ls_percpu[j] = NULL; + } + break; + } + } if (stats->ls_percpu[0] == NULL) { OBD_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_cpu])); @@ -796,10 +803,6 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num, } stats->ls_num = num; - for (i = 1; i < num_cpu; i++) - stats->ls_percpu[i] = (void *)(stats->ls_percpu[i - 1]) + - percpusize; - return stats; } @@ -807,6 +810,8 @@ void lprocfs_free_stats(struct lprocfs_stats **statsh) { struct lprocfs_stats *stats = *statsh; unsigned int num_cpu; + unsigned int percpusize; + unsigned int i; if (stats == NULL || stats->ls_num == 0) return; @@ -817,7 +822,11 @@ void lprocfs_free_stats(struct lprocfs_stats **statsh) else num_cpu = num_possible_cpus(); - OBD_FREE(stats->ls_percpu[0], stats->ls_percpu_size); + percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]); + if (num_cpu > 1) + percpusize = L1_CACHE_ALIGN(percpusize); + for (i = 0; i < num_cpu; i++) + OBD_FREE(stats->ls_percpu[i], percpusize); OBD_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_cpu])); } -- GitLab