Skip to contentSkip to conversation

Use kzalloc

PATCH In review [email protected] 5 participants 6 messages Aug 3, 2006 – Aug 13, 2006 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use kzalloc

From: Thomas Hisch <[email protected]>

use kzalloc in include/asm-i386/thread_info.h instead of kmalloc + memset

---
 include/asm-i386/thread_info.h |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
include/asm-i386/thread_info.h +1 -4
index 54d6d7a..a8f37f2 100644
@@ -32,7 +32,6 @@ struct thread_info {
 	__u32			cpu;		/* current CPU */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 
-
 	mm_segment_t		addr_limit;	/* thread address space:
 					 	   0-0xBFFFFFFF for user-thead
 						   0-0xFFFFFFFF for kernel-thread
@@ -99,9 +98,7 @@ #define alloc_thread_info(tsk)					\
 	({							\
 		struct thread_info *ret;			\
 								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
-		if (ret)					\
-			memset(ret, 0, THREAD_SIZE);		\
+		ret = kzalloc(THREAD_SIZE, GFP_KERNEL);		\
 		ret;						\
 	})
 #else
Signature · 8 lines
1.4.2.rc1.gbc9e-dirty



_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
#1 lore raw
Quoted 14 lines · On 03.08.2006 [22:47:08 +0200], [email protected] wrote:

From: Thomas Hisch <[email protected]>

use kzalloc in include/asm-i386/thread_info.h instead of kmalloc + memset

---
 include/asm-i386/thread_info.h |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
include/asm-i386/thread_info.h +0 -0
index 54d6d7a..a8f37f2 100644

include/asm-i386/thread_info.h struct thread_info { · line 35

Quoted 4 lines
include/asm-i386/thread_info.h +0 -1
@@ -32,7 +32,6 @@ struct thread_info {
 	__u32			cpu;		/* current CPU */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 
-

Looks like an unrelated change sneaked in.

Thanks,
Nish

Quoted 23 lines
include/asm-i386/thread_info.h +1 -3
 	mm_segment_t		addr_limit;	/* thread address space:
 					 	   0-0xBFFFFFFF for user-thead
 						   0-0xFFFFFFFF for kernel-thread
@@ -99,9 +98,7 @@ #define alloc_thread_info(tsk)					\
 	({							\
 		struct thread_info *ret;			\
 								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
-		if (ret)					\
-			memset(ret, 0, THREAD_SIZE);		\
+		ret = kzalloc(THREAD_SIZE, GFP_KERNEL);		\
 		ret;						\
 	})
 #else
Signature · 8 lines
1.4.2.rc1.gbc9e-dirty



_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw
In reply to [email protected]
Quoted 22 lines · On Thu, 2006-08-03 at 22:47 +0200, [email protected] wrote:

From: Thomas Hisch <[email protected]>

use kzalloc in include/asm-i386/thread_info.h instead of kmalloc + memset

---
 include/asm-i386/thread_info.h |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
include/asm-i386/thread_info.h +0 -1
index 54d6d7a..a8f37f2 100644
@@ -32,7 +32,6 @@ struct thread_info {
 	__u32			cpu;		/* current CPU */
 	int			preempt_count;	/* 0 => preemptable, <0 => BUG */
 
-
 	mm_segment_t		addr_limit;	/* thread address space:
 					 	   0-0xBFFFFFFF for user-thead
 						   0-0xFFFFFFFF for kernel-thread

include/asm-i386/thread_info.h #define alloc_thread_info(tsk) \ · line 104

Quoted 10 lines
include/asm-i386/thread_info.h +1 -3
@@ -99,9 +98,7 @@ #define alloc_thread_info(tsk)					\
 	({							\
 		struct thread_info *ret;			\
 								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
-		if (ret)					\
-			memset(ret, 0, THREAD_SIZE);		\
+		ret = kzalloc(THREAD_SIZE, GFP_KERNEL);		\
 		ret;						\
 	})
 #else

which leaves
---- snip ----
#define alloc_thread_info(tsk)

 	({							\
		struct thread_info *ret;			\
								\
		ret = kzalloc(THREAD_SIZE, GFP_KERNEL);		\
		ret;						\

})
---- snip ----
which is AFAICS equivalent to
---- snip ----
#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) ---- snip ----

Bernd

Signature · 8 lines
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
#3 lore raw

PATCH 1/1 Use kzalloc

In reply to [email protected]

From: Thomas Hisch <[email protected]>

Replace kzalloc instead of kmalloc + memset.

---
 include/asm-i386/thread_info.h |   10 +---------
 1 files changed, 1 insertions(+), 9 deletions(-)
include/asm-i386/thread_info.h +1 -9
index 54d6d7a..46d32ad 100644
@@ -95,15 +95,7 @@ static inline struct thread_info *curren
 
 /* thread information allocation */
 #ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk)					\
-	({							\
-		struct thread_info *ret;			\
-								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
-		if (ret)					\
-			memset(ret, 0, THREAD_SIZE);		\
-		ret;						\
-	})
+#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL)
 #else
 #define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
 #endif
Signature · 8 lines
1.4.2.rc1.gf25b-dirty



_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
#4 lore raw
In reply to [email protected]

hi thomas,
this patch results in:

#ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) #else
#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL) #endif

does it make sense to have two case ? the performance penalty should not matter if this is reduced to
#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) in any case. opinions ?

just my 2 cents,
walter

Quoted 20 lines · [email protected] wrote:

From: Thomas Hisch <[email protected]>

Replace kzalloc instead of kmalloc + memset.

---
 include/asm-i386/thread_info.h |   10 +---------
 1 files changed, 1 insertions(+), 9 deletions(-)
include/asm-i386/thread_info.h +0 -3
index 54d6d7a..46d32ad 100644
@@ -95,15 +95,7 @@ static inline struct thread_info *curren
 
 /* thread information allocation */
 #ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk)					\
-	({							\
-		struct thread_info *ret;			\

include/asm-i386/thread_info.h static inline struct thread_info *curren · line 101

Quoted 10 lines
include/asm-i386/thread_info.h +1 -6
-								\
-		ret = kmalloc(THREAD_SIZE, GFP_KERNEL);		\
-		if (ret)					\
-			memset(ret, 0, THREAD_SIZE);		\
-		ret;						\
-	})
+#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL)
 #else
 #define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
 #endif

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#5 lore raw

PATCH 1/1 Use kzalloc

In reply to [email protected]
Quoted 9 lines · walter harms

hi thomas,
this patch results in:

#ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) #else
#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL) #endif

Quoted 4 lines

does it make sense to have two case ? the performance penalty should not matter if this is reduced to
#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) in any case. opinions ?

yes, we could reduce it to kzalloc but why should we reduce it when a zeroed allocation is not really needed in case of CONFIG_DEBUG_STACK_USAGE is not set. look at include/asm-powerpc/thread_info.h there is the same defined alloc_thread_info function (if THREAD_SHIFT < PAGE_SHIFT) as in my patch.

maybe I'm totally wrong with my point of view, so please let me hear your opinions.

thomas

Quoted 3 lines

just my 2 cents,
walter

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors