Skip to contentSkip to conversation

core-small: Introduce CONFIG_CORE_SMALL from -tiny

PATCH In review Matt Mackall 4 participants 15 messages Jan 22, 2005 – Jan 24, 2005

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

cover core-small: Introduce CONFIG_CORE_SMALL from -tiny

This set of patches introduces a new config option CONFIG_CORE_SMALL from the -tiny tree for small systems. This series should apply cleanly against 2.6.11-rc1-mm2.

When selected, it enables various tweaks to miscellaneous core data structures to shrink their size on small systems. While each tweak is fairly small, in aggregate they can save a substantial amount of memory.

1 Add option to embedded menu
2 Collapse major names hash
3 Collapse chrdevs hash
4 Shrink PID lookup tables
5 Shrink uid hash
6 Shrink futex queue hash
7 Shrink timer lists
8 Shrink console buffer

#1 lore raw

PATCH 1/8 core-small: Add option to embedded menu

Add CONFIG_CORE_SMALL for miscellaneous core size that don't warrant their own options. Example users to follow.

init/Kconfig +6 -0
Index: tiny/init/Kconfig
===================================================================
@@ -287,6 +287,12 @@
 	   reported.  KALLSYMS_EXTRA_PASS is only a temporary workaround while
 	   you wait for kallsyms to be fixed.
 
+config CORE_SMALL
+	default n
+	bool "Enable various size reductions for core" if EMBEDDED
+	help
+	  This reduces the size of miscellaneous core kernel data structures.
+
 config FUTEX
 	bool "Enable futex support" if EMBEDDED
 	default y
#2 lore raw

PATCH 2/8 core-small: Collapse major names hash

CONFIG_CORE_SMALL degrade genhd major names hash to linked list

drivers/block/genhd.c +4 -0
Index: tiny-new/drivers/block/genhd.c
===================================================================
@@ -15,7 +15,11 @@
 #include <linux/kmod.h>
 #include <linux/kobj_map.h>
 
+#ifdef CONFIG_CORE_SMALL
+#define MAX_PROBE_HASH 1 /* degrade to linked list */
+#else
 #define MAX_PROBE_HASH 255	/* random */
+#endif
 
 static struct subsystem block_subsys;
 
#3 lore raw

PATCH 3/8 core-small: Collapse chrdevs hash

CONFIG_CORE_SMALL degrade char dev hash table to linked list

fs/char_dev.c +4 -0
Index: tiny-queue/fs/char_dev.c
===================================================================
@@ -26,7 +26,11 @@
 
 static struct kobj_map *cdev_map;
 
+#ifdef CONFIG_CORE_SMALL
+#define MAX_PROBE_HASH 1 /* degrade to linked list */
+#else
 #define MAX_PROBE_HASH 255	/* random */
+#endif
 
 static DEFINE_RWLOCK(chrdevs_lock);
 
#4 lore raw

PATCH 4/8 core-small: Shrink PID lookup tables

CONFIG_CORE_SMALL reduce size of pidmap table for small machines

include/linux/threads.h +8 -0
Index: tiny/include/linux/threads.h
===================================================================
@@ -25,11 +25,19 @@
 /*
  * This controls the default maximum pid allocated to a process
  */
+#ifdef CONFIG_CORE_SMALL
+#define PID_MAX_DEFAULT 0x1000
+#else
 #define PID_MAX_DEFAULT 0x8000
+#endif
 
 /*
  * A maximum of 4 million PIDs should be enough for a while:
  */
+#ifdef CONFIG_CORE_SMALL
+#define PID_MAX_LIMIT (PAGE_SIZE*8) /* one pidmap entry */
+#else
 #define PID_MAX_LIMIT (sizeof(long) > 4 ? 4*1024*1024 : PID_MAX_DEFAULT)
+#endif
 
 #endif
#5 lore raw

PATCH 5/8 core-small: Shrink uid hash

CONFIG_CORE_SMALL reduce UID lookup hash

