Skip to contentSkip to conversation

fork: Move most archs to generic threadinfo/taskstruct allocators

PATCH In review Thomas Gleixner 7 participants 57 messages May 5, 2012 – May 15, 2012

Subsystems (9)
x86 PowerPC MIPS MM core +5 more subsystems
lore
Share & tools
lore
#0 lore raw

cover fork: Move most archs to generic threadinfo/taskstruct allocators

We have a lot of duplicate implementations of the threadinfo and task struct allocator around in arch/*. This series consolidates them.

Applies on top of

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git smp/hotplug

Thanks,

tglx

---
 arch/Kconfig                            |    8 +++
 arch/c6x/include/asm/thread_info.h      |   17 -------
 arch/cris/include/asm/processor.h       |    5 --
 arch/cris/include/asm/thread_info.h     |    6 --
 arch/frv/include/asm/thread_info.h      |   13 ------
 arch/hexagon/include/asm/thread_info.h  |    8 ---
 arch/hexagon/kernel/process.c           |   37 -----------------
 arch/ia64/Kconfig                       |    2 
 arch/ia64/include/asm/thread_info.h     |    3 -
 arch/m32r/include/asm/thread_info.h     |   17 -------
 arch/mips/include/asm/thread_info.h     |   12 -----
 arch/mn10300/include/asm/thread_info.h  |   17 +------
 arch/mn10300/kernel/kgdb.c              |    3 -
 arch/powerpc/include/asm/thread_info.h  |   13 ------
 arch/powerpc/kernel/process.c           |   31 --------------
 arch/score/include/asm/thread_info.h    |   10 +---
 arch/sh/include/asm/thread_info.h       |   11 -----
 arch/sh/kernel/process.c                |   46 ---------------------
 arch/sparc/Kconfig                      |    1 
 arch/sparc/include/asm/thread_info_32.h |    2 
 arch/sparc/include/asm/thread_info_64.h |   25 -----------
 arch/tile/include/asm/thread_info.h     |    6 --
 arch/tile/kernel/process.c              |   23 ----------
 arch/x86/include/asm/boot.h             |    2 
 arch/x86/include/asm/page_32_types.h    |    4 -
 arch/x86/include/asm/page_64_types.h    |    4 -
 arch/x86/include/asm/thread_info.h      |   21 ---------
 arch/x86/kernel/irq_32.c                |    8 +--
 arch/x86/kernel/process.c               |    5 --
 include/linux/thread_info.h             |    6 ++
 kernel/fork.c                           |   69 ++++++++++++++++++++++----------
 31 files changed, 100 insertions(+), 335 deletions(-)
#1 lore raw

PATCH 1/18 fork: Remove the weak insanity

We error out when compiling with gcc4.1.[01] as it miscompiles __weak. The workaround with magic defines is not longer necessary. Make it __weak again.

---
 arch/sh/include/asm/thread_info.h  |    1 -
 arch/x86/include/asm/thread_info.h |    1 -
 kernel/fork.c                      |    8 +-------
 3 files changed, 1 insertion(+), 9 deletions(-)
arch/sh/include/asm/thread_info.h +0 -1
Index: tip/arch/sh/include/asm/thread_info.h
===================================================================
@@ -98,7 +98,6 @@ static inline struct thread_info *curren
 extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
 extern void free_thread_info(struct thread_info *ti);
 extern void arch_task_cache_init(void);
-#define arch_task_cache_init arch_task_cache_init
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
 extern void init_thread_xstate(void);
 
arch/x86/include/asm/thread_info.h +0 -1
Index: tip/arch/x86/include/asm/thread_info.h
===================================================================
@@ -284,6 +284,5 @@ static inline bool is_ia32_task(void)
 extern void arch_task_cache_init(void);
 extern void free_thread_info(struct thread_info *ti);
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
-#define arch_task_cache_init arch_task_cache_init
 #endif
 #endif /* _ASM_X86_THREAD_INFO_H */
kernel/fork.c +1 -7
Index: tip/kernel/fork.c
===================================================================
@@ -203,13 +203,7 @@ void __put_task_struct(struct task_struc
 }
 EXPORT_SYMBOL_GPL(__put_task_struct);
 
-/*
- * macro override instead of weak attribute alias, to workaround
- * gcc 4.1.0 and 4.1.1 bugs with weak attribute and empty functions.
- */
-#ifndef arch_task_cache_init
-#define arch_task_cache_init()
-#endif
+void __init __weak arch_task_cache_init(void) { }
 
 void __init fork_init(unsigned long mempages)
 {
#2 lore raw

Re: [patch 01/18] fork: Remove the weak insanity

Quoted 3 lines · Thomas Gleixner

We error out when compiling with gcc4.1.[01] as it miscompiles __weak. The workaround with magic defines is not longer necessary. Make it __weak again.

The cleanup is much appreciated!

But the magic defines is IMO much better than the CONFIG_ based approach that this patch-set introduces in the last patch.

If you do:

$git grep arch_task_cache_init

Then if you see:

    #define arch_task_cache_init arch_task_cache_init

Then you know alrady that this arch will provide a local implementation of arch_task_cache_init().
No need to grep for an ARCH_XXX symbol that you need to look up somewhere else.

Sam

#3 lore raw

Re: [patch 01/18] fork: Remove the weak insanity

Quoted 14 lines · Sam Ravnborg
Quoted 3 lines · Thomas Gleixner

We error out when compiling with gcc4.1.[01] as it miscompiles __weak. The workaround with magic defines is not longer necessary. Make it __weak again.

The cleanup is much appreciated!

But the magic defines is IMO much better than the CONFIG_ based approach that this patch-set introduces in the last patch.

If you do:

$git grep arch_task_cache_init

Quoted 8 lines

Then if you see:

    #define arch_task_cache_init arch_task_cache_init

Then you know alrady that this arch will provide a local implementation of arch_task_cache_init().
No need to grep for an ARCH_XXX symbol that you need to look up somewhere else.

I'm not following that argument.

Removing that magic define thing does not change anything. The change is:

-#define arch_task_cache_init arch_task_cache_init -#define arch_task_cache_init arch_task_cache_init
-/*
- * macro override instead of weak attribute alias, to workaround
- * gcc 4.1.0 and 4.1.1 bugs with weak attribute and empty functions.
- */
-#ifndef arch_task_cache_init
-#define arch_task_cache_init()
-#endif
+void __init __weak arch_task_cache_init(void) { }

So $git grep arch_task_cache_init still tells you who is overriding arch_task_cache_init () which is:

arch/sh/include/asm/thread_info.h:extern void arch_task_cache_init(void); arch/sh/kernel/process.c:void arch_task_cache_init(void) arch/x86/include/asm/thread_info.h:extern void arch_task_cache_init(void); arch/x86/kernel/process.c:void arch_task_cache_init(void)

What's your problem ?

Now for the last patch in the series:

It merily moves

#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR

to a Kconfig based

select ARCH_THREAD_INFO_ALLOCATOR

I'm not seeing any difference except that something which is actually a config switch is moved to the place where it belongs.

Thanks,

tglx

#4 lore raw

Re: [patch 01/18] fork: Remove the weak insanity

Quoted 29 lines · Thomas Gleixner
Quoted 14 lines · Sam Ravnborg
Quoted 3 lines · Thomas Gleixner

We error out when compiling with gcc4.1.[01] as it miscompiles __weak. The workaround with magic defines is not longer necessary. Make it __weak again.

The cleanup is much appreciated!

But the magic defines is IMO much better than the CONFIG_ based approach that this patch-set introduces in the last patch.

If you do:

$git grep arch_task_cache_init

Quoted 8 lines

Then if you see:

    #define arch_task_cache_init arch_task_cache_init

Then you know alrady that this arch will provide a local implementation of arch_task_cache_init().
No need to grep for an ARCH_XXX symbol that you need to look up somewhere else.

I'm not following that argument.

Removing that magic define thing does not change anything. The change is:

...

Quoted 10 lines

Now for the last patch in the series:

It merily moves

#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR

to a Kconfig based

select ARCH_THREAD_INFO_ALLOCATOR

The point was that rather than using a Kconfig symbol for this the architecutres that required a dedicated implementation could do the:

    #define foo foo

trick.

And the generic implmentation should then do:
#ifndef foo
void foo(int bar)
{
}
#endif

You are right that the archs implmenting foo() will stand out in the grep anyway.
But using the define trick you do not spread it up to the Kconfig level, for individual functions.

Sam

#5 lore raw

[tip:smp/hotplug] fork: Remove the weak insanity

In reply to Thomas Gleixner
Commit-ID:  6c0a9fa62feb7e9fdefa9720bcc03040c9b0b311
Gitweb:     http://git.kernel.org/tip/6c0a9fa62feb7e9fdefa9720bcc03040c9b0b311
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:40 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 13:55:20 +0200

fork: Remove the weak insanity

We error out when compiling with gcc4.1.[01] as it miscompiles __weak. The workaround with magic defines is not longer necessary. Make it __weak again.

---
 arch/sh/include/asm/thread_info.h  |    1 -
 arch/x86/include/asm/thread_info.h |    1 -
 kernel/fork.c                      |    8 +-------
 3 files changed, 1 insertions(+), 9 deletions(-)
arch/sh/include/asm/thread_info.h +0 -1
index 20ee40a..09963d4 100644
@@ -98,7 +98,6 @@ static inline struct thread_info *current_thread_info(void)
 extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
 extern void free_thread_info(struct thread_info *ti);
 extern void arch_task_cache_init(void);
-#define arch_task_cache_init arch_task_cache_init
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
 extern void init_thread_xstate(void);
 
arch/x86/include/asm/thread_info.h +0 -1
index ad6df8c..8692a16 100644
@@ -284,6 +284,5 @@ static inline bool is_ia32_task(void)
 extern void arch_task_cache_init(void);
 extern void free_thread_info(struct thread_info *ti);
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
-#define arch_task_cache_init arch_task_cache_init
 #endif
 #endif /* _ASM_X86_THREAD_INFO_H */
kernel/fork.c +1 -7
index b9372a0..a79b36e 100644
@@ -203,13 +203,7 @@ void __put_task_struct(struct task_struct *tsk)
 }
 EXPORT_SYMBOL_GPL(__put_task_struct);
 
-/*
- * macro override instead of weak attribute alias, to workaround
- * gcc 4.1.0 and 4.1.1 bugs with weak attribute and empty functions.
- */
-#ifndef arch_task_cache_init
-#define arch_task_cache_init()
-#endif
+void __init __weak arch_task_cache_init(void) { }
 
 void __init fork_init(unsigned long mempages)
 {
#6 lore raw

PATCH 2/18 fork: Provide weak arch_release_[task_struct|thread_info] functions

In reply to Thomas Gleixner

These functions allow us to move most of the duplicated thread_info allocators to the core code.

---
 kernel/fork.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
kernel/fork.c +17 -4
Index: tip/kernel/fork.c
===================================================================
@@ -112,14 +112,26 @@ int nr_processes(void)
 }
 
 #ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
-# define alloc_task_struct_node(node)		\
-		kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node)
-# define free_task_struct(tsk)			\
-		kmem_cache_free(task_struct_cachep, (tsk))
 static struct kmem_cache *task_struct_cachep;
+
+static inline struct task_struct *alloc_task_struct_node(int node)
+{
+	return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
+}
+
+void __weak arch_release_task_struct(struct task_struct *tsk) { }
+
+static inline void free_task_struct(struct task_struct *tsk)
+{
+	arch_release_task_struct(tsk);
+	kmem_cache_free(task_struct_cachep, tsk);
+}
 #endif
 
 #ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR
+
+void __weak arch_release_thread_info(struct thread_info *ti) { }
+
 static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 						  int node)
 {
@@ -135,6 +147,7 @@ static struct thread_info *alloc_thread_
 
 static inline void free_thread_info(struct thread_info *ti)
 {
+	arch_release_thread_info(ti);
 	free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
 }
 #endif
#7 lore raw

[tip:smp/hotplug] fork: Provide weak arch_release_[ task_struct|thread_info] functions

Commit-ID:  41101809a865dd0be1b56eff46c83fad321870b2
Gitweb:     http://git.kernel.org/tip/41101809a865dd0be1b56eff46c83fad321870b2
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:41 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 13:55:20 +0200

fork: Provide weak arch_release_[task_struct|thread_info] functions

These functions allow us to move most of the duplicated thread_info allocators to the core code.

---
 kernel/fork.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
kernel/fork.c +17 -4
index 5d22b9b..2dfad02 100644
@@ -112,14 +112,26 @@ int nr_processes(void)
 }
 
 #ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
