public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [QN/PATCH] Why do some archs allocate stack via kmalloc, others via get_free_pages?
@ 2005-07-22  4:11 Nigel Cunningham
  2005-07-22  7:50 ` David S. Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Nigel Cunningham @ 2005-07-22  4:11 UTC (permalink / raw)
  To: Linux Kernel Mailing List

Hi all.

In making some modifications to Suspend, we've discovered that some
arches use kmalloc and others use get_free_pages to allocate the stack.
Is there a reason for the variation? If not, could the following patch
be considered for inclusion (tested on x86 only).

Regards,

Nigel

 arch/frv/kernel/process.c       |    4 ++--
 include/asm-frv/thread_info.h   |   11 ++++++++---
 include/asm-i386/thread_info.h  |   11 ++++++++---
 include/asm-m32r/thread_info.h  |   10 +++++++---
 include/asm-mips/thread_info.h  |    8 +++++---
 include/asm-ppc64/thread_info.h |    9 ++++++---
 include/asm-um/thread_info.h    |    6 ++++--
 7 files changed, 40 insertions(+), 19 deletions(-)
diff -ruNp 821-make-task-struct-use-get-free-pages.patch-old/arch/frv/kernel/process.c 821-make-task-struct-use-get-free-pages.patch-new/arch/frv/kernel/process.c
--- 821-make-task-struct-use-get-free-pages.patch-old/arch/frv/kernel/process.c	2005-02-03 22:33:14.000000000 +1100
+++ 821-make-task-struct-use-get-free-pages.patch-new/arch/frv/kernel/process.c	2005-07-22 04:39:15.000000000 +1000
@@ -41,7 +41,7 @@ asmlinkage void ret_from_fork(void);
 
 struct task_struct *alloc_task_struct(void)
 {
-	struct task_struct *p = kmalloc(THREAD_SIZE, GFP_KERNEL);
+	struct task_struct *p = (struct task_struct *) __get_free_pages(GFP_KERNEL, THREAD_ORDER);
 	if (p)
 		atomic_set((atomic_t *)(p+1), 1);
 	return p;
@@ -50,7 +50,7 @@ struct task_struct *alloc_task_struct(vo
 void free_task_struct(struct task_struct *p)
 {
 	if (atomic_dec_and_test((atomic_t *)(p+1)))
-		kfree(p);
+		free_pages((unsigned long) p, THREAD_ORDER);
 }
 
 static void core_sleep_idle(void)
diff -ruNp 821-make-task-struct-use-get-free-pages.patch-old/include/asm-frv/thread_info.h 821-make-task-struct-use-get-free-pages.patch-new/include/asm-frv/thread_info.h
--- 821-make-task-struct-use-get-free-pages.patch-old/include/asm-frv/thread_info.h	2005-07-18 06:37:02.000000000 +1000
+++ 821-make-task-struct-use-get-free-pages.patch-new/include/asm-frv/thread_info.h	2005-07-22 04:52:48.000000000 +1000
@@ -89,6 +89,8 @@ struct thread_info {
 #define THREAD_SIZE		8192
 #endif
 
+#define THREAD_ORDER	(THREAD_SIZE >> PAGE_SHIFT)
+
 /* how to get the thread information struct from C */
 register struct thread_info *__current_thread_info asm("gr15");
 
@@ -100,16 +102,19 @@ register struct thread_info *__current_t
 	({							\
 		struct thread_info *ret;			\
 								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
+		ret = (struct thread_info *) 			\
+			__get_free_pages(GFP_KERNEL, 		\
+					THREAD_ORDER); 		\
 		if (ret)					\
 			memset(ret, 0, THREAD_SIZE);		\
 		ret;						\
 	})
 #else
-#define alloc_thread_info(tsk)	kmalloc(THREAD_SIZE, GFP_KERNEL)
+#define alloc_thread_info(tsk)	(struct thread_info *) \
+		__get_free_pages(GFP_KERNEL, THREAD_ORDER)
 #endif
 
-#define free_thread_info(info)	kfree(info)
+#define free_thread_info(info)	free_pages((unsigned long) info, THREAD_ORDER)
 #define get_thread_info(ti)	get_task_struct((ti)->task)
 #define put_thread_info(ti)	put_task_struct((ti)->task)
 
diff -ruNp 821-make-task-struct-use-get-free-pages.patch-old/include/asm-i386/thread_info.h 821-make-task-struct-use-get-free-pages.patch-new/include/asm-i386/thread_info.h
--- 821-make-task-struct-use-get-free-pages.patch-old/include/asm-i386/thread_info.h	2005-07-22 05:17:22.000000000 +1000
+++ 821-make-task-struct-use-get-free-pages.patch-new/include/asm-i386/thread_info.h	2005-07-22 04:58:14.000000000 +1000
@@ -55,8 +55,10 @@ struct thread_info {
 #define PREEMPT_ACTIVE		0x10000000
 #ifdef CONFIG_4KSTACKS
 #define THREAD_SIZE            (4096)
+#define THREAD_ORDER		0
 #else
 #define THREAD_SIZE		(8192)
+#define THREAD_ORDER		1
 #endif
 
 #define STACK_WARN             (THREAD_SIZE/8)
@@ -101,16 +103,19 @@ register unsigned long current_stack_poi
 	({							\
 		struct thread_info *ret;			\
 								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
+		ret = (struct thread_info *) 			\
+			__get_free_pages(GFP_KERNEL, 		\
+					THREAD_ORDER);		\
 		if (ret)					\
 			memset(ret, 0, THREAD_SIZE);		\
 		ret;						\
 	})
 #else
-#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
+#define alloc_thread_info(tsk) (struct thread_info *) \
+		__get_free_pages(GFP_KERNEL, THREAD_ORDER)
 #endif
 
-#define free_thread_info(info)	kfree(info)
+#define free_thread_info(info)	free_pages((unsigned long) info, THREAD_ORDER)
 #define get_thread_info(ti) get_task_struct((ti)->task)
 #define put_thread_info(ti) put_task_struct((ti)->task)
 
diff -ruNp 821-make-task-struct-use-get-free-pages.patch-old/include/asm-m32r/thread_info.h 821-make-task-struct-use-get-free-pages.patch-new/include/asm-m32r/thread_info.h
--- 821-make-task-struct-use-get-free-pages.patch-old/include/asm-m32r/thread_info.h	2005-07-18 06:37:03.000000000 +1000
+++ 821-make-task-struct-use-get-free-pages.patch-new/include/asm-m32r/thread_info.h	2005-07-22 05:01:51.000000000 +1000
@@ -79,6 +79,7 @@ struct thread_info {
 #define init_stack		(init_thread_union.stack)
 
 #define THREAD_SIZE (2*PAGE_SIZE)
+#define THREAD_ORDER 1
 
 /* how to get the thread information struct from C */
 static inline struct thread_info *current_thread_info(void)
@@ -100,16 +101,19 @@ static inline struct thread_info *curren
 	({							\
 		struct thread_info *ret;			\
 	 							\
-	 	ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
+	 	ret = (struct thread_info *)			\
+			__get_free_pages(GFP_KERNEL, 		\
+					THREAD_ORDER);		\
 	 	if (ret)					\
 	 		memset(ret, 0, THREAD_SIZE);		\
 	 	ret;						\
 	 })
 #else
-#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
+#define alloc_thread_info(tsk) (struct thread_info *) \
+	__get_free_pages(GFP_KERNEL, THREAD_ORDER)
 #endif
 
-#define free_thread_info(info) kfree(info)
+#define free_thread_info(info) free_pages((unsigned long) info, THREAD_ORDER)
 #define get_thread_info(ti) get_task_struct((ti)->task)
 #define put_thread_info(ti) put_task_struct((ti)->task)
 
diff -ruNp 821-make-task-struct-use-get-free-pages.patch-old/include/asm-mips/thread_info.h 821-make-task-struct-use-get-free-pages.patch-new/include/asm-mips/thread_info.h
--- 821-make-task-struct-use-get-free-pages.patch-old/include/asm-mips/thread_info.h	2005-07-18 06:37:03.000000000 +1000
+++ 821-make-task-struct-use-get-free-pages.patch-new/include/asm-mips/thread_info.h	2005-07-22 04:43:10.000000000 +1000
@@ -86,16 +86,18 @@ register struct thread_info *__current_t
 ({								\
 	struct thread_info *ret;				\
 								\
-	ret = kmalloc(THREAD_SIZE, GFP_KERNEL);			\
+	ret = (struct thread_info *)				\
+		__get_free_pages(GFP_KERNEL, THREAD_ORDER);	\
 	if (ret)						\
 		memset(ret, 0, THREAD_SIZE);			\
 	ret;							\
 })
 #else
-#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
+#define alloc_thread_info(tsk) (struct thread_info *) \
+			__get_free_pages(GFP_KERNEL, THREAD_ORDER)
 #endif
 
-#define free_thread_info(info) kfree(info)
+#define free_thread_info(info) free_pages((unsigned long) info, THREAD_ORDER)
 #define get_thread_info(ti) get_task_struct((ti)->task)
 #define put_thread_info(ti) put_task_struct((ti)->task)
 
diff -ruNp 821-make-task-struct-use-get-free-pages.patch-old/include/asm-ppc64/thread_info.h 821-make-task-struct-use-get-free-pages.patch-new/include/asm-ppc64/thread_info.h
--- 821-make-task-struct-use-get-free-pages.patch-old/include/asm-ppc64/thread_info.h	2005-07-18 06:37:03.000000000 +1000
+++ 821-make-task-struct-use-get-free-pages.patch-new/include/asm-ppc64/thread_info.h	2005-07-22 04:44:26.000000000 +1000
@@ -62,15 +62,18 @@ struct thread_info {
 	({							\
 		struct thread_info *ret;			\
 								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
+		ret = (struct thread_info *)			\
+			__get_free_pages(GFP_KERNEL, 		\
+					THREAD_ORDER);		\
 		if (ret)					\
 			memset(ret, 0, THREAD_SIZE);		\
 		ret;						\
 	})
 #else
-#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
+#define alloc_thread_info(tsk) (struct thread_info *) \
+			__get_free_pages(GFP_KERNEL, THREAD_ORDER)
 #endif
-#define free_thread_info(ti)	kfree(ti)
+#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)
 
diff -ruNp 821-make-task-struct-use-get-free-pages.patch-old/include/asm-um/thread_info.h 821-make-task-struct-use-get-free-pages.patch-new/include/asm-um/thread_info.h
--- 821-make-task-struct-use-get-free-pages.patch-old/include/asm-um/thread_info.h	2005-07-18 06:37:04.000000000 +1000
+++ 821-make-task-struct-use-get-free-pages.patch-new/include/asm-um/thread_info.h	2005-07-22 01:57:00.000000000 +1000
@@ -53,8 +53,10 @@ static inline struct thread_info *curren
 
 /* thread information allocation */
 #define alloc_thread_info(tsk) \
-	((struct thread_info *) kmalloc(THREAD_SIZE, GFP_KERNEL))
-#define free_thread_info(ti) kfree(ti)
+	((struct thread_info *) __get_free_pages(GFP_KERNEL, \
+			CONFIG_KERNEL_STACK_ORDER))
+#define free_thread_info(ti) free_pages((unsigned long) ti, \
+			CONFIG_KERNEL_STACK_ORDER)
 
 #define get_thread_info(ti) get_task_struct((ti)->task)
 #define put_thread_info(ti) put_task_struct((ti)->task)

-- 
Evolution.
Enumerate the requirements.
Consider the interdependencies.
Calculate the probabilities.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [QN/PATCH] Why do some archs allocate stack via kmalloc, others via get_free_pages?
  2005-07-22  4:11 [QN/PATCH] Why do some archs allocate stack via kmalloc, others via get_free_pages? Nigel Cunningham
@ 2005-07-22  7:50 ` David S. Miller
  2005-07-22 14:57   ` Nigel Cunningham
  0 siblings, 1 reply; 3+ messages in thread
From: David S. Miller @ 2005-07-22  7:50 UTC (permalink / raw)
  To: ncunningham; +Cc: linux-kernel

From: Nigel Cunningham <ncunningham@cyclades.com>
Date: Fri, 22 Jul 2005 14:11:17 +1000

> In making some modifications to Suspend, we've discovered that some
> arches use kmalloc and others use get_free_pages to allocate the stack.
> Is there a reason for the variation? If not, could the following patch
> be considered for inclusion (tested on x86 only).

Some platforms really need it to be page aligned (sparc32 sun4c needs
to virtually map the resulting pages into a specific place, for
example).

But, for the ones that don't have this requirement, they want the
cache coloring.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [QN/PATCH] Why do some archs allocate stack via kmalloc, others via get_free_pages?
  2005-07-22  7:50 ` David S. Miller
