Skip to contentSkip to conversation

X86_64 configurable stack size

PATCH In review [email protected] 4 participants 14 messages Nov 7, 2007 – Nov 10, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover X86_64 configurable stack size

These two patches the configuration of the stack size on x86_64.

Prior discussion on these (this version does not provide a fallback):

http://marc.info/?l=linux-mm&m=119147073128193&w=2
http://marc.info/?l=linux-mm&m=119147072506052&w=2

Signature · 5 lines
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/2 x86_64: Clean up stack allocation and free

Cleanup the allocation and freeing of stacks a bit by using a __GFP_ZERO flag instead of memset.

---
 include/asm-x86/thread_info_64.h |   16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
include/asm-x86/thread_info_64.h +5 -11
Index: linux-2.6/include/asm-x86/thread_info_64.h
===================================================================
@@ -74,20 +74,14 @@ static inline struct thread_info *stack_
 
 /* thread information allocation */
 #ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk)					\
-    ({								\
-	struct thread_info *ret;				\
-								\
-	ret = ((struct thread_info *) __get_free_pages(GFP_KERNEL,THREAD_ORDER)); \
-	if (ret)						\
-		memset(ret, 0, THREAD_SIZE);			\
-	ret;							\
-    })
+#define THREAD_FLAGS (GFP_KERNEL | __GFP_ZERO)
 #else
-#define alloc_thread_info(tsk) \
-	((struct thread_info *) __get_free_pages(GFP_KERNEL,THREAD_ORDER))
+#define THREAD_FLAGS GFP_KERNEL
 #endif
 
+#define alloc_thread_info(tsk) \
+	((struct thread_info *) __get_free_pages(THREAD_FLAGS, THREAD_ORDER))
+
 #define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_ORDER)
 
 #else /* !__ASSEMBLY__ */
Signature · 5 lines
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/2
#2 lore raw

Re: [patch 1/2] x86_64: Clean up stack allocation and free

Quoted 31 lines · On Tue, Nov 06, 2007 at 04:43:58PM -0800, [email protected] wrote:

Cleanup the allocation and freeing of stacks a bit by using a __GFP_ZERO flag instead of memset.

---
 include/asm-x86/thread_info_64.h |   16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

Index: linux-2.6/include/asm-x86/thread_info_64.h
===================================================================

include/asm-x86/thread_info_64.h +1 -10
@@ -74,20 +74,14 @@ static inline struct thread_info *stack_
 
 /* thread information allocation */
 #ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk)					\
-    ({								\
-	struct thread_info *ret;				\
-								\
-	ret = ((struct thread_info *) __get_free_pages(GFP_KERNEL,THREAD_ORDER)); \
-	if (ret)						\
-		memset(ret, 0, THREAD_SIZE);			\
-	ret;							\
-    })
+#define THREAD_FLAGS (GFP_KERNEL | __GFP_ZERO)
 #else
-#define alloc_thread_info(tsk) \

include/asm-x86/thread_info_64.h static inline struct thread_info *stack_ · line 87

Quoted 10 lines
include/asm-x86/thread_info_64.h +4 -1
-	((struct thread_info *) __get_free_pages(GFP_KERNEL,THREAD_ORDER))
+#define THREAD_FLAGS GFP_KERNEL
 #endif
 
+#define alloc_thread_info(tsk) \
+	((struct thread_info *) __get_free_pages(THREAD_FLAGS, THREAD_ORDER))
+
 #define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_ORDER)
 
 #else /* !__ASSEMBLY__ */

This seems wholy reasonable. And brings the code much closer to the x86 32bit version.

-apw

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

PATCH 2/2 x86_64: Configure stack size

In reply to [email protected]

Make the stack size configurable necessary. SGI NUMA configurations may need more stack because cpumasks and nodemasks are at times kept on the stack. This patch allows to run with 16k or 32k kernel stacks.

---
 arch/x86/Kconfig.x86_64          |    6 ++++++
 include/asm-x86/page_64.h        |    3 +--
 include/asm-x86/thread_info_64.h |    4 ++--
 3 files changed, 9 insertions(+), 4 deletions(-)