-# define alloc_task_struct_node(node)		\
-		kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node)
-# define free_task_struct(tsk)			\
-		kmem_cache_free(task_struct_cachep, (tsk))
 static struct kmem_cache *task_struct_cachep;
+
+static inline struct task_struct *alloc_task_struct_node(int node)
+{
+	return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
+}
+
+void __weak arch_release_task_struct(struct task_struct *tsk) { }
+
+static inline void free_task_struct(struct task_struct *tsk)
+{
+	arch_release_task_struct(tsk);
+	kmem_cache_free(task_struct_cachep, tsk);
+}
 #endif
 
 #ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR
+
+void __weak arch_release_thread_info(struct thread_info *ti) { }
+
 static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 						  int node)
 {
@@ -131,6 +143,7 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 
 static inline void free_thread_info(struct thread_info *ti)
 {
+	arch_release_thread_info(ti);
 	free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
 }
 #endif
#8 lore raw

PATCH 3/18 fork: Move thread info gfp flags to header

In reply to Thomas Gleixner

These flags can be useful for extra allocations outside of the core code.

Add __GFP_NOTRACE to them, so the archs which have kmemcheck do not have to provide extra allocators just for that reason.

---
 include/linux/thread_info.h |    6 ++++++
 kernel/fork.c               |    8 ++------
 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/thread_info.h +6 -0
Index: tip/include/linux/thread_info.h
===================================================================
@@ -54,6 +54,12 @@ extern long do_no_restart_syscall(struct
 
 #ifdef __KERNEL__
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACE | __GFP_ZERO)
+#else
+# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACE)
+#endif
+
 /*
  * flag set/clear/test wrappers
  * - pass TIF_xxxx constants to these functions
kernel/fork.c +2 -6
Index: tip/kernel/fork.c
===================================================================
@@ -135,12 +135,8 @@ void __weak arch_release_thread_info(str
 static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 						  int node)
 {
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	gfp_t mask = GFP_KERNEL | __GFP_ZERO;
-#else
-	gfp_t mask = GFP_KERNEL;
-#endif
-	struct page *page = alloc_pages_node(node, mask, THREAD_SIZE_ORDER);
+	struct page *page = alloc_pages_node(node, THREADINFO_GFP,
+					     THREAD_SIZE_ORDER);
 
 	return page ? page_address(page) : NULL;
 }
#9 lore raw

Re: [patch 03/18] fork: Move thread info gfp flags to header

Quoted 5 lines · Thomas Gleixner

These flags can be useful for extra allocations outside of the core code.

Add __GFP_NOTRACE to them, so the archs which have kmemcheck do not have to provide extra allocators just for that reason.

This breaks powerpc builds due to __GFP_NOTRACE not being defined. I restarted the test after removing the __GFP_NOTRACE as a testing-only hack, and will let you know how it goes. Also looking into why this builds on 32-bit x86 but not on powerpc.

Thanx, Paul

Quoted 50 lines
---
 include/linux/thread_info.h |    6 ++++++
 kernel/fork.c               |    8 ++------
 2 files changed, 8 insertions(+), 6 deletions(-)

Index: tip/include/linux/thread_info.h
===================================================================

include/linux/thread_info.h +6 -0
@@ -54,6 +54,12 @@ extern long do_no_restart_syscall(struct
 
 #ifdef __KERNEL__
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACE | __GFP_ZERO)
+#else
+# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACE)
+#endif
+
 /*
  * flag set/clear/test wrappers
  * - pass TIF_xxxx constants to these functions

Index: tip/kernel/fork.c
===================================================================

kernel/fork.c +2 -7
@@ -135,12 +135,8 @@ void __weak arch_release_thread_info(str
 static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 						  int node)
 {
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	gfp_t mask = GFP_KERNEL | __GFP_ZERO;
-#else
-	gfp_t mask = GFP_KERNEL;
-#endif
-	struct page *page = alloc_pages_node(node, mask, THREAD_SIZE_ORDER);
+	struct page *page = alloc_pages_node(node, THREADINFO_GFP,
+					     THREAD_SIZE_ORDER);
 
 	return page ? page_address(page) : NULL;
 }
 
 
--

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

#10 lore raw

Re: [patch 03/18] fork: Move thread info gfp flags to header

Quoted 11 lines · Paul E. McKenney
Quoted 5 lines · Thomas Gleixner

These flags can be useful for extra allocations outside of the core code.

Add __GFP_NOTRACE to them, so the archs which have kmemcheck do not have to provide extra allocators just for that reason.

This breaks powerpc builds due to __GFP_NOTRACE not being defined. I restarted the test after removing the __GFP_NOTRACE as a testing-only hack, and will let you know how it goes. Also looking into why this builds on 32-bit x86 but not on powerpc.

And the reason that it built on 32-bit x86 was that I mistakenly built only the RCU files, not the whole kernel. So I am guessing that there is something I need to merge into tip/smp/hotplug.

On the other hand, removing the __GFP_NOTRACE allows this patchset to pass modest rcutorture testing on Power. ;-)

Thanx, Paul

#11 lore raw

Re: [patch 03/18] fork: Move thread info gfp flags to header

In reply to Paul E. McKenney
Quoted 11 lines · Paul E. McKenney
Quoted 5 lines · Thomas Gleixner

These flags can be useful for extra allocations outside of the core code.

Add __GFP_NOTRACE to them, so the archs which have kmemcheck do not have to provide extra allocators just for that reason.

This breaks powerpc builds due to __GFP_NOTRACE not being defined. I restarted the test after removing the __GFP_NOTRACE as a testing-only hack, and will let you know how it goes. Also looking into why this builds on 32-bit x86 but not on powerpc.

Hrmpf. Seems the idiot I am fatfingered __GFP_NOTRACK to __GFP_NOTRACE and then only tested with the DEBUG stuff disabled......

#12 lore raw

Re: [patch 03/18] fork: Move thread info gfp flags to header

Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Paul E. McKenney
Quoted 5 lines · Thomas Gleixner

These flags can be useful for extra allocations outside of the core code.

Add __GFP_NOTRACE to them, so the archs which have kmemcheck do not have to provide extra allocators just for that reason.

Quoted 7 lines
Quoted 4 lines

This breaks powerpc builds due to __GFP_NOTRACE not being defined. I restarted the test after removing the __GFP_NOTRACE as a testing-only hack, and will let you know how it goes. Also looking into why this builds on 32-bit x86 but not on powerpc.

Hrmpf. Seems the idiot I am fatfingered __GFP_NOTRACK to __GFP_NOTRACE and then only tested with the DEBUG stuff disabled......

That sounds like something I would do... ;-)

I will rerun with __GFP_NOTRACK.

Thanx, Paul

#13 lore raw

Re: [patch 03/18] fork: Move thread info gfp flags to header

Quoted 15 lines · Paul E. McKenney
Quoted 14 lines · Thomas Gleixner
Quoted 11 lines · Paul E. McKenney
Quoted 5 lines · Thomas Gleixner

These flags can be useful for extra allocations outside of the core code.

Add __GFP_NOTRACE to them, so the archs which have kmemcheck do not have to provide extra allocators just for that reason.

This breaks powerpc builds due to __GFP_NOTRACE not being defined. I restarted the test after removing the __GFP_NOTRACE as a testing-only hack, and will let you know how it goes. Also looking into why this builds on 32-bit x86 but not on powerpc.

Quoted 6 lines
Quoted 2 lines

Hrmpf. Seems the idiot I am fatfingered __GFP_NOTRACK to __GFP_NOTRACE and then only tested with the DEBUG stuff disabled......

That sounds like something I would do... ;-)

I will rerun with __GFP_NOTRACK.

Which passes moderate rcutorture testing on Power.

Thanx, Paul

#14 lore raw

[tip:smp/hotplug] fork: Move thread info gfp flags to header

In reply to Thomas Gleixner
Commit-ID:  2889f60814e15dea644782597d897cdba943564f
Gitweb:     http://git.kernel.org/tip/2889f60814e15dea644782597d897cdba943564f
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:41 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 13:55:20 +0200

fork: Move thread info gfp flags to header

These flags can be useful for extra allocations outside of the core code.

Add __GFP_NOTRACK to them, so the archs which have kmemcheck do not have to provide extra allocators just for that reason.

---
 include/linux/thread_info.h |    6 ++++++
 kernel/fork.c               |    8 ++------
 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/thread_info.h +6 -0
index 8d03f07..db78775 100644
@@ -54,6 +54,12 @@ extern long do_no_restart_syscall(struct restart_block *parm);
 
 #ifdef __KERNEL__
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
+#else
+# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACK)
+#endif
+
 /*
  * flag set/clear/test wrappers
  * - pass TIF_xxxx constants to these functions
kernel/fork.c +2 -6
index a79b36e..5d22b9b 100644
@@ -123,12 +123,8 @@ static struct kmem_cache *task_struct_cachep;
 static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 						  int node)
 {
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	gfp_t mask = GFP_KERNEL | __GFP_ZERO;
-#else
-	gfp_t mask = GFP_KERNEL;
-#endif
-	struct page *page = alloc_pages_node(node, mask, THREAD_SIZE_ORDER);
+	struct page *page = alloc_pages_node(node, THREADINFO_GFP,
+					     THREAD_SIZE_ORDER);
 
 	return page ? page_address(page) : NULL;
 }
#15 lore raw

PATCH 4/18 fork: Provide kmemcache based thread_info allocator

In reply to Thomas Gleixner

Several architectures have their own kmemcache based thread allocator because THREAD_SIZE is smaller than PAGE_SIZE. Add it to the core code conditionally on THREAD_SIZE < PAGE_SIZE so the private copies can go.

---
 kernel/fork.c |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
kernel/fork.c +27 -0
Index: tip/kernel/fork.c
===================================================================
@@ -132,6 +132,11 @@ static inline void free_task_struct(stru
 
 void __weak arch_release_thread_info(struct thread_info *ti) { }
 
+/*
+ * Allocate pages if THREAD_SIZE is >= PAGE_SIZE, otherwise use a
+ * kmemcache based allocator.
+ */
+# if THREAD_SIZE >= PAGE_SIZE
 static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 						  int node)
 {
@@ -146,6 +151,28 @@ static inline void free_thread_info(stru
 	arch_release_thread_info(ti);
 	free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
 }
+# else
+static struct kmem_cache *thread_info_cache;
+
+static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
+						  int node)
+{
+	return kmem_cache_alloc_node(thread_info_cache, THREADINFO_GFP, node);
+}
+
+static void free_thread_info(struct thread_info *ti)
+{
+	arch_release_thread_info(ti);
+	kmem_cache_free(thread_info_cache, ti);
+}
+
+void thread_info_cache_init(void)
+{
+	thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
+					      THREAD_SIZE, 0, NULL);
+	BUG_ON(thread_info_cache == NULL);
+}
+# endif
 #endif
 
 /* SLAB cache for signal_struct structures (tsk->signal) */
#16 lore raw

[tip:smp/hotplug] fork: Provide kmemcache based thread_info allocator

Commit-ID:  0d15d74a1ead10673b5b1db66d4c90552769096c
Gitweb:     http://git.kernel.org/tip/0d15d74a1ead10673b5b1db66d4c90552769096c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:41 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:44 +0200

fork: Provide kmemcache based thread_info allocator

Several architectures have their own kmemcache based thread allocator because THREAD_SIZE is smaller than PAGE_SIZE. Add it to the core code conditionally on THREAD_SIZE < PAGE_SIZE so the private copies can go.

---
 kernel/fork.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
kernel/fork.c +27 -0
index 2dfad02..7590bd6 100644
@@ -132,6 +132,11 @@ static inline void free_task_struct(struct task_struct *tsk)
 
 void __weak arch_release_thread_info(struct thread_info *ti) { }
 
+/*
+ * Allocate pages if THREAD_SIZE is >= PAGE_SIZE, otherwise use a
+ * kmemcache based allocator.
+ */
+# if THREAD_SIZE >= PAGE_SIZE
 static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
 						  int node)
 {
@@ -146,6 +151,28 @@ static inline void free_thread_info(struct thread_info *ti)
 	arch_release_thread_info(ti);
 	free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
 }
+# else
+static struct kmem_cache *thread_info_cache;
+
+static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
+						  int node)
+{
+	return kmem_cache_alloc_node(thread_info_cache, THREADINFO_GFP, node);
+}
+
+static void free_thread_info(struct thread_info *ti)
+{
+	arch_release_thread_info(ti);
+	kmem_cache_free(thread_info_cache, ti);
+}
+
+void thread_info_cache_init(void)
+{
+	thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
+					      THREAD_SIZE, 0, NULL);
+	BUG_ON(thread_info_cache == NULL);
+}
+# endif
 #endif
 
 /* SLAB cache for signal_struct structures (tsk->signal) */
#17 lore raw

PATCH 5/18 x86: Use common threadinfo allocator

In reply to Thomas Gleixner

The only difference is the free_thread_info function, which frees xstate.

Use the new arch_release_task_struct() function instead and switch over to the core allocator.

---
 arch/x86/include/asm/boot.h          |    2 +-
 arch/x86/include/asm/page_32_types.h |    4 ++--
 arch/x86/include/asm/page_64_types.h |    4 ++--
 arch/x86/include/asm/thread_info.h   |   20 +-------------------
 arch/x86/kernel/irq_32.c             |    8 ++++----
 arch/x86/kernel/process.c            |    5 ++---
 6 files changed, 12 insertions(+), 31 deletions(-)
arch/x86/include/asm/boot.h +1 -1
Index: tip/arch/x86/include/asm/boot.h
===================================================================
@@ -19,7 +19,7 @@
 #ifdef CONFIG_X86_64
 #define MIN_KERNEL_ALIGN_LG2	PMD_SHIFT
 #else
-#define MIN_KERNEL_ALIGN_LG2	(PAGE_SHIFT + THREAD_ORDER)
+#define MIN_KERNEL_ALIGN_LG2	(PAGE_SHIFT + THREAD_SIZE_ORDER)
 #endif
 #define MIN_KERNEL_ALIGN	(_AC(1, UL) << MIN_KERNEL_ALIGN_LG2)
 
arch/x86/include/asm/page_32_types.h +2 -2
Index: tip/arch/x86/include/asm/page_32_types.h
===================================================================
@@ -15,8 +15,8 @@
  */
 #define __PAGE_OFFSET		_AC(CONFIG_PAGE_OFFSET, UL)
 
-#define THREAD_ORDER	1
-#define THREAD_SIZE 	(PAGE_SIZE << THREAD_ORDER)
+#define THREAD_SIZE_ORDER	1
+#define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
 
 #define STACKFAULT_STACK 0
 #define DOUBLEFAULT_STACK 1
arch/x86/include/asm/page_64_types.h +2 -2
Index: tip/arch/x86/include/asm/page_64_types.h
===================================================================
@@ -1,8 +1,8 @@
 #ifndef _ASM_X86_PAGE_64_DEFS_H
 #define _ASM_X86_PAGE_64_DEFS_H
 
-#define THREAD_ORDER	1
-#define THREAD_SIZE  (PAGE_SIZE << THREAD_ORDER)
+#define THREAD_SIZE_ORDER	1
+#define THREAD_SIZE  (PAGE_SIZE << THREAD_SIZE_ORDER)
 #define CURRENT_MASK (~(THREAD_SIZE - 1))
 
 #define EXCEPTION_STACK_ORDER 0
arch/x86/include/asm/thread_info.h +1 -19
Index: tip/arch/x86/include/asm/thread_info.h
===================================================================
@@ -155,24 +155,6 @@ struct thread_info {
 
 #define PREEMPT_ACTIVE		0x10000000
 
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
-#else
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK)
-#endif
-
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-#define alloc_thread_info_node(tsk, node)				\
-({									\
-	struct page *page = alloc_pages_node(node, THREAD_FLAGS,	\
-					     THREAD_ORDER);		\
-	struct thread_info *ret = page ? page_address(page) : NULL;	\
-									\
-	ret;								\
-})
-
 #ifdef CONFIG_X86_32
 
 #define STACK_WARN	(THREAD_SIZE/8)
@@ -282,7 +264,7 @@ static inline bool is_ia32_task(void)
 
 #ifndef __ASSEMBLY__
 extern void arch_task_cache_init(void);
-extern void free_thread_info(struct thread_info *ti);
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
+extern void arch_release_task_struct(struct task_struct *tsk);
 #endif
 #endif /* _ASM_X86_THREAD_INFO_H */
arch/x86/kernel/irq_32.c +4 -4
Index: tip/arch/x86/kernel/irq_32.c
===================================================================
@@ -127,8 +127,8 @@ void __cpuinit irq_ctx_init(int cpu)
 		return;
 
 	irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
-					       THREAD_FLAGS,
-					       THREAD_ORDER));
+					       THREADINFO_GFP,
+					       THREAD_SIZE_ORDER));
 	memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
 	irqctx->tinfo.cpu		= cpu;
 	irqctx->tinfo.preempt_count	= HARDIRQ_OFFSET;
@@ -137,8 +137,8 @@ void __cpuinit irq_ctx_init(int cpu)
 	per_cpu(hardirq_ctx, cpu) = irqctx;
 
 	irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
-					       THREAD_FLAGS,
-					       THREAD_ORDER));
+					       THREADINFO_GFP,
+					       THREAD_SIZE_ORDER));
 	memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
 	irqctx->tinfo.cpu		= cpu;
 	irqctx->tinfo.addr_limit	= MAKE_MM_SEG(0);
arch/x86/kernel/process.c +2 -3
Index: tip/arch/x86/kernel/process.c
===================================================================
@@ -76,10 +76,9 @@ void free_thread_xstate(struct task_stru
 	fpu_free(&tsk->thread.fpu);
 }
 
-void free_thread_info(struct thread_info *ti)
+void arch_release_task_struct(struct task_struct *tsk)
 {
-	free_thread_xstate(ti->task);
-	free_pages((unsigned long)ti, THREAD_ORDER);
+	free_thread_xstate(tsk);
 }
 
 void arch_task_cache_init(void)
#18 lore raw

[tip:smp/hotplug] x86: Use common threadinfo allocator

Commit-ID:  38e7c572ce7310def003d8bb7c34260f5d8118cb
Gitweb:     http://git.kernel.org/tip/38e7c572ce7310def003d8bb7c34260f5d8118cb
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:42 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:44 +0200

x86: Use common threadinfo allocator

The only difference is the free_thread_info function, which frees xstate.

Use the new arch_release_task_struct() function instead and switch over to the core allocator.

---
 arch/x86/include/asm/boot.h          |    2 +-
 arch/x86/include/asm/page_32_types.h |    4 ++--
 arch/x86/include/asm/page_64_types.h |    4 ++--
 arch/x86/include/asm/thread_info.h   |   20 +-------------------
 arch/x86/kernel/irq_32.c             |    8 ++++----
 arch/x86/kernel/process.c            |    5 ++---
 6 files changed, 12 insertions(+), 31 deletions(-)
arch/x86/include/asm/boot.h +1 -1
index 5e1a2ee..b13fe63 100644
@@ -19,7 +19,7 @@
 #ifdef CONFIG_X86_64
 #define MIN_KERNEL_ALIGN_LG2	PMD_SHIFT
 #else
-#define MIN_KERNEL_ALIGN_LG2	(PAGE_SHIFT + THREAD_ORDER)
+#define MIN_KERNEL_ALIGN_LG2	(PAGE_SHIFT + THREAD_SIZE_ORDER)
 #endif
 #define MIN_KERNEL_ALIGN	(_AC(1, UL) << MIN_KERNEL_ALIGN_LG2)
 
arch/x86/include/asm/page_32_types.h +2 -2
index ade619f..ef17af0 100644
@@ -15,8 +15,8 @@
  */
 #define __PAGE_OFFSET		_AC(CONFIG_PAGE_OFFSET, UL)
 
-#define THREAD_ORDER	1
-#define THREAD_SIZE 	(PAGE_SIZE << THREAD_ORDER)
+#define THREAD_SIZE_ORDER	1
+#define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
 
 #define STACKFAULT_STACK 0
 #define DOUBLEFAULT_STACK 1
arch/x86/include/asm/page_64_types.h +2 -2
index 7639dbf..320f7bb 100644
@@ -1,8 +1,8 @@
 #ifndef _ASM_X86_PAGE_64_DEFS_H
 #define _ASM_X86_PAGE_64_DEFS_H
 
-#define THREAD_ORDER	1
-#define THREAD_SIZE  (PAGE_SIZE << THREAD_ORDER)
+#define THREAD_SIZE_ORDER	1
+#define THREAD_SIZE  (PAGE_SIZE << THREAD_SIZE_ORDER)
 #define CURRENT_MASK (~(THREAD_SIZE - 1))
 
 #define EXCEPTION_STACK_ORDER 0
arch/x86/include/asm/thread_info.h +1 -19
index 8692a16..73cfe0d 100644
@@ -155,24 +155,6 @@ struct thread_info {
 
 #define PREEMPT_ACTIVE		0x10000000
 
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
-#else
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK)
-#endif
-
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-#define alloc_thread_info_node(tsk, node)				\
-({									\
-	struct page *page = alloc_pages_node(node, THREAD_FLAGS,	\
-					     THREAD_ORDER);		\
-	struct thread_info *ret = page ? page_address(page) : NULL;	\
-									\
-	ret;								\
-})
-
 #ifdef CONFIG_X86_32
 
 #define STACK_WARN	(THREAD_SIZE/8)
@@ -282,7 +264,7 @@ static inline bool is_ia32_task(void)
 
 #ifndef __ASSEMBLY__
 extern void arch_task_cache_init(void);
-extern void free_thread_info(struct thread_info *ti);
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
+extern void arch_release_task_struct(struct task_struct *tsk);
 #endif
 #endif /* _ASM_X86_THREAD_INFO_H */
arch/x86/kernel/irq_32.c +4 -4
index 58b7f27..344faf8 100644
@@ -127,8 +127,8 @@ void __cpuinit irq_ctx_init(int cpu)
 		return;
 
 	irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
-					       THREAD_FLAGS,
-					       THREAD_ORDER));
+					       THREADINFO_GFP,
+					       THREAD_SIZE_ORDER));
 	memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
 	irqctx->tinfo.cpu		= cpu;
 	irqctx->tinfo.preempt_count	= HARDIRQ_OFFSET;
@@ -137,8 +137,8 @@ void __cpuinit irq_ctx_init(int cpu)
 	per_cpu(hardirq_ctx, cpu) = irqctx;
 
 	irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
-					       THREAD_FLAGS,
-					       THREAD_ORDER));
+					       THREADINFO_GFP,
+					       THREAD_SIZE_ORDER));
 	memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
 	irqctx->tinfo.cpu		= cpu;
 	irqctx->tinfo.addr_limit	= MAKE_MM_SEG(0);
arch/x86/kernel/process.c +2 -3
index 8215458..e817315 100644
@@ -76,10 +76,9 @@ void free_thread_xstate(struct task_struct *tsk)
 	fpu_free(&tsk->thread.fpu);
 }
 
-void free_thread_info(struct thread_info *ti)
+void arch_release_task_struct(struct task_struct *tsk)
 {
-	free_thread_xstate(ti->task);
-	free_pages((unsigned long)ti, THREAD_ORDER);
+	free_thread_xstate(tsk);
 }
 
 void arch_task_cache_init(void)
#19 lore raw

PATCH 6/18 c6x: Use common threadinfo allocator

In reply to Thomas Gleixner

There is no functional difference. __get_free_pages() ends up calling alloc_pages_node().

---
 arch/c6x/include/asm/thread_info.h |   17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
arch/c6x/include/asm/thread_info.h +2 -15
Index: tip/arch/c6x/include/asm/thread_info.h
===================================================================
@@ -20,11 +20,11 @@
 #ifdef CONFIG_4KSTACKS
 #define THREAD_SIZE		4096
 #define THREAD_SHIFT		12
-#define THREAD_ORDER		0
+#define THREAD_SIZE_ORDER	0
 #else
 #define THREAD_SIZE		8192
 #define THREAD_SHIFT		13
-#define THREAD_ORDER		1
+#define THREAD_SIZE_ORDER	1
 #endif
 
 #define THREAD_START_SP		(THREAD_SIZE - 8)