kernel/user.c +4 -0
Index: tiny/kernel/user.c
===================================================================
@@ -18,7 +18,11 @@
  * UID task count cache, to get fast user lookup in "alloc_uid"
  * when changing user ID's (ie setuid() and friends).
  */
+#ifdef CONFIG_CORE_SMALL
+#define UIDHASH_BITS		3
+#else
 #define UIDHASH_BITS		8
+#endif
 #define UIDHASH_SZ		(1 << UIDHASH_BITS)
 #define UIDHASH_MASK		(UIDHASH_SZ - 1)
 #define __uidhashfn(uid)	(((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
#6 lore raw

PATCH 6/8 core-small: Shrink futex queue hash

CONFIG_CORE_SMALL reduce futex hash table

kernel/futex.c +4 -0
Index: tiny-new/kernel/futex.c
===================================================================
@@ -40,7 +40,11 @@
 #include <linux/pagemap.h>
 #include <linux/syscalls.h>
 
+#ifdef CONFIG_CORE_SMALL
+#define FUTEX_HASHBITS 4
+#else
 #define FUTEX_HASHBITS 8
+#endif
 
 /*
  * Futexes are matched on equal values of this key.
#7 lore raw

PATCH 7/8 core-small: Shrink timer lists

CONFIG_CORE_SMALL reduce timer list hashes

kernel/timer.c +6 -0
Index: tiny-queue/kernel/timer.c
===================================================================
@@ -50,8 +50,14 @@
 /*
  * per-CPU timer vector definitions:
  */
+
+#ifdef CONFIG_CORE_SMALL
+#define TVN_BITS 4
+#define TVR_BITS 6
+#else
 #define TVN_BITS 6
 #define TVR_BITS 8
+#endif
 #define TVN_SIZE (1 << TVN_BITS)
 #define TVR_SIZE (1 << TVR_BITS)
 #define TVN_MASK (TVN_SIZE - 1)
#8 lore raw

PATCH 8/8 core-small: Shrink console buffer

CONFIG_CORE_SMALL reduce console transfer buffer

include/linux/vt_kern.h +5 -1
Index: tiny-queue/include/linux/vt_kern.h
===================================================================
@@ -84,7 +84,11 @@
  * vc_screen.c shares this temporary buffer with the console write code so that
  * we can easily avoid touching user space while holding the console spinlock.
  */
-#define CON_BUF_SIZE	PAGE_SIZE
+#ifdef CONFIG_CORE_SMALL
+#define CON_BUF_SIZE 512
+#else
+#define CON_BUF_SIZE PAGE_SIZE
+#endif
 extern char con_buf[CON_BUF_SIZE];
 extern struct semaphore con_buf_sem;
 
#9 lore raw
In reply to Matt Mackall
Quoted 9 lines · Matt Mackall

This set of patches introduces a new config option CONFIG_CORE_SMALL from the -tiny tree for small systems. This series should apply cleanly against 2.6.11-rc1-mm2.

When selected, it enables various tweaks to miscellaneous core data structures to shrink their size on small systems. While each tweak is fairly small, in aggregate they can save a substantial amount of memory.

You know what I'm going to ask ;) How much memory?

I wish it didn't have "core" in the name. A little misleading.

Did you think of making CONFIG_CORE_SMALL an integer which has values zero or one?

Then you can lose all those ifdefs:

#define MAX_PROBE_HASH (255 - CONFIG_CORE_SMALL * 254) /* dorky */

#define PID_MAX_DEFAULT (CONFIG_CORE_SMALL ? 0x1000 : 0x8000) #define UIDHASH_BITS (CONFIG_CORE_SMALL ? 3 : 8) #define FUTEX_HASHBITS (CONFIG_CORE_SMALL ? 4 : 8) etc.

I think the ?: thing will work everywhere:

	#define XX 1
	char xx[XX ? 10 : 20];

even this works...

#10 lore raw
Quoted 6 lines · Andrew Morton
Quoted 5 lines · Matt Mackall

This set of patches introduces a new config option CONFIG_CORE_SMALL from the -tiny tree for small systems. This series should apply cleanly against 2.6.11-rc1-mm2.

Quoted 6 lines
Quoted 4 lines

When selected, it enables various tweaks to miscellaneous core data structures to shrink their size on small systems. While each tweak is fairly small, in aggregate they can save a substantial amount of memory.

You know what I'm going to ask ;) How much memory?

This stuff is mostly pretty small, a few K per patch. I think these 8 are about 40k total but my notes are several months old.

Quoted 1 line

I wish it didn't have "core" in the name. A little misleading.

Well I've got another set called NET_SMALL. BASE?

Quoted 6 lines

Did you think of making CONFIG_CORE_SMALL an integer which has values zero or one?

Then you can lose all those ifdefs:

#define MAX_PROBE_HASH (255 - CONFIG_CORE_SMALL * 254) /* dorky */

Ew.

Quoted 4 lines

#define PID_MAX_DEFAULT (CONFIG_CORE_SMALL ? 0x1000 : 0x8000) #define UIDHASH_BITS (CONFIG_CORE_SMALL ? 3 : 8) #define FUTEX_HASHBITS (CONFIG_CORE_SMALL ? 4 : 8) etc.

Hmm. I think we'd want a hidden config variable for this and I'm not sure how well the config language allows setting an int from a bool. And then it would need another name. On the whole, seems more complex than what I've done.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#11 lore raw
Quoted 4 lines · Matt Mackall
Quoted 2 lines

I wish it didn't have "core" in the name. A little misleading.

Well I've got another set called NET_SMALL. BASE?

BASE works, I guess.

Quoted 7 lines
Quoted 4 lines

#define PID_MAX_DEFAULT (CONFIG_CORE_SMALL ? 0x1000 : 0x8000) #define UIDHASH_BITS (CONFIG_CORE_SMALL ? 3 : 8) #define FUTEX_HASHBITS (CONFIG_CORE_SMALL ? 4 : 8) etc.

Hmm. I think we'd want a hidden config variable for this and I'm not sure how well the config language allows setting an int from a bool.

config AKPM_BOOL
bool "akpm"

config AKPM_INT
int
default 1 if AKPM_BOOL
default 0 if !AKPM_BOOL

seems to do everything which it should.

Quoted 2 lines

And then it would need another name. On the whole, seems more complex than what I've done.

No, it's quite simple and avoids lots of ifdeffing.

#12 lore raw
Quoted 24 lines · Andrew Morton
Quoted 4 lines · Matt Mackall
Quoted 2 lines

I wish it didn't have "core" in the name. A little misleading.

Well I've got another set called NET_SMALL. BASE?

BASE works, I guess.

Quoted 7 lines
Quoted 4 lines

#define PID_MAX_DEFAULT (CONFIG_CORE_SMALL ? 0x1000 : 0x8000) #define UIDHASH_BITS (CONFIG_CORE_SMALL ? 3 : 8) #define FUTEX_HASHBITS (CONFIG_CORE_SMALL ? 4 : 8) etc.

Hmm. I think we'd want a hidden config variable for this and I'm not sure how well the config language allows setting an int from a bool.

config AKPM_BOOL
bool "akpm"

config AKPM_INT
int
default 1 if AKPM_BOOL
default 0 if !AKPM_BOOL

Quoted 6 lines

seems to do everything which it should.

Quoted 2 lines

And then it would need another name. On the whole, seems more complex than what I've done.

No, it's quite simple and avoids lots of ifdeffing.

Ok, will respin these Monday.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#13 lore raw
In reply to Matt Mackall
Quoted 5 lines · Matt Mackall
Quoted 3 lines

Then you can lose all those ifdefs:

#define MAX_PROBE_HASH (255 - CONFIG_CORE_SMALL * 254) /* dorky */

Ew.

#define SIZE_HASH(small, large) CONFIG_CORE_SMALL ? (small):(large)

Perhaps ?

#14 lore raw
Quoted 1 line · Alan Cox

#define SIZE_HASH(small, large) CONFIG_CORE_SMALL ? (small):(large)

I hate to be a "ditto-head", but I like this a lot.

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Electronics
=============================