linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfs: simplify kmem_{zone_}zalloc
@ 2013-11-01 10:25 Gu Zheng
  2013-11-01 20:58 ` Dave Chinner
  0 siblings, 1 reply; 3+ messages in thread
From: Gu Zheng @ 2013-11-01 10:25 UTC (permalink / raw)
  To: bpm, elder; +Cc: xfs, linux-kernel, guz.fnst

Introduce flag KM_ZERO which is used to alloc zeroed entry, and convert
kmem_{zone_}zalloc to call kmem_{zone_}alloc() with KM_ZERO directly,
in order to avoid the setting to zero step.


Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
---
 fs/xfs/kmem.c |   14 ++------------
 fs/xfs/kmem.h |    7 ++++++-
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c
index a02cfb9..d56fcc9 100644
--- a/fs/xfs/kmem.c
+++ b/fs/xfs/kmem.c
@@ -65,12 +65,7 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
 void *
 kmem_zalloc(size_t size, xfs_km_flags_t flags)
 {
-	void	*ptr;
-
-	ptr = kmem_alloc(size, flags);
-	if (ptr)
-		memset((char *)ptr, 0, (int)size);
-	return ptr;
+	return kmem_alloc(size, flags | KM_ZERO);
 }
 
 void *
@@ -132,10 +127,5 @@ kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
 void *
 kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
 {
-	void	*ptr;
-
-	ptr = kmem_zone_alloc(zone, flags);
-	if (ptr)
-		memset((char *)ptr, 0, kmem_cache_size(zone));
-	return ptr;
+	return kmem_zone_alloc(zone, flags | KM_ZERO);
 }
diff --git a/fs/xfs/kmem.h b/fs/xfs/kmem.h
index 3a7371c..8ea21fd 100644
--- a/fs/xfs/kmem.h
+++ b/fs/xfs/kmem.h
@@ -32,6 +32,7 @@ typedef unsigned __bitwise xfs_km_flags_t;
 #define KM_NOSLEEP	((__force xfs_km_flags_t)0x0002u)
 #define KM_NOFS		((__force xfs_km_flags_t)0x0004u)
 #define KM_MAYFAIL	((__force xfs_km_flags_t)0x0008u)
+#define KM_ZERO		((__force xfs_km_flags_t)0x0010u)
 
 /*
  * We use a special process flag to avoid recursive callbacks into
@@ -43,7 +44,7 @@ kmem_flags_convert(xfs_km_flags_t flags)
 {
 	gfp_t	lflags;
 
-	BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL));
+	BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL|KM_ZERO));
 
 	if (flags & KM_NOSLEEP) {
 		lflags = GFP_ATOMIC | __GFP_NOWARN;
@@ -52,6 +53,10 @@ kmem_flags_convert(xfs_km_flags_t flags)
 		if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS))
 			lflags &= ~__GFP_FS;
 	}
+
+	if (flags & KM_ZERO)
+		lflags |= __GFP_ZERO;
+
 	return lflags;
 }
 
-- 
1.7.7



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: simplify kmem_{zone_}zalloc
  2013-11-01 10:25 [PATCH] xfs: simplify kmem_{zone_}zalloc Gu Zheng
@ 2013-11-01 20:58 ` Dave Chinner
  2013-11-04  2:26   ` Gu Zheng
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Chinner @ 2013-11-01 20:58 UTC (permalink / raw)
  To: Gu Zheng; +Cc: bpm, elder, linux-kernel, xfs

On Fri, Nov 01, 2013 at 06:25:11PM +0800, Gu Zheng wrote:
> Introduce flag KM_ZERO which is used to alloc zeroed entry, and convert
> kmem_{zone_}zalloc to call kmem_{zone_}alloc() with KM_ZERO directly,
> in order to avoid the setting to zero step.
> 
> 
> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
> ---
>  fs/xfs/kmem.c |   14 ++------------
>  fs/xfs/kmem.h |    7 ++++++-
>  2 files changed, 8 insertions(+), 13 deletions(-)
> 
> diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c
> index a02cfb9..d56fcc9 100644
> --- a/fs/xfs/kmem.c
> +++ b/fs/xfs/kmem.c
> @@ -65,12 +65,7 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
>  void *
>  kmem_zalloc(size_t size, xfs_km_flags_t flags)
>  {
> -	void	*ptr;
> -
> -	ptr = kmem_alloc(size, flags);
> -	if (ptr)
> -		memset((char *)ptr, 0, (int)size);
> -	return ptr;
> +	return kmem_alloc(size, flags | KM_ZERO);
>  }
>  
>  void *
> @@ -132,10 +127,5 @@ kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
>  void *
>  kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
>  {
> -	void	*ptr;
> -
> -	ptr = kmem_zone_alloc(zone, flags);
> -	if (ptr)
> -		memset((char *)ptr, 0, kmem_cache_size(zone));
> -	return ptr;
> +	return kmem_zone_alloc(zone, flags | KM_ZERO);
>  }

These functions should be made static inline functions in kmem.h
seeing as they are now just a simple wrapper.

Otherwise it's a nice cleanup.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: simplify kmem_{zone_}zalloc
  2013-11-01 20:58 ` Dave Chinner
@ 2013-11-04  2:26   ` Gu Zheng
  0 siblings, 0 replies; 3+ messages in thread
From: Gu Zheng @ 2013-11-04  2:26 UTC (permalink / raw)
  To: Dave Chinner; +Cc: bpm, elder, linux-kernel, xfs

Hi Dave,
On 11/02/2013 04:58 AM, Dave Chinner wrote:

> On Fri, Nov 01, 2013 at 06:25:11PM +0800, Gu Zheng wrote:
>> Introduce flag KM_ZERO which is used to alloc zeroed entry, and convert
>> kmem_{zone_}zalloc to call kmem_{zone_}alloc() with KM_ZERO directly,
>> in order to avoid the setting to zero step.
>>
>>
>> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
>> ---
>>  fs/xfs/kmem.c |   14 ++------------
>>  fs/xfs/kmem.h |    7 ++++++-
>>  2 files changed, 8 insertions(+), 13 deletions(-)
>>
>> diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c
>> index a02cfb9..d56fcc9 100644
>> --- a/fs/xfs/kmem.c
>> +++ b/fs/xfs/kmem.c
>> @@ -65,12 +65,7 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
>>  void *
>>  kmem_zalloc(size_t size, xfs_km_flags_t flags)
>>  {
>> -	void	*ptr;
>> -
>> -	ptr = kmem_alloc(size, flags);
>> -	if (ptr)
>> -		memset((char *)ptr, 0, (int)size);
>> -	return ptr;
>> +	return kmem_alloc(size, flags | KM_ZERO);
>>  }
>>  
>>  void *
>> @@ -132,10 +127,5 @@ kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
>>  void *
>>  kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
>>  {
>> -	void	*ptr;
>> -
>> -	ptr = kmem_zone_alloc(zone, flags);
>> -	if (ptr)
>> -		memset((char *)ptr, 0, kmem_cache_size(zone));
>> -	return ptr;
>> +	return kmem_zone_alloc(zone, flags | KM_ZERO);
>>  }
> 
> These functions should be made static inline functions in kmem.h
> seeing as they are now just a simple wrapper.

Agree. Thanks for your suggestion, I'll follow it.

> 
> Otherwise it's a nice cleanup.

Thanks:)

Regards,
Gu

> 
> Cheers,
> 
> Dave.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-04  2:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-01 10:25 [PATCH] xfs: simplify kmem_{zone_}zalloc Gu Zheng
2013-11-01 20:58 ` Dave Chinner
2013-11-04  2:26   ` Gu Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).