Skip to contentSkip to conversation

Shrink the held_lock struct by using bitfields.

PATCH In review Dave Jones 3 participants 5 messages Jan 2, 2007 – Jan 14, 2007 Locking primitives

lore
Share & tools
lore

Dave Jones

author
#0 lore raw

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
index ea097dd..ba81cce 100644
@@ -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
author
#1 lore raw

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
index ea097dd..ba81cce 100644
@@ -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
maintainer Acked-by
#2 lore raw

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

#3 lore raw

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
Index: linux/include/linux/lockdep.h
===================================================================
@@ -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
Index: linux/kernel/lockdep_internals.h
===================================================================
@@ -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)
 
#4 lore raw

Re: [patch] lockdep: shrink held_lock structure

Quoted 7 lines · Ingo Molnar

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. ]

doh - some buglet sneaked into the hlock->class_idx change ... investigating it. Ignore this patch for now.

Ingo