@@ -80,19 +80,6 @@ struct thread_info *current_thread_info(
 	return ti;
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
-#else
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK)
-#endif
-
-#define alloc_thread_info_node(tsk, node)	\
-	((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
-
-#define free_thread_info(ti)	free_pages((unsigned long) (ti), THREAD_ORDER)
 #define get_thread_info(ti)	get_task_struct((ti)->task)
 #define put_thread_info(ti)	put_task_struct((ti)->task)
 #endif /* __ASSEMBLY__ */
#21 lore raw

[tip:smp/hotplug] c6x: Use common threadinfo allocator

In reply to Thomas Gleixner
Commit-ID:  7b8fe0570a65486e77823d5fcec9998c2aae9970
Gitweb:     http://git.kernel.org/tip/7b8fe0570a65486e77823d5fcec9998c2aae9970
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:42 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:44 +0200

c6x: Use common threadinfo allocator

There is no functional difference. __get_free_pages() ends up calling alloc_pages_node().

---
 arch/c6x/include/asm/thread_info.h |   17 ++---------------
 1 files changed, 2 insertions(+), 15 deletions(-)
arch/c6x/include/asm/thread_info.h +2 -15
index fd99148..1710bcb 100644
@@ -20,11 +20,11 @@
 #ifdef CONFIG_4KSTACKS
 #define THREAD_SIZE		4096
 #define THREAD_SHIFT		12
-#define THREAD_ORDER		0
+#define THREAD_SIZE_ORDER	0
 #else
 #define THREAD_SIZE		8192
 #define THREAD_SHIFT		13
-#define THREAD_ORDER		1
+#define THREAD_SIZE_ORDER	1
 #endif
 
 #define THREAD_START_SP		(THREAD_SIZE - 8)
@@ -80,19 +80,6 @@ struct thread_info *current_thread_info(void)
 	return ti;
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
-#else
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK)
-#endif
-
-#define alloc_thread_info_node(tsk, node)	\
-	((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
-
-#define free_thread_info(ti)	free_pages((unsigned long) (ti), THREAD_ORDER)
 #define get_thread_info(ti)	get_task_struct((ti)->task)
 #define put_thread_info(ti)	put_task_struct((ti)->task)
 #endif /* __ASSEMBLY__ */
#22 lore raw

PATCH 7/18 cris: Use common threadinfo allocator

In reply to Thomas Gleixner

There is no functional difference. __get_free_pages() ends up calling alloc_pages_node().

This also allocates only one page which matches THREAD_SIZE instead of an extra page for nothing.

---
 arch/cris/include/asm/processor.h   |    5 ++---
 arch/cris/include/asm/thread_info.h |    6 ------
 2 files changed, 2 insertions(+), 9 deletions(-)
arch/cris/include/asm/processor.h +2 -3
Index: tip/arch/cris/include/asm/processor.h
===================================================================
@@ -25,13 +25,12 @@ struct task_struct;
  */
 #define TASK_UNMAPPED_BASE      (PAGE_ALIGN(TASK_SIZE / 3))
 
-/* THREAD_SIZE is the size of the task_struct/kernel_stack combo.
+/* THREAD_SIZE is the size of the thread_info/kernel_stack combo.
  * normally, the stack is found by doing something like p + THREAD_SIZE
  * in CRIS, a page is 8192 bytes, which seems like a sane size
  */
-
 #define THREAD_SIZE       PAGE_SIZE
-#define KERNEL_STACK_SIZE PAGE_SIZE
+#define THREAD_SIZE_ORDER (0)
 
 /*
  * At user->kernel entry, the pt_regs struct is stacked on the top of the kernel-stack.
arch/cris/include/asm/thread_info.h +0 -6
Index: tip/arch/cris/include/asm/thread_info.h
===================================================================
@@ -65,12 +65,6 @@ struct thread_info {
 
 #define init_thread_info	(init_thread_union.thread_info)
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-/* thread information allocation */
-#define alloc_thread_info_node(tsk, node)	\
-	((struct thread_info *) __get_free_pages(GFP_KERNEL, 1))
-#define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
-
 #endif /* !__ASSEMBLY__ */
 
 /*
#23 lore raw

[tip:smp/hotplug] cris: Use common threadinfo allocator

Commit-ID:  803fc74f06cf3cd23417463ca5a176b41717ec19
Gitweb:     http://git.kernel.org/tip/803fc74f06cf3cd23417463ca5a176b41717ec19
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:43 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:44 +0200

cris: Use common threadinfo allocator

There is no functional difference. __get_free_pages() ends up calling alloc_pages_node().

This also allocates only one page which matches THREAD_SIZE instead of an extra page for nothing.

---
 arch/cris/include/asm/processor.h   |    5 ++---
 arch/cris/include/asm/thread_info.h |    6 ------
 2 files changed, 2 insertions(+), 9 deletions(-)
arch/cris/include/asm/processor.h +2 -3
index 4210d72..8dc56ef 100644
@@ -25,13 +25,12 @@ struct task_struct;
  */
 #define TASK_UNMAPPED_BASE      (PAGE_ALIGN(TASK_SIZE / 3))
 
-/* THREAD_SIZE is the size of the task_struct/kernel_stack combo.
+/* THREAD_SIZE is the size of the thread_info/kernel_stack combo.
  * normally, the stack is found by doing something like p + THREAD_SIZE
  * in CRIS, a page is 8192 bytes, which seems like a sane size
  */
-
 #define THREAD_SIZE       PAGE_SIZE
-#define KERNEL_STACK_SIZE PAGE_SIZE
+#define THREAD_SIZE_ORDER (0)
 
 /*
  * At user->kernel entry, the pt_regs struct is stacked on the top of the kernel-stack.
arch/cris/include/asm/thread_info.h +0 -6
index 29b9288..5b1c448 100644
@@ -65,12 +65,6 @@ struct thread_info {
 
 #define init_thread_info	(init_thread_union.thread_info)
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-/* thread information allocation */
-#define alloc_thread_info_node(tsk, node)	\
-	((struct thread_info *) __get_free_pages(GFP_KERNEL, 1))
-#define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
-
 #endif /* !__ASSEMBLY__ */
 
 /*
Acked-by on v1 7/18
#24 lore raw

Re: [patch 07/18] cris: Use common threadinfo allocator

In reply to Thomas Gleixner
Quoted 7 lines · Thomas Gleixner

There is no functional difference. __get_free_pages() ends up calling alloc_pages_node().

This also allocates only one page which matches THREAD_SIZE instead of an extra page for nothing.

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]
#25 lore raw

PATCH 8/18 frv: Use common threadinfo allocator

In reply to Thomas Gleixner

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

---
 arch/frv/include/asm/thread_info.h |   13 -------------
 1 file changed, 13 deletions(-)
arch/frv/include/asm/thread_info.h +0 -13
Index: tip/arch/frv/include/asm/thread_info.h
===================================================================
@@ -80,19 +80,6 @@ register struct thread_info *__current_t
 
 #define current_thread_info() ({ __current_thread_info; })
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node)			\
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node)			\
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
-#define free_thread_info(info)	kfree(info)
-
 #endif /* __ASSEMBLY__ */
 
 /*
#26 lore raw

[tip:smp/hotplug] frv: Use common threadinfo allocator

Commit-ID:  c64872cd0dd5892f4d6f3605ffca36d13e63443d
Gitweb:     http://git.kernel.org/tip/c64872cd0dd5892f4d6f3605ffca36d13e63443d
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:43 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:44 +0200

frv: Use common threadinfo allocator

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

---
 arch/frv/include/asm/thread_info.h |   13 -------------
 1 files changed, 0 insertions(+), 13 deletions(-)
arch/frv/include/asm/thread_info.h +0 -13
index aaea388..54ab13a 100644
@@ -80,19 +80,6 @@ register struct thread_info *__current_thread_info asm("gr15");
 
 #define current_thread_info() ({ __current_thread_info; })
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node)			\
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node)			\
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
-#define free_thread_info(info)	kfree(info)
-
 #endif /* __ASSEMBLY__ */
 
 /*
#27 lore raw

PATCH 9/18 hexagon: Use common threadinfo allocator

In reply to Thomas Gleixner

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

---
 arch/hexagon/include/asm/thread_info.h |    8 -------
 arch/hexagon/kernel/process.c          |   37 ---------------------------------
 2 files changed, 45 deletions(-)
arch/hexagon/include/asm/thread_info.h +0 -8
Index: tip/arch/hexagon/include/asm/thread_info.h
===================================================================
@@ -31,15 +31,7 @@
 
 #define THREAD_SHIFT		12
 #define THREAD_SIZE		(1<<THREAD_SHIFT)
-
-#if THREAD_SHIFT >= PAGE_SHIFT
 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
-#else  /*  don't use standard allocator  */
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
-extern void free_thread_info(struct thread_info *ti);
-#endif
-
 
 #ifndef __ASSEMBLY__
 
arch/hexagon/kernel/process.c +0 -37
Index: tip/arch/hexagon/kernel/process.c
===================================================================
@@ -234,43 +234,6 @@ unsigned long get_wchan(struct task_stru
 }
 
 /*
- * Borrowed from PowerPC -- basically allow smaller kernel stacks if we
- * go crazy with the page sizes.
- */
-#if THREAD_SHIFT < PAGE_SHIFT
-
-static struct kmem_cache *thread_info_cache;
-
-struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
-{
-	struct thread_info *ti;
-
-	ti = kmem_cache_alloc_node(thread_info_cache, GFP_KERNEL, node);
-	if (unlikely(ti == NULL))
-		return NULL;
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	memset(ti, 0, THREAD_SIZE);
-#endif
-	return ti;
-}
-
-void free_thread_info(struct thread_info *ti)
-{
-	kmem_cache_free(thread_info_cache, ti);
-}
-
-/*  Weak symbol; called by init/main.c  */
-
-void thread_info_cache_init(void)
-{
-	thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
-					      THREAD_SIZE, 0, NULL);
-	BUG_ON(thread_info_cache == NULL);
-}
-
-#endif /* THREAD_SHIFT < PAGE_SHIFT */
-
-/*
  * Required placeholder.
  */
 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
#28 lore raw

[tip:smp/hotplug] hexagon: Use common threadinfo allocator

Commit-ID:  fe844052bca4355bf1a1b078d3e7727800cf3c73
Gitweb:     http://git.kernel.org/tip/fe844052bca4355bf1a1b078d3e7727800cf3c73
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:44 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:45 +0200

hexagon: Use common threadinfo allocator

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

---
 arch/hexagon/include/asm/thread_info.h |    8 -------
 arch/hexagon/kernel/process.c          |   37 --------------------------------
 2 files changed, 0 insertions(+), 45 deletions(-)
arch/hexagon/include/asm/thread_info.h +0 -8
index 9c2934f..4f936a7 100644
@@ -31,15 +31,7 @@
 
 #define THREAD_SHIFT		12
 #define THREAD_SIZE		(1<<THREAD_SHIFT)
-
-#if THREAD_SHIFT >= PAGE_SHIFT
 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
-#else  /*  don't use standard allocator  */
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
-extern void free_thread_info(struct thread_info *ti);
-#endif
-
 
 #ifndef __ASSEMBLY__
 
arch/hexagon/kernel/process.c +0 -37
index ff02821..af51de6 100644
@@ -234,43 +234,6 @@ unsigned long get_wchan(struct task_struct *p)
 }
 
 /*
- * Borrowed from PowerPC -- basically allow smaller kernel stacks if we
- * go crazy with the page sizes.
- */
-#if THREAD_SHIFT < PAGE_SHIFT
-
-static struct kmem_cache *thread_info_cache;
-
-struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
-{
-	struct thread_info *ti;
-
-	ti = kmem_cache_alloc_node(thread_info_cache, GFP_KERNEL, node);
-	if (unlikely(ti == NULL))
-		return NULL;
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	memset(ti, 0, THREAD_SIZE);
-#endif
-	return ti;
-}
-
-void free_thread_info(struct thread_info *ti)
-{
-	kmem_cache_free(thread_info_cache, ti);
-}
-
-/*  Weak symbol; called by init/main.c  */
-
-void thread_info_cache_init(void)
-{
-	thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
-					      THREAD_SIZE, 0, NULL);
-	BUG_ON(thread_info_cache == NULL);
-}
-
-#endif /* THREAD_SHIFT < PAGE_SHIFT */
-
-/*
  * Required placeholder.
  */
 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
#29 lore raw

PATCH 10/18 m32r: Use common threadinfo allocator

In reply to Thomas Gleixner

No reason why m32r needs to use kmalloc to allocate 2 pages instead of using the core allocator.

---
 arch/m32r/include/asm/thread_info.h |   17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
arch/m32r/include/asm/thread_info.h +2 -15
Index: tip/arch/m32r/include/asm/thread_info.h
===================================================================
@@ -55,8 +55,8 @@ struct thread_info {
 
 #define PREEMPT_ACTIVE		0x10000000
 
-#define THREAD_SIZE (PAGE_SIZE << 1)
-
+#define THREAD_SIZE		(PAGE_SIZE << 1)
+#define THREAD_SIZE_ORDER	1
 /*
  * macros/functions for gaining access to the thread information structure
  */
@@ -92,19 +92,6 @@ static inline struct thread_info *curren
 	return ti;
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node)			\
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node)			\
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
-#define free_thread_info(info) kfree(info)
-
 #define TI_FLAG_FAULT_CODE_SHIFT	28
 
 static inline void set_thread_fault_code(unsigned int val)
