mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Bird <tim.bird@am.sony.com>
To: Russell King <rmk@arm.linux.org.uk>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	Arnd Bergmann <arnd@arndb.de>, Andi Kleen <andi@firstfloor.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/3] ARM 4Kstacks: Add support for 4K kernel stacks to ARM
Date: Tue, 18 Oct 2011 16:29:10 -0700	[thread overview]
Message-ID: <4E9E0BC6.1030505@am.sony.com> (raw)
In-Reply-To: <4E9E0B71.9020708@am.sony.com>

This saves 4K per kernel thread and user-space process.
For systems with lots of threads, this can save
100s of K of memory.

Signed-off-by: Tim Bird <tim.bird@am.sony.com>
---
 arch/arm/Kconfig                   |   13 +++++++++++++
 arch/arm/include/asm/thread_info.h |    7 ++++++-
 arch/arm/kernel/entry-header.S     |    4 ++--
 arch/arm/mm/proc-macros.S          |    4 ++--
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 3146ed3..321ee11 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1555,6 +1555,19 @@ config OABI_COMPAT
 	  UNPREDICTABLE (in fact it can be predicted that it won't work
 	  at all). If in doubt say Y.

+config 4KSTACKS
+	bool "Use 4K kernel stacks instead of 8K"
+	default n
+	help
+	  This option will use less memory for each kernel stack in the
+	  system, which can save potentially hundreds of kilobytes of memory.
+	  It also helps reduce fragmentation in kernel memory.  However,
+	  it can be dangerous since not all kernel code paths are thrifty
+	  in their use of the stack.  Unless you have carefully monitored your
+	  kernel stack usage and verified that your programs and kernel
+	  usage patterns will not overflow 4K, you should leave this set
+	  to N.
+
 config ARCH_HAS_HOLES_MEMORYMODEL
 	bool

diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index 7b5cc8d..3021d06 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -15,8 +15,13 @@
 #include <linux/compiler.h>
 #include <asm/fpstate.h>

+#ifndef CONFIG_4KSTACKS
 #define THREAD_SIZE_ORDER	1
-#define THREAD_SIZE		8192
+#else
+#define THREAD_SIZE_ORDER	0
+#endif
+
+#define THREAD_SIZE		(4096 << THREAD_SIZE_ORDER)
 #define THREAD_START_SP		(THREAD_SIZE - 8)

 #ifndef __ASSEMBLY__
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index 9a8531e..c818505 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -109,8 +109,8 @@
 	.endm

 	.macro	get_thread_info, rd
-	mov	\rd, sp, lsr #13
-	mov	\rd, \rd, lsl #13
+	mov	\rd, sp, lsr #12 + THREAD_SIZE_ORDER
+	mov	\rd, \rd, lsl #12 + THREAD_SIZE_ORDER
 	.endm

 	@
diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
index 307a4de..27c0907 100644
--- a/arch/arm/mm/proc-macros.S
+++ b/arch/arm/mm/proc-macros.S
@@ -30,8 +30,8 @@
  * act_mm - get current->active_mm
  */
 	.macro	act_mm, rd
-	bic	\rd, sp, #8128
-	bic	\rd, \rd, #63
+	mov	\rd, sp, lsr #12 + THREAD_SIZE_ORDER
+	mov	\rd, \rd, lsl #12 + THREAD_SIZE_ORDER
 	ldr	\rd, [\rd, #TI_TASK]
 	ldr	\rd, [\rd, #TSK_ACTIVE_MM]
 	.endm
-- 
1.6.6


  reply	other threads:[~2011-10-18 23:29 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-18 23:27 [PATCH 0/3] ARM 4Kstacks: introduction Tim Bird
2011-10-18 23:29 ` Tim Bird [this message]
2011-10-18 23:31 ` [PATCH 2/3] ARM: Add static kernel function stack size analyzer, for ARM Tim Bird
2011-10-19 10:45   ` Arnd Bergmann
2011-10-21 17:03     ` Andi Kleen
2011-10-18 23:34 ` [PATCH 3/3] ARM 4Kstacks: Decrease poll and select stack usage, when using 4K stacks Tim Bird
2011-10-20 12:21   ` Arnd Bergmann
2011-10-19  0:14 ` [PATCH 0/3] ARM 4Kstacks: introduction Joe Perches
2011-10-19  0:26   ` Tim Bird
2011-10-19  0:31     ` Joe Perches
2011-10-19 23:43       ` Tim Bird
2011-10-19  4:54     ` Dave Chinner
2011-10-19  5:02       ` Andi Kleen
2011-10-19 10:51     ` Arnd Bergmann
2011-10-22  8:50       ` Ming Lei
2011-10-22 13:13         ` Måns Rullgård
2011-10-22 14:27           ` Andi Kleen
2011-10-22 13:36         ` Russell King - ARM Linux
2011-10-23 19:25           ` Tim Bird
2011-10-23 20:11             ` Russell King - ARM Linux
2011-10-24 10:36           ` Ming Lei
2011-10-23 14:06       ` Bernd Petrovitsch
2011-10-19  4:33 ` Dave Chinner
2011-10-19  7:35 ` Russell King - ARM Linux
2011-10-19 23:36   ` Tim Bird
2011-10-20  0:13     ` Måns Rullgård
2011-10-20  1:08       ` Tim Bird
2011-10-20  1:55         ` Måns Rullgård
2011-10-20 22:21     ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E9E0BC6.1030505@am.sony.com \
    --to=tim.bird@am.sony.com \
    --cc=andi@firstfloor.org \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome