Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a4a6198

Browse files
Jan BeulichLinus Torvalds
authored andcommitted
[PATCH] tvec_bases too large for per-cpu data
With internal Xen-enabled kernels we see the kernel's static per-cpu data area exceed the limit of 32k on x86-64, and even native x86-64 kernels get fairly close to that limit. I generally question whether it is reasonable to have data structures several kb in size allocated as per-cpu data when the space there is rather limited. The biggest arch-independent consumer is tvec_bases (over 4k on 32-bit archs, over 8k on 64-bit ones), which now gets converted to use dynamically allocated memory instead. Signed-off-by: Jan Beulich <jbeulich@novell.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent c98d8cf commit a4a6198

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

kernel/timer.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ struct tvec_t_base_s {
8686
} ____cacheline_aligned_in_smp;
8787

8888
typedef struct tvec_t_base_s tvec_base_t;
89-
static DEFINE_PER_CPU(tvec_base_t, tvec_bases);
89+
static DEFINE_PER_CPU(tvec_base_t *, tvec_bases);
90+
static tvec_base_t boot_tvec_bases;
9091

9192
static inline void set_running_timer(tvec_base_t *base,
9293
struct timer_list *timer)
@@ -157,7 +158,7 @@ EXPORT_SYMBOL(__init_timer_base);
157158
void fastcall init_timer(struct timer_list *timer)
158159
{
159160
timer->entry.next = NULL;
160-
timer->base = &per_cpu(tvec_bases, raw_smp_processor_id()).t_base;
161+
timer->base = &per_cpu(tvec_bases, raw_smp_processor_id())->t_base;
161162
}
162163
EXPORT_SYMBOL(init_timer);
163164

@@ -218,7 +219,7 @@ int __mod_timer(struct timer_list *timer, unsigned long expires)
218219
ret = 1;
219220
}
220221

221-
new_base = &__get_cpu_var(tvec_bases);
222+
new_base = __get_cpu_var(tvec_bases);
222223

223224
if (base != &new_base->t_base) {
224225
/*
@@ -258,7 +259,7 @@ EXPORT_SYMBOL(__mod_timer);
258259
*/
259260
void add_timer_on(struct timer_list *timer, int cpu)
260261
{
261-
tvec_base_t *base = &per_cpu(tvec_bases, cpu);
262+
tvec_base_t *base = per_cpu(tvec_bases, cpu);
262263
unsigned long flags;
263264

264265
BUG_ON(timer_pending(timer) || !timer->function);
@@ -504,7 +505,7 @@ unsigned long next_timer_interrupt(void)
504505
}
505506
hr_expires += jiffies;
506507

507-
base = &__get_cpu_var(tvec_bases);
508+
base = __get_cpu_var(tvec_bases);
508509
spin_lock(&base->t_base.lock);
509510
expires = base->timer_jiffies + (LONG_MAX >> 1);
510511
list = NULL;
@@ -901,7 +902,7 @@ EXPORT_SYMBOL(xtime_lock);
901902
*/
902903
static void run_timer_softirq(struct softirq_action *h)
903904
{
904-
tvec_base_t *base = &__get_cpu_var(tvec_bases);
905+
tvec_base_t *base = __get_cpu_var(tvec_bases);
905906

906907
hrtimer_run_queues();
907908
if (time_after_eq(jiffies, base->timer_jiffies))
@@ -1256,12 +1257,32 @@ asmlinkage long sys_sysinfo(struct sysinfo __user *info)
12561257
return 0;
12571258
}
12581259

1259-
static void __devinit init_timers_cpu(int cpu)
1260+
static int __devinit init_timers_cpu(int cpu)
12601261
{
12611262
int j;
12621263
tvec_base_t *base;
12631264

1264-
base = &per_cpu(tvec_bases, cpu);
1265+
base = per_cpu(tvec_bases, cpu);
1266+
if (!base) {
1267+
static char boot_done;
1268+
1269+
/*
1270+
* Cannot do allocation in init_timers as that runs before the
1271+
* allocator initializes (and would waste memory if there are
1272+
* more possible CPUs than will ever be installed/brought up).
1273+
*/
1274+
if (boot_done) {
1275+
base = kmalloc_node(sizeof(*base), GFP_KERNEL,
1276+
cpu_to_node(cpu));
1277+
if (!base)
1278+
return -ENOMEM;
1279+
memset(base, 0, sizeof(*base));
1280+
} else {
1281+
base = &boot_tvec_bases;
1282+
boot_done = 1;
1283+
}
1284+
per_cpu(tvec_bases, cpu) = base;
1285+
}
12651286
spin_lock_init(&base->t_base.lock);
12661287
for (j = 0; j < TVN_SIZE; j++) {
12671288
INIT_LIST_HEAD(base->tv5.vec + j);
@@ -1273,6 +1294,7 @@ static void __devinit init_timers_cpu(int cpu)
12731294
INIT_LIST_HEAD(base->tv1.vec + j);
12741295

12751296
base->timer_jiffies = jiffies;
1297+
return 0;
12761298
}
12771299

12781300
#ifdef CONFIG_HOTPLUG_CPU
@@ -1295,8 +1317,8 @@ static void __devinit migrate_timers(int cpu)
12951317
int i;
12961318

12971319
BUG_ON(cpu_online(cpu));
1298-
old_base = &per_cpu(tvec_bases, cpu);
1299-
new_base = &get_cpu_var(tvec_bases);
1320+
old_base = per_cpu(tvec_bases, cpu);
1321+
new_base = get_cpu_var(tvec_bases);
13001322

13011323
local_irq_disable();
13021324
spin_lock(&new_base->t_base.lock);
@@ -1326,7 +1348,8 @@ static int __devinit timer_cpu_notify(struct notifier_block *self,
13261348
long cpu = (long)hcpu;
13271349
switch(action) {
13281350
case CPU_UP_PREPARE:
1329-
init_timers_cpu(cpu);
1351+
if (init_timers_cpu(cpu) < 0)
1352+
return NOTIFY_BAD;
13301353
break;
13311354
#ifdef CONFIG_HOTPLUG_CPU
13321355
case CPU_DEAD:

0 commit comments

Comments
 (0)