#30 lore raw

[tip:smp/hotplug] m32r: Use common threadinfo allocator

Commit-ID:  e6e9c540d5d177e7a40d8b40a3b2386bdefbe5da
Gitweb:     http://git.kernel.org/tip/e6e9c540d5d177e7a40d8b40a3b2386bdefbe5da
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:44 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:45 +0200

m32r: Use common threadinfo allocator

No reason why m32r needs to use kmalloc to allocate 2 pages instead of using the core allocator.

---
 arch/m32r/include/asm/thread_info.h |   17 ++---------------
 1 files changed, 2 insertions(+), 15 deletions(-)
arch/m32r/include/asm/thread_info.h +2 -15
index bf8fa3c..c083f60 100644
@@ -55,8 +55,8 @@ struct thread_info {
 
 #define PREEMPT_ACTIVE		0x10000000
 
-#define THREAD_SIZE (PAGE_SIZE << 1)
-
+#define THREAD_SIZE		(PAGE_SIZE << 1)
+#define THREAD_SIZE_ORDER	1
 /*
  * macros/functions for gaining access to the thread information structure
  */
@@ -92,19 +92,6 @@ static inline struct thread_info *current_thread_info(void)
 	return ti;
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node)			\
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node)			\
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
-#define free_thread_info(info) kfree(info)
-
 #define TI_FLAG_FAULT_CODE_SHIFT	28
 
 static inline void set_thread_fault_code(unsigned int val)
#31 lore raw

PATCH 11/18 mips: Use common threadinfo allocator

In reply to Thomas Gleixner

No point in using kmalloc for allocating 0, 1 resp. 2 pages for threadinfo.

---
 arch/mips/include/asm/thread_info.h |   12 ------------
 1 file changed, 12 deletions(-)
arch/mips/include/asm/thread_info.h +0 -12
Index: tip/arch/mips/include/asm/thread_info.h
===================================================================
@@ -85,18 +85,6 @@ register struct thread_info *__current_t
 
 #define STACK_WARN	(THREAD_SIZE / 8)
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node) \
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node) \
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
-#define free_thread_info(info) kfree(info)
-
 #endif /* !__ASSEMBLY__ */
 
 #define PREEMPT_ACTIVE		0x10000000
#32 lore raw

[tip:smp/hotplug] mips: Use common threadinfo allocator

Commit-ID:  3194f61de93d4d4fbc2f2ddb25aeded6f9cebaeb
Gitweb:     http://git.kernel.org/tip/3194f61de93d4d4fbc2f2ddb25aeded6f9cebaeb
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:44 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:45 +0200

mips: Use common threadinfo allocator

No point in using kmalloc for allocating 0, 1 resp. 2 pages for threadinfo.

---
 arch/mips/include/asm/thread_info.h |   12 ------------
 1 files changed, 0 insertions(+), 12 deletions(-)
arch/mips/include/asm/thread_info.h +0 -12
index 0d85d8e..e2eca7d 100644
@@ -85,18 +85,6 @@ register struct thread_info *__current_thread_info __asm__("$28");
 
 #define STACK_WARN	(THREAD_SIZE / 8)
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node) \
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node) \
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
-#define free_thread_info(info) kfree(info)
-
 #endif /* !__ASSEMBLY__ */
 
 #define PREEMPT_ACTIVE		0x10000000
#33 lore raw

PATCH 12/18 mn10300: Use common threadinfo allocator

In reply to Thomas Gleixner

Let the core code allocate and handle the kgdb cleanup with the arch_release_thread_info() function.

---
 arch/mn10300/include/asm/thread_info.h |   17 +++--------------
 arch/mn10300/kernel/kgdb.c             |    3 +--
 2 files changed, 4 insertions(+), 16 deletions(-)
arch/mn10300/include/asm/thread_info.h +3 -14
Index: tip/arch/mn10300/include/asm/thread_info.h
===================================================================
@@ -20,8 +20,10 @@
 
 #ifdef CONFIG_4KSTACKS
 #define THREAD_SIZE		(4096)
+#define THREAD_SIZE_ORDER	(0)
 #else
 #define THREAD_SIZE		(8192)
+#define THREAD_SIZE_ORDER	(1)
 #endif
 
 #define STACK_WARN		(THREAD_SIZE / 8)
@@ -120,21 +122,8 @@ static inline unsigned long current_stac
 	return sp;
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node)			\
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node)			\
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
 #ifndef CONFIG_KGDB
-#define free_thread_info(ti)	kfree((ti))
-#else
-extern void free_thread_info(struct thread_info *);
+void arch_release_thread_info(struct thread_info *ti)
 #endif
 #define get_thread_info(ti)	get_task_struct((ti)->task)
 #define put_thread_info(ti)	put_task_struct((ti)->task)
