All of lore.kernel.org
 help / color / mirror / Atom feed
From: Santosh Jodh <santosh.jodh@citrix.com>
To: xen-devel@lists.xensource.com
Cc: ian.campbell@citrix.com
Subject: [PATCH] perf: Replace malloc with alloca in hot path
Date: Mon, 30 Jan 2012 11:07:35 -0800	[thread overview]
Message-ID: <4952090d35e0cf5deb86.1327950455@REDBLD-XS.ad.xensource.com> (raw)

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;
 }

             reply	other threads:[~2012-01-30 19:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-30 19:07 Santosh Jodh [this message]
2012-02-01 16:14 ` [PATCH] perf: Replace malloc with alloca in hot path Ian Campbell
2012-02-01 16:19   ` Santosh Jodh
2012-02-07 18:46   ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4952090d35e0cf5deb86.1327950455@REDBLD-XS.ad.xensource.com \
    --to=santosh.jodh@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.