lkml.org 
[lkml]   [2008]   [Dec]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 8/8] cpumask: use percpu allocations instead of array in arch/x86/kernel/cpu/mcheck/mce_64.c From: Rusty Russell <>
Impact: reduce memory usage, use alloc_percpu().

Instead of allocating an nr_cpu_ids array, most places should be using
percpu_alloc(). This doesn't waste space if cpu numbers aren't
contiguous.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Mike Travis <travis@sgi.com>
---
arch/x86/kernel/cpu/mcheck/mce_64.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

--- linux-2.6-for-ingo.orig/arch/x86/kernel/cpu/mcheck/mce_64.c
+++ linux-2.6-for-ingo/arch/x86/kernel/cpu/mcheck/mce_64.c
@@ -568,7 +568,7 @@ static void collect_tscs(void *data)
{
unsigned long *cpu_tsc = (unsigned long *)data;

- rdtscll(cpu_tsc[smp_processor_id()]);
+ rdtscll(*per_cpu_ptr(cpu_tsc, smp_processor_id()));
}

static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
@@ -580,7 +580,7 @@ static ssize_t mce_read(struct file *fil
char __user *buf = ubuf;
int i, err;

- cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
+ cpu_tsc = alloc_percpu(unsigned long);
if (!cpu_tsc)
return -ENOMEM;

@@ -590,7 +590,7 @@ static ssize_t mce_read(struct file *fil
/* Only supports full reads right now */
if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
mutex_unlock(&mce_read_mutex);
- kfree(cpu_tsc);
+ free_percpu(cpu_tsc);
return -EINVAL;
}

@@ -624,7 +624,8 @@ static ssize_t mce_read(struct file *fil
on_each_cpu(collect_tscs, cpu_tsc, 1);
for (i = next; i < MCE_LOG_LEN; i++) {
if (mcelog.entry[i].finished &&
- mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
+ mcelog.entry[i].tsc < *per_cpu_ptr(cpu_tsc,
+ mcelog.entry[i].cpu)) {
err |= copy_to_user(buf, mcelog.entry+i,
sizeof(struct mce));
smp_rmb();
@@ -633,7 +634,7 @@ static ssize_t mce_read(struct file *fil
}
}
mutex_unlock(&mce_read_mutex);
- kfree(cpu_tsc);
+ free_percpu(cpu_tsc);
return err ? -EFAULT : buf - ubuf;
}

--


\
 
 \ /
  Last update: 2008-12-19 01:05    [W:0.183 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site