Shrink the held_lock struct by using bitfields.
Shrink the held_lock struct by using bitfields.
This shrinks task_struct on lockdep enabled kernels by 480 bytes.
include/linux/lockdep.h +5 -5
@@ -175,11 +175,11 @@ struct held_lock {* The following field is used to detect when we cross into an * interrupt context: */ -int irq_context; -int trylock; -int read; -int check; -int hardirqs_off; + unsigned char irq_context:1; + unsigned char trylock:1; + unsigned char read:1; + unsigned char check:1; + unsigned char hardirqs_off:1; };/*
Signature · 1 line
http://www.codemonkey.org.uk
On Tue, Jan 02, 2007 at 06:35:58PM -0500, Dave Jones wrote:
Sent the wrong diff. Here's the fixed version...
Shrink the held_lock struct by using bitfields.
This shrinks task_struct on lockdep enabled kernels by 480 bytes.
include/linux/lockdep.h +5 -5
@@ -175,11 +175,11 @@ struct held_lock {* The following field is used to detect when we cross into an * interrupt context: */ -int irq_context; -int trylock; -int read; -int check; -int hardirqs_off; + unsigned char irq_context:1; + unsigned char trylock:1; + unsigned char read:2; + unsigned char check:1; + unsigned char hardirqs_off:1; };/*
Signature · 1 line
http://www.codemonkey.org.uk
include/linux/lockdep.h struct held_lock { · line 182
Quoted 5 lines · Dave Jones
include/linux/lockdep.h +5
-0+ unsigned char irq_context:1; + unsigned char trylock:1; + unsigned char read:2; + unsigned char check:1; + unsigned char hardirqs_off:1;
cool! I totally missed those. I'd even do this for 2.6.20, but it's probably too late for that.
Ingo
PATCH 1/1 lockdep: shrink held_lock structure
Subject: [patch] lockdep: shrink held_lock structure
From: Dave Jones <[email protected]>
shrink the held_lock structure from 40 to 20 bytes. This shrinks struct task_struct from 3056 to 2464 bytes.
[ From: Ingo Molnar <[email protected]>, shrunk hlock->class too. ]
Shrunk MAX_KEYS_BITS from 11 to 10, and thus kernel size goes down significantly too:
text data bss dec hex filename
5297365 642664 3203072 9143101 8b833d vmlinux.before 5298257 642024 2953216 8893497 87b439 vmlinux.after
--- include/linux/lockdep.h | 16 ++++--- kernel/lockdep.c | 91 ++++++++++++++++++++++++--------------------- kernel/lockdep_internals.h | 3 - 3 files changed, 58 insertions(+), 52 deletions(-)
include/linux/lockdep.h +9 -7
@@ -143,6 +143,9 @@ struct lock_chain {u64 chain_key; }; +#define MAX_LOCKDEP_KEYS_BITS 10 +#define MAX_LOCKDEP_KEYS (1UL << MAX_LOCKDEP_KEYS_BITS) +struct held_lock {/* * One-way hash of the dependency chain up to this point. We
@@ -159,10 +162,9 @@ struct held_lock {* with zero), here we store the previous hash value: */ u64 prev_chain_key; -struct lock_class *class;unsigned long acquire_ip;struct lockdep_map *instance; - + int class_idx:MAX_LOCKDEP_KEYS_BITS;/* * The lock-stack is unified in that the lock chains of interrupt * contexts nest ontop of process context chains, but we 'separate'
@@ -176,11 +178,11 @@ struct held_lock {* The following field is used to detect when we cross into an * interrupt context: */ -int irq_context; -int trylock; -int read; -int check; -int hardirqs_off; + unsigned char irq_context:1; + unsigned char trylock:1; + unsigned char read:2; + unsigned char check:1; + unsigned char hardirqs_off:1; };/*
kernel/lockdep.c +49 -42
311 lines not on this page · raw message
kernel/lockdep_internals.h +0 -3
@@ -17,9 +17,6 @@*/ #define MAX_LOCKDEP_ENTRIES 8192UL -#define MAX_LOCKDEP_KEYS_BITS 11 -#define MAX_LOCKDEP_KEYS (1UL << MAX_LOCKDEP_KEYS_BITS) -#define MAX_LOCKDEP_CHAINS_BITS 14#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS)
Re: [patch] lockdep: shrink held_lock structure
Quoted 7 lines · Ingo Molnar
Subject: [patch] lockdep: shrink
held_lockstructure
From: Dave Jones <[email protected]>shrink the
held_lockstructure from 40 to 20 bytes. This shrinks structtask_structfrom 3056 to 2464 bytes.[ From: Ingo Molnar <[email protected]>, shrunk
hlock->classtoo. ]
doh - some buglet sneaked into the hlock->class_idx change ... investigating it. Ignore this patch for now.
Ingo