From: Ian Campbell Subject: Re: [PATCH] perf: Replace malloc with alloca in hot path Date: Wed, 1 Feb 2012 16:14:58 +0000 Message-ID: <1328112898.17444.96.camel@zakaz.uk.xensource.com> References: <4952090d35e0cf5deb86.1327950455@REDBLD-XS.ad.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4952090d35e0cf5deb86.1327950455@REDBLD-XS.ad.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Santosh Jodh Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org 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 Acked-by: Ian Campbell > > 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; > }