Skip to content
Snippets Groups Projects
Commit 34fdece4 authored by bwzhou's avatar bwzhou
Browse files

Branch HEAD

b=14740
r=johann, bobijam

allocating one percpu struct each time instead of all in one time
parent d387061f
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
......@@ -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]));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment