All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: Replace malloc with alloca in hot path
@ 2012-01-30 19:07 Santosh Jodh
  2012-02-01 16:14 ` Ian Campbell
  0 siblings, 1 reply; 4+ messages in thread
From: Santosh Jodh @ 2012-01-30 19:07 UTC (permalink / raw)
  To: xen-devel; +Cc: ian.campbell

Replace malloc with alloc in hot paths for improved performance.

Signed-off-by: Santosh Jodh <santosh.jodh@citrix.com>

diff -r e2722b24dc09 -r 4952090d35e0 tools/libxc/xc_linux_osdep.c
--- a/tools/libxc/xc_linux_osdep.c	Thu Jan 26 17:43:31 2012 +0000
+++ b/tools/libxc/xc_linux_osdep.c	Mon Jan 30 11:02:32 2012 -0800
@@ -242,7 +242,7 @@ static void *linux_privcmd_map_foreign_b
          * IOCTL_PRIVCMD_MMAPBATCH_V2 is not supported - fall back to
          * IOCTL_PRIVCMD_MMAPBATCH.
          */
-        xen_pfn_t *pfn = malloc(num * sizeof(*pfn));
+        xen_pfn_t *pfn = alloca(num * sizeof(*pfn));
 
         if ( pfn )
         {
@@ -288,8 +288,6 @@ static void *linux_privcmd_map_foreign_b
                 break;
             }
 
-            free(pfn);
-
             if ( rc == -ENOENT && i == num )
                 rc = 0;
             else if ( rc )
@@ -524,7 +522,7 @@ static void *linux_gnttab_grant_map(xc_g
     if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
         domids_stride = 0;
 
-    map = malloc(sizeof(*map) +
+    map = alloca(sizeof(*map) +
                  (count - 1) * sizeof(struct ioctl_gntdev_map_grant_ref));
     if ( map == NULL )
         return NULL;
@@ -598,7 +596,6 @@ static void *linux_gnttab_grant_map(xc_g
     }
 
  out:
-    free(map);
 
     return addr;
 }

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

* Re: [PATCH] perf: Replace malloc with alloca in hot path
  2012-01-30 19:07 [PATCH] perf: Replace malloc with alloca in hot path Santosh Jodh
@ 2012-02-01 16:14 ` Ian Campbell
  2012-02-01 16:19   ` Santosh Jodh
  2012-02-07 18:46   ` Ian Jackson
  0 siblings, 2 replies; 4+ messages in thread
From: Ian Campbell @ 2012-02-01 16:14 UTC (permalink / raw)
  To: Santosh Jodh; +Cc: xen-devel

On Mon, 2012-01-30 at 19:07 +0000, Santosh Jodh wrote:
> Replace malloc with alloc in hot paths for improved performance.

This is a hot path in something like a userspace PV backend which is
frequently mapping guest domain pages, or something like that?

> Signed-off-by: Santosh Jodh <santosh.jodh@citrix.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