@ 2005-07-22 14:57   ` Nigel Cunningham
  0 siblings, 0 replies; 3+ messages in thread
From: Nigel Cunningham @ 2005-07-22 14:57 UTC (permalink / raw)
  To: David S. Miller; +Cc: Linux Kernel Mailing List

Hi.

On Fri, 2005-07-22 at 17:50, David S. Miller wrote:
> From: Nigel Cunningham <ncunningham@cyclades.com>
> Date: Fri, 22 Jul 2005 14:11:17 +1000
> 
> > In making some modifications to Suspend, we've discovered that some
> > arches use kmalloc and others use get_free_pages to allocate the stack.
> > Is there a reason for the variation? If not, could the following patch
> > be considered for inclusion (tested on x86 only).
> 
> Some platforms really need it to be page aligned (sparc32 sun4c needs
> to virtually map the resulting pages into a specific place, for
> example).
> 
> But, for the ones that don't have this requirement, they want the
> cache coloring.

Thanks David.

Nigel

-- 
Evolution.
Enumerate the requirements.
Consider the interdependencies.
Calculate the probabilities.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-23  3:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-22  4:11 [QN/PATCH] Why do some archs allocate stack via kmalloc, others via get_free_pages? Nigel Cunningham
2005-07-22  7:50 ` David S. Miller
2005-07-22 14:57   ` Nigel Cunningham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox