Skip to contentSkip to conversation

task_struct colouring ...

PATCH Manfred Spraul 3 participants 3 messages Dec 1, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines

2) Code clarity

I really liked Ben's idea of an include file with macros for asm access to the current pointer. That was a major improvement for the code clarity. IMHO a patch that changes current should introduce such a file.

Quoted 3 lines
      unsigned long tskb = __get_free_pages(GFP_KERNEL, 1), tsk;
     tsk = tskb | ((tskb >> 13) & 0x00000060) | SMP_CACHE_BYTES;
     *(unsigned long *) tskb = tsk;

You only colour 2 bits (offset 32, 64 or 96 - all within one cacheline on P 4) - I doubt that this helps a lot. And you do not colour the stack top - all processes sleeping in accept() will still have their wait queues at the same cache colour. And if you use more bits, you risk stack overflows.

Which means there are only 2 options for the memory allocation:
- split stack and task structure into 2 independant parts. task struct from slab, stack 8 kB-colouring.
- switch to 16 kB allocations for stack+task, and then colour both stack and task structure.

There are obviously lots of alternatives how to look up the task structure address:
* bottom of stack allocation (your patch)
* %cr2 (broken, only works for OS' that never cause page faults such as Netware)
* gs: (segment register, x86-64 uses that. But i386 doesn't have the swapgs instruction)
* str (Ben's patch)
* read from local apic memory (real slow!, uncached memory reference)

Quoted 3 lines

More, in finding the pointer directly at the base (SP & ~8191UL) makes it easy for external programs ( ie gdb ) to seek the task_struct w/out knowing the internal math that created it.

Is that a realistic problem? Usually you want to go from task struct to the stack, not the other way around.

--
Manfred

#1 lore raw
Quoted 7 lines · Manfred Spraul
Quoted 3 lines

2) Code clarity

I really liked Ben's idea of an include file with macros for asm access to the current pointer. That was a major improvement for the code clarity. IMHO a patch that changes current should introduce such a file.

Quoted 8 lines
Quoted 3 lines
      unsigned long tskb = __get_free_pages(GFP_KERNEL, 1), tsk;
     tsk = tskb | ((tskb >> 13) & 0x00000060) | SMP_CACHE_BYTES;
     *(unsigned long *) tskb = tsk;

You only colour 2 bits (offset 32, 64 or 96 - all within one cacheline on P 4) - I doubt that this helps a lot. And you do not colour the stack top - all processes sleeping in accept() will still have their wait queues at the same cache colour. And if you use more bits, you risk stack overflows.

32, 64, 96 and 128
Anyway it's clear that this is a 32 cache line size setup and that such magic numbers have to change accounding to cache line size and associativity level.
True that with CPUs with 7 or more bits for cache line size we're going to be subject of stack overflow.
More then increasing stack allocation i'd rather prefer to allocate two items ( like your patch ) 1) the task_struct from a slab 2) the stack with __get_free_pages().
What I do not really like is storing pointers inside global CPU registers, at least until the perf difference will justify it ( we'll see ). The stack jittering is quite easy to implement in arch/??/kernel/process.c and another couple of fixes.
I'll try slab task struct allocation + stack base pointer indirection.

- Davide

#2 lore raw
In reply to Manfred Spraul
Followup to:  <000901c17a51$62526070$010411ac@local>
By author:    "Manfred Spraul" <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 8 lines

There are obviously lots of alternatives how to look up the task structure address:
* bottom of stack allocation (your patch)
* %cr2 (broken, only works for OS' that never cause page faults such as Netware)
* gs: (segment register, x86-64 uses that. But i386 doesn't have the swapgs instruction)
* str (Ben's patch)
* read from local apic memory (real slow!, uncached memory reference)

%gs on x86-64 actually points to a per-CPU area; as does the proposed %tr hack. IMNSHO I think this is a much better idea than having something that points to "current"; if we do this consistently across architectures I'm sure there is plenty we can use this per-CPU area for.

Saving and restoring %gs (or %fs, which is less likely to be used in userspace, and therefore potentially faster) is probably not justifiable unless we do at least four accesses to "current" in the average system call.

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt	<[email protected]>