> 
> diff -r e2722b24dc09 -r 4952090d35e0 tools/libxc/xc_linux_osdep.c
> --- a/tools/libxc/xc_linux_osdep.c	Thu Jan 26 17:43:31 2012 +0000
> +++ b/tools/libxc/xc_linux_osdep.c	Mon Jan 30 11:02:32 2012 -0800
> @@ -242,7 +242,7 @@ static void *linux_privcmd_map_foreign_b
>           * IOCTL_PRIVCMD_MMAPBATCH_V2 is not supported - fall back to
>           * IOCTL_PRIVCMD_MMAPBATCH.
>           */
> -        xen_pfn_t *pfn = malloc(num * sizeof(*pfn));
> +        xen_pfn_t *pfn = alloca(num * sizeof(*pfn));
>  
>          if ( pfn )
>          {
> @@ -288,8 +288,6 @@ static void *linux_privcmd_map_foreign_b
>                  break;
>              }
>  
> -            free(pfn);
> -
>              if ( rc == -ENOENT && i == num )
>                  rc = 0;
>              else if ( rc )
> @@ -524,7 +522,7 @@ static void *linux_gnttab_grant_map(xc_g
>      if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
>          domids_stride = 0;
>  
> -    map = malloc(sizeof(*map) +
> +    map = alloca(sizeof(*map) +
>                   (count - 1) * sizeof(struct ioctl_gntdev_map_grant_ref));
>      if ( map == NULL )
>          return NULL;
> @@ -598,7 +596,6 @@ static void *linux_gnttab_grant_map(xc_g
>      }
>  
>   out:
> -    free(map);
>  
>      return addr;
>  }

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

* Re: [PATCH] perf: Replace malloc with alloca in hot path
  2012-02-01 16:14 ` Ian Campbell
@ 2012-02-01 16:19   ` Santosh Jodh
  2012-02-07 18:46   ` Ian Jackson
  1 sibling, 0 replies; 4+ messages in thread
From: Santosh Jodh @ 2012-02-01 16:19 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

Yes - that is correct. This is used in the IO path for user mode block backend.

Thanks,
Santosh

-----Original Message-----
From: Ian Campbell 
Sent: Wednesday, February 01, 2012 8:15 AM
To: Santosh Jodh
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] perf: Replace malloc with alloca in hot path

On Mon, 2012-01-30 at 19:07 +0000, Santosh Jodh wrote:
> Replace malloc with alloc in hot paths for improved performance.

This is a hot path in something like a userspace PV backend which is frequently mapping guest domain pages, or something like that?

> Signed-off-by: Santosh Jodh <santosh.jodh@citrix.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

> 
> diff -r e2722b24dc09 -r 4952090d35e0 tools/libxc/xc_linux_osdep.c
> --- a/tools/libxc/xc_linux_osdep.c	Thu Jan 26 17:43:31 2012 +0000
> +++ b/tools/libxc/xc_linux_osdep.c	Mon Jan 30 11:02:32 2012 -0800
> @@ -242,7 +242,7 @@ static void *linux_privcmd_map_foreign_b
>           * IOCTL_PRIVCMD_MMAPBATCH_V2 is not supported - fall back to
>           * IOCTL_PRIVCMD_MMAPBATCH.
>           */
> -        xen_pfn_t *pfn = malloc(num * sizeof(*pfn));
> +        xen_pfn_t *pfn = alloca(num * sizeof(*pfn));
>  
>          if ( pfn )
>          {
> @@ -288,8 +288,6 @@ static void *linux_privcmd_map_foreign_b
>                  break;
>              }
>  
> -            free(pfn);
> -
>              if ( rc == -ENOENT && i == num )
>                  rc = 0;
>              else if ( rc )
> @@ -524,7 +522,7 @@ static void *linux_gnttab_grant_map(xc_g
>      if (flags & XC_GRANT_MAP_SINGLE_DOMAIN)
>          domids_stride = 0;
>  
> -    map = malloc(sizeof(*map) +
> +    map = alloca(sizeof(*map) +
>                   (count - 1) * sizeof(struct ioctl_gntdev_map_grant_ref));
>      if ( map == NULL )
>          return NULL;
> @@ -598,7 +596,6 @@ static void *linux_gnttab_grant_map(xc_g
>      }
>  
>   out:
> -    free(map);
>  
>      return addr;
>  }

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

* Re: [PATCH] perf: Replace malloc with alloca in hot path
  2012-02-01 16:14 ` Ian Campbell
  2012-02-01 16:19   ` Santosh Jodh
@ 2012-02-07 18:46   ` Ian Jackson
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Jackson @ 2012-02-07 18:46 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel, Santosh Jodh

Ian Campbell writes ("Re: [Xen-devel] [PATCH] perf: Replace malloc with alloca in hot path"):
> On Mon, 2012-01-30 at 19:07 +0000, Santosh Jodh wrote:
> > Replace malloc with alloc in hot paths for improved performance.
> 
> This is a hot path in something like a userspace PV backend which is
> frequently mapping guest domain pages, or something like that?
> 
> > Signed-off-by: Santosh Jodh <santosh.jodh@citrix.com>
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>

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

end of thread, other threads:[~2012-02-07 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-30 19:07 [PATCH] perf: Replace malloc with alloca in hot path Santosh Jodh
2012-02-01 16:14 ` Ian Campbell
2012-02-01 16:19   ` Santosh Jodh
2012-02-07 18:46   ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.