This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC PATCH]: Align large allocations to cacheline
- From: Will Newton <will dot newton at linaro dot org>
- To: Wilco Dijkstra <wdijkstr at arm dot com>
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Wed, 29 Oct 2014 14:05:39 +0000
- Subject: Re: [RFC PATCH]: Align large allocations to cacheline
- Authentication-results: sourceware.org; auth=none
- References: <002301cff37e$61c12330$25436990$ at com>
On 29 October 2014 13:43, Wilco Dijkstra <wdijkstr@arm.com> wrote:
> This patch aligns allocations of large blocks to a cacheline on ARM and AArch64. The main goal is to
> reduce performance variations due to random alignment choices, however it improves performance on
> several benchmarks as well. SPECFP2000 improves by ~1.5%.
>
> Any comments?
This bug may be relevant to changing malloc alignments:
https://sourceware.org/bugzilla/show_bug.cgi?id=6527
I don't know precisely what the issue is with malloc_get_state so I am
not sure if it applies here.
> ChangeLog:
> 2014-10-29 Wilco Dijkstra <wdijkstr@arm.com>
>
> * malloc/malloc.c (__libc_malloc): Add support for aligning large blocks.
I think this should be:
malloc/malloc.c (__libc_malloc) [MALLOC_LARGE_BLOCK_ALIGN]: Add
support for aligning large blocks.
Although I am not a GNU ChangeLog expert...
> * sysdeps/unix/sysv/linux/aarch64/malloc-sysdep.h: New file.
> New defines (MALLOC_LARGE_BLOCK_ALIGN), (MALLOC_LARGE_BLOCK_SIZE).
"New file." should be sufficient.
> * sysdeps/unix/sysv/linux/arm/malloc-sysdep.h: Likewise.
>
> ---
> malloc/malloc.c | 8 ++++++++
> sysdeps/unix/sysv/linux/aarch64/malloc-sysdep.h | 23 +++++++++++++++++++++++
> sysdeps/unix/sysv/linux/arm/malloc-sysdep.h | 23 +++++++++++++++++++++++
> 3 files changed, 54 insertions(+)
> create mode 100644 sysdeps/unix/sysv/linux/aarch64/malloc-sysdep.h
> create mode 100644 sysdeps/unix/sysv/linux/arm/malloc-sysdep.h
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 6cbe9f3..0b0466e 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -2878,6 +2878,14 @@ __libc_malloc (size_t bytes)
> mstate ar_ptr;
> void *victim;
>
> +#ifdef MALLOC_LARGE_BLOCK_ALIGN
> + if (bytes > MALLOC_LARGE_BLOCK_SIZE)
> + {
> + void *address = RETURN_ADDRESS (0);
> + return _mid_memalign (MALLOC_LARGE_BLOCK_ALIGN, bytes, address);
> + }
> +#endif
> +
This will change the behaviour of malloc hooks i.e. the malloc hook
will not get triggered but memalign will.
> void *(*hook) (size_t, const void *)
> = atomic_forced_read (__malloc_hook);
> if (__builtin_expect (hook != NULL, 0))
> diff --git a/sysdeps/unix/sysv/linux/aarch64/malloc-sysdep.h
> b/sysdeps/unix/sysv/linux/aarch64/malloc-sysdep.h
> new file mode 100644
> index 0000000..3fe9f72
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/malloc-sysdep.h
> @@ -0,0 +1,23 @@
> +/* System-specific malloc support functions. AArch64 version.
> + Copyright (C) 2012-2014 Free Software Foundation, Inc.
These copyright lines are wrong, but the whole copy of the LGPL could
probably be dropped with the file being so simple.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <http://www.gnu.org/licenses/>. */
> +
> +#define MALLOC_LARGE_BLOCK_ALIGN (64)
> +#define MALLOC_LARGE_BLOCK_SIZE (16384)
> +
> +#include_next <malloc-sysdep.h>
> +
> diff --git a/sysdeps/unix/sysv/linux/arm/malloc-sysdep.h
> b/sysdeps/unix/sysv/linux/arm/malloc-sysdep.h
> new file mode 100644
> index 0000000..3fe9f72
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/arm/malloc-sysdep.h
> @@ -0,0 +1,23 @@
> +/* System-specific malloc support functions. AArch64 version.
> + Copyright (C) 2012-2014 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <http://www.gnu.org/licenses/>. */
> +
> +#define MALLOC_LARGE_BLOCK_ALIGN (64)
> +#define MALLOC_LARGE_BLOCK_SIZE (16384)
> +
> +#include_next <malloc-sysdep.h>
> +
> --
> 1.7.9.5
>
>
--
Will Newton
Toolchain Working Group, Linaro