Re: [CHECKER] large stack variables (>=1K) in 2.4.4 and 2.4.4-ac8

From: dean gaudet (dean-list-linux-kernel@arctic.org)
Date: Fri May 25 2001 - 10:45:08 EST


On Fri, 25 May 2001, Andi Kleen wrote:

> On Fri, May 25, 2001 at 04:03:57PM +0200, Oliver Neukum wrote:
> > Is there a reason for the task structure to be at the bottom rather than the
> > top of these two pages ?
>
> This way you save one addition for every current access; which adds to
> quite a few KB over the complete kernel.

hrm, really?

i think it really depends on how you use current -- here's an alternative
usage which can fold the extra addition into the structure offset
calculations, and moves the task struct to the top of the stack.

not that this really solves anything, 'cause a stack underflow will just
trash something else rather than the task struct :)

-dean

% cat task.c
struct task {
        int a;
        int b;
};

#define current(p) (((struct task *)(((unsigned)p | 0x1fff)+1))-1)
int foo(void *p)
{
        return current(p)->a + current(p)->b;
}
% gcc -O -c task.c
% objdump -dr task.o

task.o: file format elf32-i386

Disassembly of section .text:

00000000 <foo>:
   0: 55 push %ebp
   1: 89 e5 mov %esp,%ebp
   3: 8b 55 08 mov 0x8(%ebp),%edx
   6: 81 ca ff 1f 00 00 or $0x1fff,%edx
   c: 8b 42 fd mov 0xfffffffd(%edx),%eax
   f: 03 42 f9 add 0xfffffff9(%edx),%eax
  12: c9 leave
  13: c3 ret

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu May 31 2001 - 21:00:24 EST