arch/mn10300/kernel/kgdb.c +1 -2
Index: tip/arch/mn10300/kernel/kgdb.c
===================================================================
@@ -397,7 +397,7 @@ static bool kgdb_arch_undo_singlestep(st
  * single-step state is cleared.  At this point the breakpoints should have
  * been removed by __switch_to().
  */
-void free_thread_info(struct thread_info *ti)
+void arch_release_thread_info(struct thread_info *ti)
 {
 	if (kgdb_sstep_thread == ti) {
 		kgdb_sstep_thread = NULL;
@@ -407,7 +407,6 @@ void free_thread_info(struct thread_info
 		 * so force immediate reentry */
 		kgdb_breakpoint();
 	}
-	kfree(ti);
 }
 
 /*
#34 lore raw

[tip:smp/hotplug] mn10300: Use common threadinfo allocator

Commit-ID:  c03a6a7ba6f456663e4b254cdde460b24c0852e1
Gitweb:     http://git.kernel.org/tip/c03a6a7ba6f456663e4b254cdde460b24c0852e1
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:45 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:45 +0200

mn10300: Use common threadinfo allocator

Let the core code allocate and handle the kgdb cleanup with the arch_release_thread_info() function.

---
 arch/mn10300/include/asm/thread_info.h |   17 +++--------------
 arch/mn10300/kernel/kgdb.c             |    3 +--
 2 files changed, 4 insertions(+), 16 deletions(-)
arch/mn10300/include/asm/thread_info.h +3 -14
index 28cf521..08251d6 100644
@@ -20,8 +20,10 @@
 
 #ifdef CONFIG_4KSTACKS
 #define THREAD_SIZE		(4096)
+#define THREAD_SIZE_ORDER	(0)
 #else
 #define THREAD_SIZE		(8192)
+#define THREAD_SIZE_ORDER	(1)
 #endif
 
 #define STACK_WARN		(THREAD_SIZE / 8)
@@ -120,21 +122,8 @@ static inline unsigned long current_stack_pointer(void)
 	return sp;
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info_node(tsk, node)			\
-		kzalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#else
-#define alloc_thread_info_node(tsk, node)			\
-		kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#endif
-
 #ifndef CONFIG_KGDB
-#define free_thread_info(ti)	kfree((ti))
-#else
-extern void free_thread_info(struct thread_info *);
+void arch_release_thread_info(struct thread_info *ti)
 #endif
 #define get_thread_info(ti)	get_task_struct((ti)->task)
 #define put_thread_info(ti)	put_task_struct((ti)->task)
arch/mn10300/kernel/kgdb.c +1 -2
index f6c981d..9977082 100644
@@ -397,7 +397,7 @@ static bool kgdb_arch_undo_singlestep(struct pt_regs *regs)
  * single-step state is cleared.  At this point the breakpoints should have
  * been removed by __switch_to().
  */
-void free_thread_info(struct thread_info *ti)
+void arch_release_thread_info(struct thread_info *ti)
 {
 	if (kgdb_sstep_thread == ti) {
 		kgdb_sstep_thread = NULL;
@@ -407,7 +407,6 @@ void free_thread_info(struct thread_info *ti)
 		 * so force immediate reentry */
 		kgdb_breakpoint();
 	}
-	kfree(ti);
 }
 
 /*
#35 lore raw

PATCH 13/18 powerpc: Use common threadinfo allocator

In reply to Thomas Gleixner

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

Cc Benjamin Herrenschmidt <[email protected]>
---
 arch/powerpc/include/asm/thread_info.h |   13 -------------
 arch/powerpc/kernel/process.c          |   31 -------------------------------
 2 files changed, 44 deletions(-)
arch/powerpc/include/asm/thread_info.h +0 -13
Index: tip/arch/powerpc/include/asm/thread_info.h
===================================================================
@@ -62,21 +62,8 @@ struct thread_info {
 #define init_thread_info	(init_thread_union.thread_info)
 #define init_stack		(init_thread_union.stack)
 
-/* thread information allocation */
-
-#if THREAD_SHIFT >= PAGE_SHIFT
-
 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
 
-#else /* THREAD_SHIFT < PAGE_SHIFT */
-
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
-extern void free_thread_info(struct thread_info *ti);
-
-#endif /* THREAD_SHIFT < PAGE_SHIFT */
-
 /* how to get the thread information struct from C */
 static inline struct thread_info *current_thread_info(void)
 {
arch/powerpc/kernel/process.c +0 -31
Index: tip/arch/powerpc/kernel/process.c
===================================================================
@@ -1252,37 +1252,6 @@ void __ppc64_runlatch_off(void)
 }
 #endif /* CONFIG_PPC64 */
 
-#if THREAD_SHIFT < PAGE_SHIFT
-
-static struct kmem_cache *thread_info_cache;
-
-struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
-{
-	struct thread_info *ti;
-
-	ti = kmem_cache_alloc_node(thread_info_cache, GFP_KERNEL, node);
-	if (unlikely(ti == NULL))
-		return NULL;
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	memset(ti, 0, THREAD_SIZE);
-#endif
-	return ti;
-}
-
-void free_thread_info(struct thread_info *ti)
-{
-	kmem_cache_free(thread_info_cache, ti);
-}
-
-void thread_info_cache_init(void)
-{
-	thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
-					      THREAD_SIZE, 0, NULL);
-	BUG_ON(thread_info_cache == NULL);
-}
-
-#endif /* THREAD_SHIFT < PAGE_SHIFT */
-
 unsigned long arch_align_stack(unsigned long sp)
 {
 	if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
#36 lore raw

[tip:smp/hotplug] powerpc: Use common threadinfo allocator

Commit-ID:  96c951179736eb59c5f66de2ac85af9e7a6a8b15
Gitweb:     http://git.kernel.org/tip/96c951179736eb59c5f66de2ac85af9e7a6a8b15
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:45 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:45 +0200

powerpc: Use common threadinfo allocator

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

---
 arch/powerpc/include/asm/thread_info.h |   13 -------------
 arch/powerpc/kernel/process.c          |   31 -------------------------------
 2 files changed, 0 insertions(+), 44 deletions(-)
arch/powerpc/include/asm/thread_info.h +0 -13
index 4a741c7..1a1bb00 100644
@@ -62,21 +62,8 @@ struct thread_info {
 #define init_thread_info	(init_thread_union.thread_info)
 #define init_stack		(init_thread_union.stack)
 
-/* thread information allocation */
-
-#if THREAD_SHIFT >= PAGE_SHIFT
-
 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
 
-#else /* THREAD_SHIFT < PAGE_SHIFT */
-
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
-extern void free_thread_info(struct thread_info *ti);
-
-#endif /* THREAD_SHIFT < PAGE_SHIFT */
-
 /* how to get the thread information struct from C */
 static inline struct thread_info *current_thread_info(void)
 {
arch/powerpc/kernel/process.c +0 -31
index 4937c96..aa05935 100644
@@ -1252,37 +1252,6 @@ void __ppc64_runlatch_off(void)
 }
 #endif /* CONFIG_PPC64 */
 
-#if THREAD_SHIFT < PAGE_SHIFT
-
-static struct kmem_cache *thread_info_cache;
-
-struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
-{
-	struct thread_info *ti;
-
-	ti = kmem_cache_alloc_node(thread_info_cache, GFP_KERNEL, node);
-	if (unlikely(ti == NULL))
-		return NULL;
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	memset(ti, 0, THREAD_SIZE);
-#endif
-	return ti;
-}
-
-void free_thread_info(struct thread_info *ti)
-{
-	kmem_cache_free(thread_info_cache, ti);
-}
-
-void thread_info_cache_init(void)
-{
-	thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
-					      THREAD_SIZE, 0, NULL);
-	BUG_ON(thread_info_cache == NULL);
-}
-
-#endif /* THREAD_SHIFT < PAGE_SHIFT */
-
 unsigned long arch_align_stack(unsigned long sp)
 {
 	if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
#37 lore raw

PATCH 14/18 score: Use common threadinfo allocator

In reply to Thomas Gleixner

No point in using kmalloc for allocating 2 pages.

---
 arch/score/include/asm/thread_info.h |   10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
arch/score/include/asm/thread_info.h +3 -7
Index: tip/arch/score/include/asm/thread_info.h
===================================================================
@@ -11,10 +11,9 @@
 #include <linux/const.h>
 
 /* thread information allocation */
-#define THREAD_SIZE_ORDER 	(1)
-#define THREAD_SIZE 		(PAGE_SIZE << THREAD_SIZE_ORDER)
-#define THREAD_MASK 		(THREAD_SIZE - _AC(1,UL))
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
+#define THREAD_SIZE_ORDER	(1)
+#define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
+#define THREAD_MASK		(THREAD_SIZE - _AC(1,UL))
 
 #ifndef __ASSEMBLY__
 
@@ -71,9 +70,6 @@ struct thread_info {
 register struct thread_info *__current_thread_info __asm__("r28");
 #define current_thread_info()	__current_thread_info
 
-#define alloc_thread_info_node(tsk, node) kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#define free_thread_info(info) kfree(info)
-
 #endif /* !__ASSEMBLY__ */
 
 #define PREEMPT_ACTIVE		0x10000000
#38 lore raw

[tip:smp/hotplug] score: Use common threadinfo allocator

Commit-ID:  c4e26890ff4cb4e85969b1e8565af4b046ce03b8
Gitweb:     http://git.kernel.org/tip/c4e26890ff4cb4e85969b1e8565af4b046ce03b8
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:46 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:46 +0200

score: Use common threadinfo allocator

No point in using kmalloc for allocating 2 pages.

---
 arch/score/include/asm/thread_info.h |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
arch/score/include/asm/thread_info.h +3 -7
index 2205c62..a18006e9 100644
@@ -11,10 +11,9 @@
 #include <linux/const.h>
 
 /* thread information allocation */
-#define THREAD_SIZE_ORDER 	(1)
-#define THREAD_SIZE 		(PAGE_SIZE << THREAD_SIZE_ORDER)
-#define THREAD_MASK 		(THREAD_SIZE - _AC(1,UL))
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
+#define THREAD_SIZE_ORDER	(1)
+#define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
+#define THREAD_MASK		(THREAD_SIZE - _AC(1,UL))
 
 #ifndef __ASSEMBLY__
 
@@ -71,9 +70,6 @@ struct thread_info {
 register struct thread_info *__current_thread_info __asm__("r28");
 #define current_thread_info()	__current_thread_info
 
-#define alloc_thread_info_node(tsk, node) kmalloc_node(THREAD_SIZE, GFP_KERNEL, node)
-#define free_thread_info(info) kfree(info)
-
 #endif /* !__ASSEMBLY__ */
 
 #define PREEMPT_ACTIVE		0x10000000
#39 lore raw

PATCH 15/18 sh: Use common threadinfo allocator

In reply to Thomas Gleixner

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

Deal with the xstate cleanup in the new arch_release_task_struct() function.

---
 arch/sh/include/asm/thread_info.h |   10 --------
 arch/sh/kernel/process.c          |   46 +-------------------------------------
 2 files changed, 3 insertions(+), 53 deletions(-)
arch/sh/include/asm/thread_info.h +1 -9
Index: tip/arch/sh/include/asm/thread_info.h
===================================================================
@@ -88,21 +88,13 @@ static inline struct thread_info *curren
 	return ti;
 }
 
-/* thread information allocation */
-#if THREAD_SHIFT >= PAGE_SHIFT
-
 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
 
-#endif
-
-extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
-extern void free_thread_info(struct thread_info *ti);
 extern void arch_task_cache_init(void);
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
+extern void arch_release_task_struct(struct task_struct *tsk);
 extern void init_thread_xstate(void);
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 #endif /* __ASSEMBLY__ */
 
 /*
arch/sh/kernel/process.c +2 -44

54 lines not on this page · raw message

#40 lore raw

[tip:smp/hotplug] sh-use-common-threadinfo-allocator

Commit-ID:  df9a7b9b5d1a5ef8cd3474d0cea2c6428542e288
Gitweb:     http://git.kernel.org/tip/df9a7b9b5d1a5ef8cd3474d0cea2c6428542e288
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:46 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:45 +0200

sh-use-common-threadinfo-allocator

The core now has a threadinfo allocator which uses a kmemcache when THREAD_SIZE < PAGE_SIZE.

Deal with the xstate cleanup in the new arch_release_task_struct() function.

---
 arch/sh/include/asm/thread_info.h |   10 +-------
 arch/sh/kernel/process.c          |   46 +-----------------------------------
 2 files changed, 3 insertions(+), 53 deletions(-)
arch/sh/include/asm/thread_info.h +1 -9
index 09963d4..b690206 100644
@@ -88,21 +88,13 @@ static inline struct thread_info *current_thread_info(void)
 	return ti;
 }
 
-/* thread information allocation */
-#if THREAD_SHIFT >= PAGE_SHIFT
-
 #define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
 
-#endif
-
-extern struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node);
-extern void free_thread_info(struct thread_info *ti);
 extern void arch_task_cache_init(void);
 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
+extern void arch_release_task_struct(struct task_struct *tsk);
 extern void init_thread_xstate(void);
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 #endif /* __ASSEMBLY__ */
 
 /*
arch/sh/kernel/process.c +2 -44

54 lines not on this page · raw message

#41 lore raw

PATCH 16/18 sparc: Use common threadinfo allocator

In reply to Thomas Gleixner

Exaclty the same as the core code.

Cc "David S. Miller" <[email protected]>
---
 arch/sparc/include/asm/thread_info_64.h |   25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)
arch/sparc/include/asm/thread_info_64.h +2 -23
Index: tip/arch/sparc/include/asm/thread_info_64.h
===================================================================
@@ -138,32 +138,11 @@ register struct thread_info *current_thr
 
 /* thread information allocation */
 #if PAGE_SHIFT == 13
-#define __THREAD_INFO_ORDER	1
+#define THREAD_SIZE_ORDER	1
 #else /* PAGE_SHIFT == 13 */
-#define __THREAD_INFO_ORDER	0
+#define THREAD_SIZE_ORDER	0
 #endif /* PAGE_SHIFT == 13 */
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_ZERO)
-#else
-#define THREAD_FLAGS (GFP_KERNEL)
-#endif
-
-#define alloc_thread_info_node(tsk, node)				\
-({									\
-	struct page *page = alloc_pages_node(node, THREAD_FLAGS,	\
-					     __THREAD_INFO_ORDER);	\
-	struct thread_info *ret;					\
-									\
-	ret = page ? page_address(page) : NULL;				\
-	ret;								\
-})
-
-#define free_thread_info(ti) \
-	free_pages((unsigned long)(ti),__THREAD_INFO_ORDER)
-
 #define __thread_flag_byte_ptr(ti)	\
 	((unsigned char *)(&((ti)->flags)))
 #define __cur_thread_flag_byte_ptr	__thread_flag_byte_ptr(current_thread_info())
#43 lore raw

[tip:smp/hotplug] sparc: Use common threadinfo allocator

In reply to Thomas Gleixner
Commit-ID:  66bb4cda55477efeb1be5c2cbd3785a69b088a8a
Gitweb:     http://git.kernel.org/tip/66bb4cda55477efeb1be5c2cbd3785a69b088a8a
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:47 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:46 +0200

sparc: Use common threadinfo allocator

Exaclty the same as the core code.

---
 arch/sparc/include/asm/thread_info_64.h |   25 ++-----------------------
 1 files changed, 2 insertions(+), 23 deletions(-)
arch/sparc/include/asm/thread_info_64.h +2 -23
index 01d057f..7f0981b 100644
@@ -138,32 +138,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
 
 /* thread information allocation */
 #if PAGE_SHIFT == 13
-#define __THREAD_INFO_ORDER	1
+#define THREAD_SIZE_ORDER	1
 #else /* PAGE_SHIFT == 13 */
-#define __THREAD_INFO_ORDER	0
+#define THREAD_SIZE_ORDER	0
 #endif /* PAGE_SHIFT == 13 */
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_ZERO)
-#else
-#define THREAD_FLAGS (GFP_KERNEL)
-#endif
-
-#define alloc_thread_info_node(tsk, node)				\
-({									\
-	struct page *page = alloc_pages_node(node, THREAD_FLAGS,	\
-					     __THREAD_INFO_ORDER);	\
-	struct thread_info *ret;					\
-									\
-	ret = page ? page_address(page) : NULL;				\
-	ret;								\
-})
-
-#define free_thread_info(ti) \
-	free_pages((unsigned long)(ti),__THREAD_INFO_ORDER)
-
 #define __thread_flag_byte_ptr(ti)	\
 	((unsigned char *)(&((ti)->flags)))
 #define __cur_thread_flag_byte_ptr	__thread_flag_byte_ptr(current_thread_info())
#44 lore raw

PATCH 17/18 tile: Use common threadinfo allocator

In reply to Thomas Gleixner

Use the core allocator and deal with the extra cleanup in arch_release_thread_info().

---
 arch/tile/include/asm/thread_info.h |    6 ++----
 arch/tile/kernel/process.c          |   23 ++---------------------
 2 files changed, 4 insertions(+), 25 deletions(-)
arch/tile/include/asm/thread_info.h +2 -4
Index: tip/arch/tile/include/asm/thread_info.h
===================================================================
@@ -77,16 +77,14 @@ struct thread_info {
 
 #ifndef __ASSEMBLY__
 
+void arch_release_thread_info(struct thread_info *info);
+
 /* How to get the thread information struct from C. */
 register unsigned long stack_pointer __asm__("sp");
 
 #define current_thread_info() \
   ((struct thread_info *)(stack_pointer & -THREAD_SIZE))
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-extern struct thread_info *alloc_thread_info_node(struct task_struct *task, int node);
-extern void free_thread_info(struct thread_info *info);
-
 /* Sit on a nap instruction until interrupted. */
 extern void smp_nap(void);
 
arch/tile/kernel/process.c +2 -21
Index: tip/arch/tile/kernel/process.c
===================================================================
@@ -114,27 +114,10 @@ void cpu_idle(void)
 	}
 }
 
-struct thread_info *alloc_thread_info_node(struct task_struct *task, int node)
-{
-	struct page *page;
-	gfp_t flags = GFP_KERNEL;
-
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	flags |= __GFP_ZERO;
-#endif
-
-	page = alloc_pages_node(node, flags, THREAD_SIZE_ORDER);
-	if (!page)
-		return NULL;
-
-	return (struct thread_info *)page_address(page);
-}
-
 /*
- * Free a thread_info node, and all of its derivative
- * data structures.
+ * Release a thread_info structure
  */
-void free_thread_info(struct thread_info *info)
+void arch_release_thread_info(struct thread_info *info)
 {
 	struct single_step_state *step_state = info->step_state;
 
@@ -169,8 +152,6 @@ void free_thread_info(struct thread_info
 		 */
 		kfree(step_state);
 	}
-
-	free_pages((unsigned long)info, THREAD_SIZE_ORDER);
 }
 
 static void save_arch_state(struct thread_struct *t);
#45 lore raw

Re: [patch 17/18] tile: Use common threadinfo allocator

Quoted 9 lines · Thomas Gleixner

Use the core allocator and deal with the extra cleanup in arch_release_thread_info().

---
 arch/tile/include/asm/thread_info.h |    6 ++----
 arch/tile/kernel/process.c          |   23 ++---------------------
 2 files changed, 4 insertions(+), 25 deletions(-)

We have some changes we haven't yet merged upstream that this will likely conflict with.

You may note that we have APIs like homecache_alloc_pages() that take a core or other magic value to indicate what the "home" cache should be on our architecture. This enables significant performance optimizations when you can co-locate the home cache with where most of the core references are coming from.

The additional changes we haven't yet merged are in the area of managing the home cache dynamically. Rather than just setting the home cache at allocation time, we allow it to be modified dynamically: for example, as the process migrates, we migrate the kernel and user stack pages. This is tricky since there are lots of coherence issues to manage, and the changes we have include a variety of changes in the core mm code to handle transitioning the home cache, proper locking, unmapping, hooks in the buddy allocator, blocking other cores while a page is transitioning, etc etc.

But, the relevance to this change is that as part of that code, we use the homecache_alloc_page() method to set the home cache of a kernel stack page to be the core that is running the thread (and then migrate the home cache dynamically after that). Using the new proposed core allocator will mean we lose that hook. We don't need a free hook (when we're using the dynamic mode we are already hooked into the allocator itself), but we do need a way to know when we're allocating a kernel stack page as opposed to any other kind of a page.

The simplest approach is of course just to allow __HAVE_ARCH_THREAD_INFO_ALLOCATOR to continue to be meaningful and use it for tile, but maybe there's some halfway point. For example, that symbol could refer only to the allocate function, and not also imply an arch-specific free function. Or, we could have a new much more focused override that was just "a function to use instead of alloc_pages_node", e.g. provide a weak alloc_threadinfo_pages_node() that just was generically just a call to alloc_pages_node, which architectures could override.

Signature · 2 lines
Chris Metcalf, Tilera Corp.
http://www.tilera.com
#46 lore raw

Re: [patch 17/18] tile: Use common threadinfo allocator

Quoted 29 lines · Chris Metcalf
Quoted 9 lines · Thomas Gleixner

Use the core allocator and deal with the extra cleanup in arch_release_thread_info().

---
 arch/tile/include/asm/thread_info.h |    6 ++----
 arch/tile/kernel/process.c          |   23 ++---------------------
 2 files changed, 4 insertions(+), 25 deletions(-)

We have some changes we haven't yet merged upstream that this will likely conflict with.

You may note that we have APIs like homecache_alloc_pages() that take a core or other magic value to indicate what the "home" cache should be on our architecture. This enables significant performance optimizations when you can co-locate the home cache with where most of the core references are coming from.

The additional changes we haven't yet merged are in the area of managing the home cache dynamically. Rather than just setting the home cache at allocation time, we allow it to be modified dynamically: for example, as the process migrates, we migrate the kernel and user stack pages. This is tricky since there are lots of coherence issues to manage, and the changes we have include a variety of changes in the core mm code to handle transitioning the home cache, proper locking, unmapping, hooks in the buddy allocator, blocking other cores while a page is transitioning, etc etc.

Quoted 8 lines

But, the relevance to this change is that as part of that code, we use the homecache_alloc_page() method to set the home cache of a kernel stack page to be the core that is running the thread (and then migrate the home cache dynamically after that). Using the new proposed core allocator will mean we lose that hook. We don't need a free hook (when we're using the dynamic mode we are already hooked into the allocator itself), but we do need a way to know when we're allocating a kernel stack page as opposed to any other kind of a page.

What's the difference between a kernel stack page for a given node and a page which is allocated on a given node ?

Quoted 8 lines

The simplest approach is of course just to allow __HAVE_ARCH_THREAD_INFO_ALLOCATOR to continue to be meaningful and use it for tile, but maybe there's some halfway point. For example, that symbol could refer only to the allocate function, and not also imply an arch-specific free function. Or, we could have a new much more focused override that was just "a function to use instead of alloc_pages_node", e.g. provide a weak alloc_threadinfo_pages_node() that just was generically just a call to alloc_pages_node, which architectures could override.

Again, that would give you what?

If you treat kernel stack pages different to general pages allocated on a node then why not using a special GFP flag for that purpose?

Thanks,

tglx

#47 lore raw

Re: [patch 17/18] tile: Use common threadinfo allocator

Quoted 38 lines · Thomas Gleixner
Quoted 28 lines · Chris Metcalf
Quoted 9 lines · Thomas Gleixner

Use the core allocator and deal with the extra cleanup in arch_release_thread_info().

---
 arch/tile/include/asm/thread_info.h |    6 ++----
 arch/tile/kernel/process.c          |   23 ++---------------------
 2 files changed, 4 insertions(+), 25 deletions(-)

We have some changes we haven't yet merged upstream that this will likely conflict with.

You may note that we have APIs like homecache_alloc_pages() that take a core or other magic value to indicate what the "home" cache should be on our architecture. This enables significant performance optimizations when you can co-locate the home cache with where most of the core references are coming from.

The additional changes we haven't yet merged are in the area of managing the home cache dynamically. Rather than just setting the home cache at allocation time, we allow it to be modified dynamically: for example, as the process migrates, we migrate the kernel and user stack pages. This is tricky since there are lots of coherence issues to manage, and the changes we have include a variety of changes in the core mm code to handle transitioning the home cache, proper locking, unmapping, hooks in the buddy allocator, blocking other cores while a page is transitioning, etc etc.

Quoted 8 lines

But, the relevance to this change is that as part of that code, we use the homecache_alloc_page() method to set the home cache of a kernel stack page to be the core that is running the thread (and then migrate the home cache dynamically after that). Using the new proposed core allocator will mean we lose that hook. We don't need a free hook (when we're using the dynamic mode we are already hooked into the allocator itself), but we do need a way to know when we're allocating a kernel stack page as opposed to any other kind of a page.

Quoted 2 lines

What's the difference between a kernel stack page for a given node and a page which is allocated on a given node ?

No difference except in how it is allocated (and of course how it is used). The task migration code currently knows that the kernel stack should have its home cache migrated; it finds it by VA. In the absence of migration the kernel stack page is not treated differently than any other page_alloc'ed page.

Quoted 9 lines
Quoted 8 lines

The simplest approach is of course just to allow __HAVE_ARCH_THREAD_INFO_ALLOCATOR to continue to be meaningful and use it for tile, but maybe there's some halfway point. For example, that symbol could refer only to the allocate function, and not also imply an arch-specific free function. Or, we could have a new much more focused override that was just "a function to use instead of alloc_pages_node", e.g. provide a weak alloc_threadinfo_pages_node() that just was generically just a call to alloc_pages_node, which architectures could override.

Again, that would give you what?

The advantage is that when you initially allocate the stack page, you can set its home cache appropriately to be on the local cpu, where the new task is likely to run. Otherwise, you could imagine using a suitable hook for when the task starts up to migrate the page at that point, but you miss out on the opportunity to have the allocator return a suitably-cached page up front when the task is created.

Quoted 2 lines

If you treat kernel stack pages different to general pages allocated on a node then why not using a special GFP flag for that purpose?

There are certainly different possible ways to tell the allocator to allocate a page with its cache "here" vs with its cache fully-distributed (and thus less local, and less good for stack or percpu pages). We use a different approach (some per-task data structures that pass homing info to the allocator) but we could probably use GFP_ values instead. But the point is we need to be able to know to do so, and I think the only obvious way is to override something in the threadinfo allocator.

Thanks!

Signature · 2 lines
Chris Metcalf, Tilera Corp.
http://www.tilera.com
#48 lore raw

Re: [patch 17/18] tile: Use common threadinfo allocator

Quoted 30 lines · Chris Metcalf
Quoted 2 lines · Thomas Gleixner

What's the difference between a kernel stack page for a given node and a page which is allocated on a given node ?

No difference except in how it is allocated (and of course how it is used). The task migration code currently knows that the kernel stack should have its home cache migrated; it finds it by VA. In the absence of migration the kernel stack page is not treated differently than any other page_alloc'ed page.

Quoted 9 lines
Quoted 8 lines

The simplest approach is of course just to allow __HAVE_ARCH_THREAD_INFO_ALLOCATOR to continue to be meaningful and use it for tile, but maybe there's some halfway point. For example, that symbol could refer only to the allocate function, and not also imply an arch-specific free function. Or, we could have a new much more focused override that was just "a function to use instead of alloc_pages_node", e.g. provide a weak alloc_threadinfo_pages_node() that just was generically just a call to alloc_pages_node, which architectures could override.

Again, that would give you what?

The advantage is that when you initially allocate the stack page, you can set its home cache appropriately to be on the local cpu, where the new task is likely to run. Otherwise, you could imagine using a suitable hook for when the task starts up to migrate the page at that point, but you miss out on the opportunity to have the allocator return a suitably-cached page up front when the task is created.

Quoted 2 lines

If you treat kernel stack pages different to general pages allocated on a node then why not using a special GFP flag for that purpose?

Quoted 7 lines

There are certainly different possible ways to tell the allocator to allocate a page with its cache "here" vs with its cache fully-distributed (and thus less local, and less good for stack or percpu pages). We use a different approach (some per-task data structures that pass homing info to the allocator) but we could probably use GFP_ values instead. But the point is we need to be able to know to do so, and I think the only obvious way is to override something in the threadinfo allocator.

Wrong. The obvious way is to use the common code and add a special flag to it.

There is nothing wrong to add

#ifndef ARCH_THREADINFO_GFP
#define ARCH_THREADINFO_GFP (0)
#endif

and or ARCH_THREADINFO_GFP to the generic THREADINFO_GFP flags

instead of insisting on a separate allocator function for something which has no fricking reason to be arch specific (IA64 and some weird sparc crap aside)

Thanks,

tglx

#49 lore raw

Re: [patch 17/18] tile: Use common threadinfo allocator

Quoted 6 lines · Thomas Gleixner
Quoted 2 lines · Chris Metcalf

I think the only obvious
way is to override something in the threadinfo allocator.

Wrong. The obvious way is to use the common code and add a special flag to it.

Well, that's overriding something in the threadinfo allocator :-)

In all seriousness, adding an arch-specific GFP flag sounds like it should work OK for tile. Thanks!

Signature · 2 lines
Chris Metcalf, Tilera Corp.
http://www.tilera.com
#50 lore raw

Re: [patch 17/18] tile: Use common threadinfo allocator

Quoted 5 lines · Chris Metcalf
Quoted 4 lines · Thomas Gleixner
Quoted 2 lines · Chris Metcalf

I think the only obvious
way is to override something in the threadinfo allocator.

Quoted 7 lines
Quoted 2 lines

Wrong. The obvious way is to use the common code and add a special flag to it.

Well, that's overriding something in the threadinfo allocator :-)

In all seriousness, adding an arch-specific GFP flag sounds like it should work OK for tile. Thanks!

I pushed out the minimum set of patches into a separate branch, so you can base your work on that and we wont run into merge order dependencies.

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git smp/threadinfo

The patch below lets you define your extra gfp flag for tile.

Thanks,

tglx

-------->

Subject: threadinfo: Add an optional ARCH gfp flag for the threadinfo allocator

Allows architectures to add their magic gfp flags.

include/linux/thread_info.h +8 -2
@@ -55,11 +55,17 @@ extern long do_no_restart_syscall(struct
 #ifdef __KERNEL__
 
 #ifdef CONFIG_DEBUG_STACK_USAGE
-# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
+# define __THREADINFO_GFP	(GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
 #else
-# define THREADINFO_GFP		(GFP_KERNEL | __GFP_NOTRACK)
+# define __THREADINFO_GFP	(GFP_KERNEL | __GFP_NOTRACK)
 #endif
 
+#ifndef ARCH_THREAD_INFO_GFP
+# define ARCH_THREAD_INFO_GFP	(0)
+#endif
+
+#define THREADINFO_GFP		(__THREADINFO_GFP | ARCH_THREAD_INFO_GFP)
+
 /*
  * flag set/clear/test wrappers
  * - pass TIF_xxxx constants to these functions
#51 lore raw

[tip:smp/hotplug] tile: Use common threadinfo allocator

In reply to Thomas Gleixner
Commit-ID:  d909a81b198a397593495508c4a5755fe95552fb
Gitweb:     http://git.kernel.org/tip/d909a81b198a397593495508c4a5755fe95552fb
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:47 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 13:55:20 +0200

tile: Use common threadinfo allocator

Use the core allocator and deal with the extra cleanup in arch_release_thread_info().

---
 arch/tile/include/asm/thread_info.h |    6 ++----
 arch/tile/kernel/process.c          |   23 ++---------------------
 2 files changed, 4 insertions(+), 25 deletions(-)
arch/tile/include/asm/thread_info.h +2 -4
index bc4f562..c1cf8a8 100644
@@ -77,16 +77,14 @@ struct thread_info {
 
 #ifndef __ASSEMBLY__
 
+void arch_release_thread_info(struct thread_info *info);
+
 /* How to get the thread information struct from C. */
 register unsigned long stack_pointer __asm__("sp");
 
 #define current_thread_info() \
   ((struct thread_info *)(stack_pointer & -THREAD_SIZE))
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-extern struct thread_info *alloc_thread_info_node(struct task_struct *task, int node);
-extern void free_thread_info(struct thread_info *info);
-
 /* Sit on a nap instruction until interrupted. */
 extern void smp_nap(void);
 
arch/tile/kernel/process.c +2 -21
index 2d5ef61..efb9833 100644
@@ -114,27 +114,10 @@ void cpu_idle(void)
 	}
 }
 
