powerpc: Don't use kmalloc() for kernel stacks

David Gibson david at gibson.dropbear.id.au
Mon Oct 24 14:05:38 EST 2005


On Fri, Oct 21, 2005 at 09:53:46AM +0200, Christoph Hellwig wrote:
> On Fri, Oct 21, 2005 at 03:45:50PM +1000, David Gibson wrote:
> > 	- In readiness for 64k pages, when THREAD_SIZE will be less
> > than a page, ppc64 used kmalloc() rather than get_free_pages() to
> > allocate the kernel stack.  With this patch we do the same for ppc32,
> > since there's no strong reason not to.
> 
> This adds quite a bit of overhead and wasted memory.  Please don't do it
> for ppc32 or ppc64 with THREAD_SIZE >= PAGE_SIZE either.

Very well, the patch below addresses this.

In readiness for 64k pages, when THREAD_SIZE will be less than
PAGE_SIZE, ppc64 uses kmalloc() rather than __get_free_pages() to
allocate kernel stacks, and since thread_info.h was merged, so does
ppc32.  However that adds some overhead which we don't really want
when PAGE_SIZE <= THREAD_SIZE (including all ppc32 machines), so this
patch avoids it.

Signed-off-by: David Gibson <dwg at au1.ibm.com>

Index: working-2.6/include/asm-powerpc/thread_info.h
===================================================================
--- working-2.6.orig/include/asm-powerpc/thread_info.h	2005-10-24 10:36:28.000000000 +1000
+++ working-2.6/include/asm-powerpc/thread_info.h	2005-10-24 13:57:10.000000000 +1000
@@ -66,19 +66,26 @@
 /* thread information allocation */
 
 #ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk)					\
-	({							\
-		struct thread_info *ret;			\
-								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
-		if (ret)					\
-			memset(ret, 0, THREAD_SIZE);		\
-		ret;						\
-	})
+#define THREAD_INFO_GFP		GFP_KERNEL | __GFP_ZERO
 #else
-#define alloc_thread_info(tsk)	kmalloc(THREAD_SIZE, GFP_KERNEL)
+#define THREAD_INFO_GFP		GFP_KERNEL
 #endif
+
+#if THREAD_SHIFT >= PAGE_SHIFT
+
+#define THREAD_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
+
+#define alloc_thread_info(tsk)	\
+	((struct thread_info *)__get_free_pages(THREAD_INFO_GFP, THREAD_ORDER))
+#define free_thread_info(ti)	free_pages((unsigned long)ti, THREAD_ORDER)
+
+#else /* THREAD_SHIFT < PAGE_SHIFT */
+
+#define alloc_thread_info(tsk)	kmalloc(THREAD_SIZE, THREAD_INFO_GFP)
 #define free_thread_info(ti)	kfree(ti)
+
+#endif /* THREAD_SHIFT < PAGE_SHIFT */
+
 #define get_thread_info(ti)	get_task_struct((ti)->task)
 #define put_thread_info(ti)	put_task_struct((ti)->task)
 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/people/dgibson



More information about the Linuxppc64-dev mailing list