arch/x86/Kconfig.x86_64 +6 -0
Index: linux-2.6/arch/x86/Kconfig.x86_64
===================================================================
@@ -378,6 +378,12 @@ config NODES_SHIFT
 	default "6"
 	depends on NEED_MULTIPLE_NODES
 
+config THREAD_ORDER
+	int "Kernel stack size (in page order)"
+	default "1"
+	help
+	  Page order for the thread stack.
+
 # Dummy CONFIG option to select ACPI_NUMA from drivers/acpi/Kconfig.
 
 config X86_64_ACPI_NUMA
include/asm-x86/page_64.h +1 -2
Index: linux-2.6/include/asm-x86/page_64.h
===================================================================
@@ -9,8 +9,7 @@
 #define PAGE_MASK	(~(PAGE_SIZE-1))
 #define PHYSICAL_PAGE_MASK	(~(PAGE_SIZE-1) & __PHYSICAL_MASK)
 
-#define THREAD_ORDER 1 
-#define THREAD_SIZE  (PAGE_SIZE << THREAD_ORDER)
+#define THREAD_SIZE  (PAGE_SIZE << CONFIG_THREAD_ORDER)
 #define CURRENT_MASK (~(THREAD_SIZE-1))
 
 #define EXCEPTION_STACK_ORDER 0
include/asm-x86/thread_info_64.h +2 -2
Index: linux-2.6/include/asm-x86/thread_info_64.h
===================================================================
@@ -80,9 +80,9 @@ static inline struct thread_info *stack_
 #endif
 
 #define alloc_thread_info(tsk) \
-	((struct thread_info *) __get_free_pages(THREAD_FLAGS, THREAD_ORDER))
+	((struct thread_info *) __get_free_pages(THREAD_FLAGS, CONFIG_THREAD_ORDER))
 
-#define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_ORDER)
+#define free_thread_info(ti) free_pages((unsigned long) (ti), CONFIG_THREAD_ORDER)
 
 #else /* !__ASSEMBLY__ */
 
Signature · 5 lines
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 2/2
#4 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 50 lines · On Tue, Nov 06, 2007 at 04:43:59PM -0800, [email protected] wrote:

Make the stack size configurable necessary. SGI NUMA configurations may need more stack because cpumasks and nodemasks are at times kept on the stack. This patch allows to run with 16k or 32k kernel stacks.

---
 arch/x86/Kconfig.x86_64          |    6 ++++++
 include/asm-x86/page_64.h        |    3 +--
 include/asm-x86/thread_info_64.h |    4 ++--
 3 files changed, 9 insertions(+), 4 deletions(-)

Index: linux-2.6/arch/x86/Kconfig.x86_64
===================================================================

arch/x86/Kconfig.x86_64 +6 -0
@@ -378,6 +378,12 @@ config NODES_SHIFT
 	default "6"
 	depends on NEED_MULTIPLE_NODES
 
+config THREAD_ORDER
+	int "Kernel stack size (in page order)"
+	default "1"
+	help
+	  Page order for the thread stack.
+
 # Dummy CONFIG option to select ACPI_NUMA from drivers/acpi/Kconfig.
 
 config X86_64_ACPI_NUMA

Index: linux-2.6/include/asm-x86/page_64.h
===================================================================

include/asm-x86/page_64.h +1 -2
@@ -9,8 +9,7 @@
 #define PAGE_MASK	(~(PAGE_SIZE-1))
 #define PHYSICAL_PAGE_MASK	(~(PAGE_SIZE-1) & __PHYSICAL_MASK)
 
-#define THREAD_ORDER 1 
-#define THREAD_SIZE  (PAGE_SIZE << THREAD_ORDER)
+#define THREAD_SIZE  (PAGE_SIZE << CONFIG_THREAD_ORDER)
 #define CURRENT_MASK (~(THREAD_SIZE-1))
 
 #define EXCEPTION_STACK_ORDER 0

Index: linux-2.6/include/asm-x86/thread_info_64.h
===================================================================

include/asm-x86/thread_info_64.h static inline struct thread_info *stack_ · line 87

Quoted 10 lines
include/asm-x86/thread_info_64.h +2 -2
@@ -80,9 +80,9 @@ static inline struct thread_info *stack_
 #endif
 
 #define alloc_thread_info(tsk) \
-	((struct thread_info *) __get_free_pages(THREAD_FLAGS, THREAD_ORDER))
+	((struct thread_info *) __get_free_pages(THREAD_FLAGS, CONFIG_THREAD_ORDER))
 
-#define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_ORDER)
+#define free_thread_info(ti) free_pages((unsigned long) (ti), CONFIG_THREAD_ORDER)
 
 #else /* !__ASSEMBLY__ */

We seem to be growing two different mechanisms here for 32bit and 64bit. This does seem a better option than that in 32bit CONFIG_4KSTACKS etc. IMO when these two merge we should consolidate on this version.

-apw

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 3 lines

We seem to be growing two different mechanisms here for 32bit and 64bit. This does seem a better option than that in 32bit CONFIG_4KSTACKS etc. IMO when these two merge we should consolidate on this version.

Best would be to not change it at all for 64bit for now.

We can worry about the 16k CPU systems when they appear, but shorter term it would just lead to other crappy kernel code relying on large stacks when it shouldn't.

-Andi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 10 lines · Andi Kleen
Quoted 4 lines

We seem to be growing two different mechanisms here for 32bit and 64bit. This does seem a better option than that in 32bit CONFIG_4KSTACKS etc. IMO when these two merge we should consolidate on this version.

Best would be to not change it at all for 64bit for now.

We can worry about the 16k CPU systems when they appear, but shorter term it would just lead to other crappy kernel code relying on large stacks when it shouldn't.

Well we cannot really test these systems without these patches and when they become officially available then its too late for merging.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#7 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 7 lines · On Wed, 7 Nov 2007 16:42:04 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 5 lines · Andi Kleen
Quoted 4 lines

We seem to be growing two different mechanisms here for 32bit and 64bit. This does seem a better option than that in 32bit CONFIG_4KSTACKS etc. IMO when these two merge we should consolidate on this version.

Quoted 8 lines
Quoted 5 lines

Best would be to not change it at all for 64bit for now.

We can worry about the 16k CPU systems when they appear, but shorter term it would just lead to other crappy kernel code relying on large stacks when it shouldn't.

Well we cannot really test these systems without these patches and when they become officially available then its too late for merging.

It doesn't take many 2kb cpumasks to use up a lot of stack.

What else can we do? Change all sites to do some dynamic allocation if (NR_CPUS >= lots), I guess.

As for timing: we might as well merge it now so that 2.6.25 has at least a chance of running on 16384-way.

otoh, I doubt if anyone will actually ship an NR_CPUS=16384 kernel, so it isn't terribly pointful.

So I'm wobbly. Could we please examine the alternatives before proceeding? Is there any plan in anyone's mind to fix this problem in a better but probably more intrusive fashion?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 2 lines · Andrew Morton

otoh, I doubt if anyone will actually ship an NR_CPUS=16384 kernel, so it isn't terribly pointful.

Our competition (Cray) just announced a product featuring up to 21k cpus although that is a cluster. We are definitely getting there...

Quoted 1 line

So I'm wobbly. Could we please examine the alternatives before proceeding?

This works fine with a 32k stack on IA64 with 4k processors. So I tend to think of this as a solution that is already working on another platform. An 8k stack is also going to be tough with 4k processors on x86_64 which we will have soon.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#9 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 7 lines · On Fri, 9 Nov 2007 12:45:06 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 2 lines · Andrew Morton

otoh, I doubt if anyone will actually ship an NR_CPUS=16384 kernel, so it isn't terribly pointful.

Our competition (Cray) just announced a product featuring up to 21k cpus although that is a cluster. We are definitely getting there...

I'm talking about software, not hardware. I'd expect that you'll have trouble talking RH/suse/etc into general shipping of an NR_CPUS=16384 kernel.

If I'm correct than I'd have thought that this will be a significant problem for SGI, so we should find other solutions.

Quoted 3 lines
Quoted 1 line

So I'm wobbly. Could we please examine the alternatives before proceeding?

This works fine with a 32k stack on IA64 with 4k processors.

yeah, but that's an order-1 allocation on ia64, not an order-3.

Quoted 5 lines

So I tend to
think of this as a solution that is already working on another platform. An 8k stack is also going to be tough with 4k processors on x86_64 which we will have soon.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 3 lines · Andrew Morton

I'm talking about software, not hardware. I'd expect that you'll have trouble talking RH/suse/etc into general shipping of an NR_CPUS=16384 kernel.

Yeah that is one reason why I removed all percpu arrays from the kernel with the cpu_alloc patchset. I think we can get to a point where this does not hurt that much. We want to be as close as possible to a distro kernel as possible.

Quoted 2 lines
Quoted 1 line

If I'm correct than I'd have thought that this will be a significant

problem for SGI, so we should find other solutions.

Maybe a special kernel from the distros is unavoidable but then they have done that in the past for us too. Certainly we do not want to have the kernel patches just for HPC apps. This is an option after all and not a default. Mike Travis is working on reducing the per cpu overhead in the x86_64 arch code. So we should be getting to a pretty good situation even if we have to leave the cpumasks alone.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

So I'm wobbly. Could we please examine the alternatives before proceeding?

This works fine with a 32k stack on IA64 with 4k processors.

yeah, but that's an order-1 allocation on ia64, not an order-3.

Well the default is also an order-1 allocation on x86_64. The order-3 alloc is not going to be that much of a problem if you have a system with several terabytes of RAM.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#11 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 23 lines · On Fri, 9 Nov 2007 13:19:11 -0800 (PST) Christoph Lameter <[email protected]>…
Quoted 3 lines · Andrew Morton

I'm talking about software, not hardware. I'd expect that you'll have trouble talking RH/suse/etc into general shipping of an NR_CPUS=16384 kernel.

Yeah that is one reason why I removed all percpu arrays from the kernel with the cpu_alloc patchset. I think we can get to a point where this does not hurt that much. We want to be as close as possible to a distro kernel as possible.

Quoted 2 lines
Quoted 1 line

If I'm correct than I'd have thought that this will be a significant

problem for SGI, so we should find other solutions.

Maybe a special kernel from the distros is unavoidable but then they have done that in the past for us too. Certainly we do not want to have the kernel patches just for HPC apps. This is an option after all and not a default. Mike Travis is working on reducing the per cpu overhead in the x86_64 arch code. So we should be getting to a pretty good situation even if we have to leave the cpumasks alone.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

So I'm wobbly. Could we please examine the alternatives before proceeding?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

This works fine with a 32k stack on IA64 with 4k processors.

yeah, but that's an order-1 allocation on ia64, not an order-3.

Well the default is also an order-1 allocation on x86_64. The order-3 alloc is not going to be that much of a problem if you have a system with several terabytes of RAM.

Fair enough.

Did you consider making the stack size a calculated-in-Kconfig-arithmetic thing rather than an offered-to-humans thing? Derive it from CONFIG_NR_CPUS?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw

Re: [patch 2/2] x86_64: Configure stack size

Quoted 2 lines · Andrew Morton

Did you consider making the stack size a calculated-in-Kconfig-arithmetic thing rather than an offered-to-humans thing? Derive it from CONFIG_NR_CPUS?

Estimating stack use based on NR_CPUS is a difficult thing. The estimates likely have to change as the use of the stack changes in the kernel. I'd rather have a constant there now. Maybe in the future we can come up with such a scheme.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

Re: [patch 2/2] x86_64: Configure stack size

In reply to Andrew Morton
Quoted 2 lines

What else can we do? Change all sites to do some dynamic allocation if (NR_CPUS >= lots), I guess.

I think that's an reasonable alternative. Perhaps push one or two into task_struct and grab them from there, then go dynamic. Only issue is error handling and making it look nice in the source.

Quoted 2 lines

As for timing: we might as well merge it now so that 2.6.25 has at least a chance of running on 16384-way.

x86 is still limited to 256 virtual CPUs. What makes you think that changed? With x2APIC from Intel it will be higher, but I haven't seen code for that yet.

Quoted 2 lines

otoh, I doubt if anyone will actually ship an NR_CPUS=16384 kernel, so it isn't terribly pointful.

NR_CPUS==4096 might happen. Of course that still needs eliminating a lot of NR_CPUS arrays and fixing up of NR_INTERRUPTS and some other things.

-Andi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>