-struct thread_info *alloc_thread_info_node(struct task_struct *task, int node)
-{
-	struct page *page;
-	gfp_t flags = GFP_KERNEL;
-
-#ifdef CONFIG_DEBUG_STACK_USAGE
-	flags |= __GFP_ZERO;
-#endif
-
-	page = alloc_pages_node(node, flags, THREAD_SIZE_ORDER);
-	if (!page)
-		return NULL;
-
-	return (struct thread_info *)page_address(page);
-}
-
 /*
- * Free a thread_info node, and all of its derivative
- * data structures.
+ * Release a thread_info structure
  */
-void free_thread_info(struct thread_info *info)
+void arch_release_thread_info(struct thread_info *info)
 {
 	struct single_step_state *step_state = info->step_state;
 
@@ -169,8 +152,6 @@ void free_thread_info(struct thread_info *info)
 		 */
 		kfree(step_state);
 	}
-
-	free_pages((unsigned long)info, THREAD_SIZE_ORDER);
 }
 
 static void save_arch_state(struct thread_struct *t);
Acked-by
#52 lore raw

Re: [tip:smp/hotplug] tile: Use common threadinfo allocator

Quoted 12 lines · tip-bot for Thomas Gleixner
Commit-ID:  d909a81b198a397593495508c4a5755fe95552fb
Gitweb:     http://git.kernel.org/tip/d909a81b198a397593495508c4a5755fe95552fb
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:47 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 13:55:20 +0200

tile: Use common threadinfo allocator

Use the core allocator and deal with the extra cleanup in arch_release_thread_info().

Quoted 7 lines
---
 arch/tile/include/asm/thread_info.h |    6 ++----
 arch/tile/kernel/process.c          |   23 ++---------------------
 2 files changed, 4 insertions(+), 25 deletions(-)
Signature · 2 lines
Chris Metcalf, Tilera Corp.
http://www.tilera.com
#53 lore raw

PATCH 18/18 task_allocator: Use config switches instead of magic defines

In reply to Thomas Gleixner

Replace __HAVE_ARCH_TASK_ALLOCATOR and __HAVE_ARCH_THREAD_ALLOCATOR with proper config switches.

---
 arch/Kconfig                            |    8 ++++++++
 arch/ia64/Kconfig                       |    2 ++
 arch/ia64/include/asm/thread_info.h     |    3 ---
 arch/sparc/Kconfig                      |    1 +
 arch/sparc/include/asm/thread_info_32.h |    2 --
 kernel/fork.c                           |    7 +++----
 6 files changed, 14 insertions(+), 9 deletions(-)
arch/Kconfig +8 -0
Index: tip/arch/Kconfig
===================================================================
@@ -152,6 +152,14 @@ config GENERIC_SMP_IDLE_THREAD
 config ARCH_INIT_TASK
        bool
 
+# Select if arch has its private alloc_task_struct() function
+config ARCH_TASK_STRUCT_ALLOCATOR
+	bool
+
+# Select if arch has its private alloc_thread_info() function
+config ARCH_THREAD_INFO_ALLOCATOR
+	bool
+
 config HAVE_REGS_AND_STACK_ACCESS_API
 	bool
 	help
arch/ia64/Kconfig +2 -0
Index: tip/arch/ia64/Kconfig
===================================================================
@@ -35,6 +35,8 @@ config IA64
 	select GENERIC_IOMAP
 	select GENERIC_SMP_IDLE_THREAD
 	select ARCH_INIT_TASK
+	select ARCH_TASK_STRUCT_ALLOCATOR
+	select ARCH_THREAD_INFO_ALLOCATOR
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/ia64/include/asm/thread_info.h +0 -3
Index: tip/arch/ia64/include/asm/thread_info.h
===================================================================
@@ -54,8 +54,6 @@ struct thread_info {
 	},					\
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 #ifndef ASM_OFFSETS_C
 /* how to get the thread information struct from C */
 #define current_thread_info()	((struct thread_info *) ((char *) current + IA64_TASK_SIZE))
@@ -84,7 +82,6 @@ struct thread_info {
 #endif
 #define end_of_stack(p) (unsigned long *)((void *)(p) + IA64_RBS_OFFSET)
 
-#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
 #define alloc_task_struct_node(node)						\
 ({										\
 	struct page *page = alloc_pages_node(node, GFP_KERNEL | __GFP_COMP,	\
arch/sparc/Kconfig +1 -0
Index: tip/arch/sparc/Kconfig
===================================================================
@@ -36,6 +36,7 @@ config SPARC32
 	def_bool !64BIT
 	select GENERIC_ATOMIC64
 	select CLZ_TAB
+	select ARCH_THREAD_INFO_ALLOCATOR
 
 config SPARC64
 	def_bool 64BIT
arch/sparc/include/asm/thread_info_32.h +0 -2
Index: tip/arch/sparc/include/asm/thread_info_32.h
===================================================================
@@ -80,8 +80,6 @@ register struct thread_info *current_thr
  */
 #define THREAD_INFO_ORDER  1
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info_node, int)
 #define alloc_thread_info_node(tsk, node) BTFIXUP_CALL(alloc_thread_info_node)(node)
 
kernel/fork.c +3 -4
Index: tip/kernel/fork.c
===================================================================
@@ -111,7 +111,7 @@ int nr_processes(void)
 	return total;
 }
 
-#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
+#ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR
 static struct kmem_cache *task_struct_cachep;
 
 static inline struct task_struct *alloc_task_struct_node(int node)
@@ -128,8 +128,7 @@ static inline void free_task_struct(stru
 }
 #endif
 
-#ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
+#ifndef CONFIG_ARCH_THREAD_INFO_ALLOCATOR
 void __weak arch_release_thread_info(struct thread_info *ti) { }
 
 /*
@@ -243,7 +242,7 @@ void __init __weak arch_task_cache_init(
 
 void __init fork_init(unsigned long mempages)
 {
-#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
+#ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR
 #ifndef ARCH_MIN_TASKALIGN
 #define ARCH_MIN_TASKALIGN	L1_CACHE_BYTES
 #endif
#54 lore raw

Re: [patch 18/18] task_allocator: Use config switches instead of magic defines

Quoted 12 lines · Thomas Gleixner

Replace __HAVE_ARCH_TASK_ALLOCATOR and __HAVE_ARCH_THREAD_ALLOCATOR with proper config switches.

Index: tip/arch/sparc/include/asm/thread_info_32.h
===================================================================

arch/sparc/include/asm/thread_info_32.h register struct thread_info *current_thr · line 84

Quoted 7 lines
arch/sparc/include/asm/thread_info_32.h +0 -2
@@ -80,8 +80,6 @@ register struct thread_info *current_thr
  */
 #define THREAD_INFO_ORDER  1
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info_node, int)
 #define alloc_thread_info_node(tsk, node) BTFIXUP_CALL(alloc_thread_info_node)(node)

On the sparc mailing list we have discussed to drop support for sun4c - and decided to do so. With sun4c dropped sparc32 will be able to use the generic variant too.

I will take care to introduce the generic variant when sparc32 is ready.

Sam

#55 lore raw

Re: [patch 18/18] task_allocator: Use config switches instead of magic defines

Quoted 26 lines · Sam Ravnborg
Quoted 12 lines · Thomas Gleixner

Replace __HAVE_ARCH_TASK_ALLOCATOR and __HAVE_ARCH_THREAD_ALLOCATOR with proper config switches.

Index: tip/arch/sparc/include/asm/thread_info_32.h
===================================================================

arch/sparc/include/asm/thread_info_32.h register struct thread_info *current_thr · line 84

Quoted 7 lines
arch/sparc/include/asm/thread_info_32.h +0 -2
@@ -80,8 +80,6 @@ register struct thread_info *current_thr
  */
 #define THREAD_INFO_ORDER  1
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info_node, int)
 #define alloc_thread_info_node(tsk, node) BTFIXUP_CALL(alloc_thread_info_node)(node)

On the sparc mailing list we have discussed to drop support for sun4c - and decided to do so. With sun4c dropped sparc32 will be able to use the generic variant too.

Quoted 2 lines

I will take care to introduce the generic variant when sparc32 is ready.

Nice :)

#56 lore raw

[tip:smp/hotplug] task_allocator: Use config switches instead of magic defines

In reply to Thomas Gleixner
Commit-ID:  f5e10287367dcffb5504d19c83e85ca041ca2596
Gitweb:     http://git.kernel.org/tip/f5e10287367dcffb5504d19c83e85ca041ca2596
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Sat, 5 May 2012 15:05:48 +0000
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 8 May 2012 14:08:46 +0200

task_allocator: Use config switches instead of magic defines

Replace __HAVE_ARCH_TASK_ALLOCATOR and __HAVE_ARCH_THREAD_ALLOCATOR with proper config switches.

---
 arch/Kconfig                            |    8 ++++++++
 arch/ia64/Kconfig                       |    2 ++
 arch/ia64/include/asm/thread_info.h     |    3 ---
 arch/sparc/Kconfig                      |    1 +
 arch/sparc/include/asm/thread_info_32.h |    2 --
 kernel/fork.c                           |    7 +++----
 6 files changed, 14 insertions(+), 9 deletions(-)
arch/Kconfig +8 -0
index 597b132..bd265a2 100644
@@ -152,6 +152,14 @@ config GENERIC_SMP_IDLE_THREAD
 config ARCH_INIT_TASK
        bool
 
+# Select if arch has its private alloc_task_struct() function
+config ARCH_TASK_STRUCT_ALLOCATOR
+	bool
+
+# Select if arch has its private alloc_thread_info() function
+config ARCH_THREAD_INFO_ALLOCATOR
+	bool
+
 config HAVE_REGS_AND_STACK_ACCESS_API
 	bool
 	help
arch/ia64/Kconfig +2 -0
index 022ea3a..ba667b6 100644
@@ -35,6 +35,8 @@ config IA64
 	select GENERIC_IOMAP
 	select GENERIC_SMP_IDLE_THREAD
 	select ARCH_INIT_TASK
+	select ARCH_TASK_STRUCT_ALLOCATOR
+	select ARCH_THREAD_INFO_ALLOCATOR
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/ia64/include/asm/thread_info.h +0 -3
index e054bcc..310d973 100644
@@ -54,8 +54,6 @@ struct thread_info {
 	},					\
 }
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 #ifndef ASM_OFFSETS_C
 /* how to get the thread information struct from C */
 #define current_thread_info()	((struct thread_info *) ((char *) current + IA64_TASK_SIZE))
@@ -84,7 +82,6 @@ struct thread_info {
 #endif
 #define end_of_stack(p) (unsigned long *)((void *)(p) + IA64_RBS_OFFSET)
 
-#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
 #define alloc_task_struct_node(node)						\
 ({										\
 	struct page *page = alloc_pages_node(node, GFP_KERNEL | __GFP_COMP,	\
arch/sparc/Kconfig +1 -0
index e417f35..ec0347a 100644
@@ -36,6 +36,7 @@ config SPARC32
 	def_bool !64BIT
 	select GENERIC_ATOMIC64
 	select CLZ_TAB
+	select ARCH_THREAD_INFO_ALLOCATOR
 
 config SPARC64
 	def_bool 64BIT
arch/sparc/include/asm/thread_info_32.h +0 -2
index c2a1080..b29498d 100644
@@ -80,8 +80,6 @@ register struct thread_info *current_thread_info_reg asm("g6");
  */
 #define THREAD_INFO_ORDER  1
 
-#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
 BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info_node, int)
 #define alloc_thread_info_node(tsk, node) BTFIXUP_CALL(alloc_thread_info_node)(node)
 
kernel/fork.c +3 -4
index 7590bd6..a1793e4 100644
@@ -111,7 +111,7 @@ int nr_processes(void)
 	return total;
 }
 
-#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
+#ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR
 static struct kmem_cache *task_struct_cachep;
 
 static inline struct task_struct *alloc_task_struct_node(int node)
@@ -128,8 +128,7 @@ static inline void free_task_struct(struct task_struct *tsk)
 }
 #endif
 
-#ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR
-
+#ifndef CONFIG_ARCH_THREAD_INFO_ALLOCATOR
 void __weak arch_release_thread_info(struct thread_info *ti) { }
 
 /*
@@ -243,7 +242,7 @@ void __init __weak arch_task_cache_init(void) { }
 
 void __init fork_init(unsigned long mempages)
 {
-#ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
+#ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR
 #ifndef ARCH_MIN_TASKALIGN
 #define ARCH_MIN_TASKALIGN	L1_CACHE_BYTES
 #endif