100 Commits
Author SHA1 Message Date
Wilco Dijkstra a3439ac139 Arm: Remove inline assembler from string-fza.h
Use __uqsub8 since minimum GCC supports it now.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-08-17 15:44:50 +00:00
Wilco Dijkstra c5c47f1b86 benchtests: Increase iterations for strpbrk/strspn
Increase iterations for strpbrk/strspn so they run for at least 0.5s.
Reduce iterations for the much slower wcs* variants since they take over 10s.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-08-17 15:43:52 +00:00
Wilco Dijkstra 17a90edfe5 AArch64: Add ifunc masking tunable
Remove the glibc.cpu.name tunable since it's unused and out of date.
Add support for glibc.cpu.hwcaps to adjust ifunc selection for debugging
and benchmarking.  Only allow disabling of features that are (a) used by
ifuncs, (b) safe to disable to a more generic ifunc without any security
impact.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2026-07-27 13:24:35 +00:00
Wilco Dijkstra cdbefe2f94 string: Improve memchr random test
Add matches before the start to ensure the memchr test checks they do not
result in false matches or missed matches.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-06-18 19:44:31 +00:00
Wilco Dijkstra 368438d8b6 manual: Update memchr description [BZ #19406]
Update memchr description to indicate it cannot overread and the size
may be larger than the object passed.  This is required since C11.

Suggested-by: Paul Eggert <eggert@cs.ucla.edu>
Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
2026-06-17 11:48:50 +00:00
Wilco Dijkstra 49244da110 malloc: Simplify _int_free_chunk
Simplify _int_free_chunk() and always lock if needed.  Use
_int_free_merge_chunk() for cases that assume the arena has been locked
instead.  Move the errno save/restore to _int_free_maybe_trim().

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2026-06-05 13:56:37 +00:00
Wilco Dijkstra 93e6135904 malloc: Reduce maximum arenas
The default maximum arenas is 8 times the number of cores in a 64-bit system.
Since modern CPUs have many cores and big servers have 256 cores, this results
in excessive number of arenas, which wastes memory.  Limit the number of arenas
to max (8, ncores) which is less extreme.  In the future the limit should be
lowered further for large systems.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-06-04 14:25:37 +00:00
Wilco Dijkstra b7e256c32c malloc: Improve documentation of malloc tunables
Update default for tcache_count tunable.  Remove existing documentation and
mention removal of fastbins in mxfast tunable.  Improve wording of hugetlb
tunable, including default for AArch64.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-06-03 13:10:58 +00:00
Wilco Dijkstra 4a7805d05c malloc: Minor cleanups
Merge request2size into checked_request2size.  Improve interface of
clear_memory.  Fix incorrect use of __glibc_unlikely in __libc_calloc.
Fix missing tabs.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2026-06-03 13:10:06 +00:00
Wilco Dijkstra b26cc4fbb7 Arch64: Add support for SVE2 ifuncs
Add support for SVE2 in cpu-features. Minor cleanup of init-arch.h.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2026-05-27 13:21:37 +00:00
Wilco Dijkstra 746a560a62 string: Improve test-memchr page cross checks
The tests for memchr attempt to check for accidental overreads that cross a
page.  However they weren't done at the end of a page and don't check for the
case where we match right at the end.  Add buf1_size/buf2_size to make finding
end of buffer easier.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2026-05-21 16:13:07 +00:00
Wilco Dijkstra 17a79a5120 malloc: Remove dynamic mmap/trim threshold [BZ #30769]
v2: Update documentation

Whenever a large mmap is released the mmap and trim thresholds are updated.
As a result these thresholds grow ever larger which means huge allocations
are always served by arenas rather than mmap.  The thresholds can end up as
large as an arena, which completely stops all trimming of the top block.
Remove the code completely - the default thresholds seem way too low for
modern 64-bit targets, but they can be increased seperately.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-05-18 13:31:00 -03:00
Wilco Dijkstra 02d9614158 malloc: Remove unused aliases for malloc symbols
Malloc defines a lot of aliases which are unused, not exported and not needed.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: DJ Delorie <dj@redhat.com>
2026-04-15 13:31:14 +00:00
Wilco Dijkstra 49ed3efdd3 AArch64: Remove unused MIDR entries
Remove the now unused eMAG MIDR check and unused entries from cpu_list[].

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-04-02 14:14:57 +00:00
Wilco Dijkstra d43c0b008e AArch64: Remove eMAG memset ifunc
As a cleanup remove the eMAG ifunc for memset.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-04-02 14:14:18 +00:00
Wilco Dijkstra 87083d062a AArch64: Remove eMAG memchr ifunc
As a cleanup remove the eMAG ifunc for memchr.

Reviewed-by: JiangNing OS<jiangning@amperemail.onmicrosoft.com>
2026-04-02 14:08:28 +00:00
Wilco Dijkstra e87c151130 malloc: Show hugetlb tunable default in --list-tunables
Update the hugetlb tunable default in elf/dl-tunables.c so it is shown as 1
with /lib/ld-linux-aarch64.so.1 --list-tunables.
Move the intitialization of thp_mode/thp_pagesize to do_set_hugetlb() and
avoid accessing /sys/kernel/mm if DEFAULT_THP_PAGESIZE > 0.  Switch off THP if
glibc.malloc.hugetlb=0 is used - this behaves as if DEFAULT_THP_PAGESIZE==0.
Fix the --list-tunables testcase.

Reviewed-by: DJ Delorie <dj@redhat.com>
2026-04-01 12:22:26 +00:00
Wilco Dijkstra 057e7c9aa1 AArch64: Remove prefer_sve_ifuncs
Remove the prefer_sve_ifuncs CPU feature since it was intended for older
kernels. Current distros all use modern Linux kernels with improved support
for SVE save/restore, making this check redundant.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2026-03-16 19:09:14 +00:00
Wilco Dijkstra 0ea9ebe48a malloc: Cleanup warnings
Cleanup warnings - malloc builds with -Os and -Og without needing any
complex warning avoidance defines.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-03-11 18:30:45 +00:00
Wilco Dijkstra 28882c408c malloc: Improve memalign alignment
Use generic stdc_bit_width to safely adapt to input types. Move rounding up of
alignments that are not powers of 2 to __libc_memalign.  Simplify alignment
handling of aligned_alloc and __posix_memalign. Add a testcase for non-power
of 2 memalign and fix malloc-debug.

Reviewed-by: DJ Delorie <dj@redhat.com>
2026-03-10 12:17:52 +00:00
Wilco Dijkstra 2e8a940df1 malloc: Avoid accessing /sys/kernel/mm files
On AArch64 malloc always checks /sys/kernel/mm/transparent_hugepage/enabled to
set the THP mode.  However this check is quite expensive and the file may not
be accessible in containers. If DEFAULT_THP_PAGESIZE is non-zero, use
malloc_thp_mode_madvise so that we take advantage of THP in all cases.  Since
madvise is a fast systemcall, it adds only a small overhead compared to the
cost of mmap and populating the pages.

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
2026-03-04 14:21:40 +00:00
Wilco Dijkstra d2bbf8aeda AArch64: Improve memset when len is 64
Change the mask to 48 to support len==64. The second memory store now accesses
offset 32, whereas the third one accesses offset 16.  As a result performance
for len==64 almost doubles.
2026-03-03 14:32:42 +00:00
Wilco Dijkstra c37b8d9f34 malloc: Add asserts for malloc assumptions
Currently malloc has various assumptions, some documented, some implicit.
Add a few asserts to check the most fundamental assumptions using verify().
Remove some odd #define void.

Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
2026-03-03 14:31:14 +00:00
Wilco Dijkstra ea4c36c36b malloc: Remove unused tcache code from unsorted bin scan
Now that fastbins have been removed, there is no need to add chunks
to tcache during an unsorted scan.  Small blocks can only be added
to unsorted as a result of a remainder chunk split off a larger block,
so there is no point in checking for additional chunks to place in
tcache.  The last remainder is checked first, and will be used if it
is large enough or an exact fit.  The unsorted bin scan becomes simpler
as a result.  Remove the tcache_unsorted_limit tunable and manual entries.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-02-06 18:20:17 +00:00
Wilco Dijkstra 707658b428 AArch64: Add if('fastmath') to math-vector-fortran.h [BZ #33226]
Only enable vector math functions with -ffast-math by adding if('fastmath').
This uses a new annotation supported by GCC 16 (PR 118955).  If an older
compiler is used, it will disable the math function without an error.
This fixes BZ #33226.
2026-02-03 17:19:19 +00:00
Wilco DijkstraandAdhemerval Zanella 570fc094c3 math: Add __issignaling inline
Add __issignaling inline based on the issignaling_inline implementation.
Improve the __issignalingf inline.  Remove issignaling(f)_inline and its uses.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Co-authored-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2026-02-02 14:34:18 -03:00
Wilco Dijkstra 9da0585852 atomic: Reinstate HAVE_64B_ATOMICS configure check
Reinstate HAVE_64B_ATOMICS configure check that was reverted by commit
7fec8a5de6 due to BZ #33632.  This was
fixed by 3dd2cbfa35 by only allowing
64-bit atomics on sem_t if its type is 8-byte aligned.  Rebase and add
in cleanups in include/atomic.h that were omitted.

Fix an issue with sparcv8-linux-gnu-leon3 forcing -mcpu=v8 for rtld.c which
overrules -mcpu=leon3 and causes __atomic_always_lock_free (4, 0) to
incorrectly return 0 and trigger asserts in atomics.  Remove this as it
seems to be a workaround for an issue in 1997.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-12-17 22:57:00 +00:00
Wilco Dijkstra 1c588a2187 malloc: Improve thp_init
Cleanup thp_init, change it so that the DEFAULT_THP_PAGESIZE
setting can be overridden with glibc.malloc.hugetlb=0 tunable.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-12-17 19:11:01 +00:00
Wilco Dijkstra 83dd79dffb nptl: Check alignment of pthread structs
Report assertion failure if the alignment of external pthread structs is
lower than the internal version.  This triggers on type mismatches like
in BZ #33632.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2025-12-04 15:45:15 +00:00
Wilco Dijkstra 7f670284d8 malloc: Use _int_free_chunk in tcache_thread_shutdown
Directly call _int_free_chunk during tcache shutdown to avoid recursion.
Calling __libc_free on a block from tcache gets flagged as a double free,
and tcache_double_free_verify checks every tcache chunk (quadratic
overhead).

Reviewed-by: Arjun Shankar <arjun@redhat.com>
2025-11-20 12:28:46 +00:00
Wilco Dijkstra 989e538224 math: Remove float_t and double_t [BZ #33563]
Remove uses of float_t and double_t. This is not useful on modern machines,
and does not help given GCC defaults to -fexcess-precision=fast.
One use of double_t remains to allow forcing the precision to double
on targets where FLT_EVAL_METHOD=2. This fixes BZ #33563 on
i486-pc-linux-gnu.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-11-12 19:33:23 +00:00
Wilco Dijkstra 3b7bb7b2f2 math: Remove ldbl-128/s_fma.c
Remove ldbl-128/s_fma.c - it makes no sense to use emulated float128
operations to emulate FMA.  Benchmarking shows dbl-64/s_fma.c is about
twice as fast.  Remove redundant dbl-64/s_fma.c includes in targets
that were trying to work around this issue.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-11-12 18:57:29 +00:00
Wilco DijkstraandAdhemerval Zanella 324c088a18 nptl: Remove ATOMIC_EXCHANGE_USES_CAS usage
The only usage was for pthread_spin_lock, introduced by 12d2dd7060,
as a way to optimize the code for certain architectures. Now that atomic
builtins are used by default, let the compiler use the best code sequence
for the atomic exchange.

Co-authored-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
2025-11-04 04:14:01 -03:00
Wilco DijkstraandAdhemerval Zanella 53807741fb Define __HAVE_64B_ATOMICS from compiler support
Now that atomic builtins are used by default, we can rely on the
compiler to define when to use 64-bit atomic operations.

It allows the use of 64-bit atomic operations on some 32-bit ABIs where
they were not previously enabled due to missing pre-processor handling:
hppa, mips64n32, s390, and sparcv9.

Co-authored-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Reviewed-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
2025-11-04 04:14:01 -03:00
Wilco Dijkstra 1136c036a3 math: Remove xfail from pow test [BZ #33563]
Remove xfail from pow testcase since pow and powf have been fixed.
Also check float128 maximum value.  See BZ #33563.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-31 19:13:53 +00:00
Wilco Dijkstra 0212fc23b0 math: Fix pow special case [BZ #33563]
Fix pow (DBL_MAX, 1.0) to return DBL_MAX when rouding upwards without FMA.
This fixes BZ #33563.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-31 19:13:41 +00:00
Wilco Dijkstra 8917bd3eb3 math: Fix powf special case [BZ #33563]
Fix powf (0x1.fffffep+127, 1.0f) to return 0x1.fffffep+127 when
rouding upwards.  Cleanup the special case code - performance
improves by ~1.2%.  This fixes BZ #33563.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-31 19:12:47 +00:00
Wilco Dijkstra 0375e6e233 AArch64: Use math-use-builtins for roundeven(f)/lrint(f)/lround(f)
Remove target implementations of roundeven(f)/lrint(f)/lround(f) and
use the math-use-builtins mechanism instead.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-17 17:03:54 +00:00
Wilco Dijkstra 35807cc5cd math: Add builtin support for (l)lround(f)
Add builtin support for (l)lround(f) via the math-use-builtins
header mechanism.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-17 17:03:54 +00:00
Wilco Dijkstra e974b1b7eb malloc: Cleanup _int_memalign
Cleanup _int_memalign. Simplify the logic. Add a seperate check
for mmap. Only release the tail chunk if it is at least MINSIZE.
Use the new mmap abstractions.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-17 17:03:54 +00:00
Wilco Dijkstra 88de32a070 malloc: Improve mmap interface
Add mmap_set_chunk() to create a new chunk from an mmap block.
Remove set_mmap_is_hp() since it is done inside mmap_set_chunk().
Rename prev_size_mmap() to mmap_base_offset().  Cleanup comments.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-10-08 12:59:30 +00:00
Wilco Dijkstra adbd3ba137 atomic: Remove atomic_forced_read
Remove the odd atomic_forced_read which is neither atomic nor forced.
Some uses are completely redundant, so simply remove them.  In other cases
the intended use is to force a memory ordering, so use acquire load for those.
In yet other cases their purpose is unclear, for example __nscd_cache_search
appears to allow concurrent accesses to the cache while it is being garbage
collected by another thread!  Use relaxed atomic loads here to block spills
from accidentally reloading memory that is being changed.

Passes regress on AArch64, OK for commit?
2025-10-08 12:59:30 +00:00
Wilco Dijkstra eba46f7077 benchtests: Fix warning in bench-strchr.c
Ensure benchtests compile with trunk GCC.
2025-09-22 12:42:57 +00:00
Wilco Dijkstra 9825f9b823 NEWS: Update with removal of dumped heaps
Support for dumped heaps has been removed - malloc_set_state() now always
returns the error code -1.
2025-09-22 12:42:43 +00:00
Wilco Dijkstra 85c5b504aa malloc: Remove dumped heap support
Remove support for obsolete dumped heaps.  Dumping heaps was discontinued
8 years ago, however loading a dumped heap is still supported. This blocks
changes and improvements of the malloc data structures - hence it is time
to remove this.  Ancient binaries that still call malloc_set_state will now
get the -1 error code.  Update tst-mallocstate.c to just check for this.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-19 13:11:56 +00:00
Wilco Dijkstra aebaeb2c33 AArch64: Update math-vector-fortran.h
Update math-vector-fortran.h with the latest set of math functions
and sort by name.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2025-09-19 12:57:47 +00:00
Wilco Dijkstra 19442c052c malloc: Cleanup libc_realloc
Minor cleanup of libc_realloc: remove unnecessary special cases for mmap, move
ar_ptr initialization, first check for oldmem == NULL.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-09-10 09:18:06 +00:00
Wilco Dijkstra 210ee29503 atomics: Remove unused atomics
Remove all unused atomics.  Replace uses of catomic_increment and
catomic_decrement with atomic_fetch_add_relaxed which maps to a standard
compiler builtin. Relaxed memory ordering is correct for simple counters
since they only need atomicity.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-10 09:18:06 +00:00
Wilco Dijkstra c7b7c80b39 atomic: Switch atomic.h to builtin atomics
Switch to standard builtin atomics by removing the defines for
!USE_ATOMIC_COMPILER_BUILTINS.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:57:59 +00:00
Wilco Dijkstra b568af853b atomic: Switch power to builtin atomics
Switch power to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:57:59 +00:00
Wilco Dijkstra 9c72e0193d atomic: Switch hppa to builtin atomics
Switch hppa to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra 6916b7faf8 atomic: Switch sh to builtin atomics
Switch sh to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra 666c26c243 atomic: Switch microblaze to builtin atomics
Switch microblaze to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra 30108f8b6c atomic: Switch alpha to builtin atomics
Switch alpha to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra 1c48da52bc atomic: Switch m68k to builtin atomics
Switch m68k to builtin atomics.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra 2a035debbb atomic: Use builtin atomics with USE_ATOMIC_COMPILER_BUILTINS
Use builtin atomics for atomic_compare_and_exchange_* and
atomic_exchange_and_add if USE_ATOMIC_COMPILER_BUILTINS is enabled.
This allows removing target atomic-machine.h headers.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-09-09 13:53:54 +00:00
Wilco Dijkstra 921e251e8f malloc: Support hugepages in mremap_chunk
Add mremap_chunk support for mmap()ed chunks using hugepages by accounting for
their alignment, to prevent the mremap call failing in most cases where the
size passed is not a hugepage size multiple. It also improves robustness for
reallocating hugepages since mremap is much less likely to fail, so running
out of memory when reallocating a larger size and having to copy the old
contents after mremap fails is also less likely.

To track whether an mmap()ed chunk uses hugepages, have a flag in the lowest
bit of the mchunk_prev_size field which is set after a call to sysmalloc_mmap,
and accessed later in mremap_chunk. Create macros for getting and setting this
bit, and for mapping the bit off when accessing the field for mmap()ed chunks.
Since the alignment cannot be lower than 8 bytes, this flag cannot affect the
alignment data.

Add malloc/tst-tcfree4-malloc-check to the tests-exclude-malloc-check list as
malloc-check prevents the tcache from being used to store chunks. This test
caused failures due to a bug in mem2chunk_check to be fixed in a later patch.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-08-27 13:07:09 +00:00
Wilco Dijkstra 614cfd0f8a malloc: Change mmap chunk layout
Change the mmap chunk layout to be identical to a normal chunk.  This makes it
safe for tcache to hold mmap chunks and simplifies size calculations in
memsize and musable.  Add mmap_base() and mmap_size() macros to simplify code.

Reviewed-by: Cupertino Miranda <cupertino.miranda@oracle.com>
2025-08-27 11:41:58 +00:00
Wilco Dijkstra 122847e4a2 benchtests: Avoid truncation in random memcpy/memset benchmarks
Use uint16_t rather than uint8_t for the size arrays.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2025-08-12 11:15:58 +00:00
Wilco Dijkstra a5e9269f51 malloc: Fix MALLOC_DEBUG
MALLOC_DEBUG only works on locked arenas, so move the call to
check_inuse_chunk from __libc_free() to _int_free_chunk().
Regress now passes if MALLOC_DEBUG is enabled.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-08-08 14:00:43 +00:00
Wilco Dijkstra 05a14648e9 malloc: Support THP in arenas
Arenas support huge pages but not transparent huge pages.  Add this by
also checking mp_.thp_pagesize when creating a new arena, and use madvise.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-08-08 14:00:11 +00:00
Wilco Dijkstra 94ebcfc4f2 malloc: Remove use of __curbrk
Remove an odd use of __curbrk and use MORECORE (0) instead.
This fixes Hurd build since it doesn't define this symbol.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-08-08 13:59:31 +00:00
Wilco Dijkstra 7ab623afb9 Revert "Remove use of __curbrk."
This reverts commit 1ee0b771a9.
2025-08-04 17:31:56 +00:00
Wilco Dijkstra 91a7726374 Revert "Improve MALLOC_DEBUG"
This reverts commit 4b3e65682d.
2025-08-04 17:31:54 +00:00
Wilco Dijkstra b6f8c0031c Revert "Enable THP on arenas"
This reverts commit 77d3e73936.
2025-08-04 17:31:52 +00:00
Wilco Dijkstra 011ef5b18c Revert "benchtests: Avoid overflow in random memcpy/memset benchmarks"
This reverts commit 09604542d3.
2025-08-04 17:31:51 +00:00
Wilco Dijkstra 3191dda282 Revert "Use _int_free_chunk in tcache_thread_shutdown"
This reverts commit 05ef6a4974.
2025-08-04 17:31:49 +00:00
Wilco Dijkstra f4e402b370 Revert "Remove dumped heap support"
This reverts commit 8f57caa7fd.
2025-08-04 17:31:47 +00:00
Wilco Dijkstra 1bf4a379e8 Revert "malloc: Cleanup libc_realloc"
This reverts commit dea1e52af3.
2025-08-04 17:31:45 +00:00
Wilco Dijkstra 8c2b6e528d Revert "Change mmap representation"
This reverts commit 4b74591022.
2025-08-04 17:31:40 +00:00
Wilco Dijkstra 1ee0b771a9 Remove use of __curbrk. 2025-08-04 17:13:55 +00:00
Wilco Dijkstra 4b3e65682d Improve MALLOC_DEBUG 2025-08-04 17:13:55 +00:00
Wilco Dijkstra 77d3e73936 Enable THP on arenas 2025-08-04 17:13:55 +00:00
Wilco Dijkstra 09604542d3 benchtests: Avoid overflow in random memcpy/memset benchmarks
Use uint16_t rather than uint8_t for the size arrays.
2025-08-04 17:13:55 +00:00
Wilco Dijkstra 05ef6a4974 Use _int_free_chunk in tcache_thread_shutdown 2025-08-04 17:13:55 +00:00
Wilco Dijkstra 8f57caa7fd Remove dumped heap support 2025-08-04 17:13:55 +00:00
Wilco Dijkstra dea1e52af3 malloc: Cleanup libc_realloc
Minor cleanup of libc_realloc: remove unnecessary special cases for mmap, move
ar_ptr initialization, first check for oldmem == NULL.
2025-08-04 17:13:55 +00:00
Wilco Dijkstra 4b74591022 Change mmap representation 2025-08-04 17:13:55 +00:00
Wilco Dijkstra 35a7a7ab99 malloc: Cleanup sysmalloc_mmap
Cleanup sysmalloc_mmap - simplify padding since it is always a constant.
Remove av parameter which is only used in do_check_chunk, but since it may be
NULL for mmap, it will cause a crash in checking mode.  Remove the odd check
on mmap in do_check_chunk.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-08-02 15:21:16 +00:00
Wilco Dijkstra b68b125ad1 malloc: Improve checked_request2size
Change checked_request2size to return SIZE_MAX for huge inputs.  This
ensures large allocation requests stay large and can't be confused with a
small allocation.  As a result several existing checks against PTRDIFF_MAX
become redundant.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-08-02 14:38:35 +00:00
Wilco Dijkstra 21fda179c2 malloc: Cleanup madvise defines
Remove redundant ifdefs for madvise/THP.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-08-02 14:19:50 +00:00
Wilco Dijkstra 2df57ad95c benchtests: Cleanup bench-malloc-thread
Change duration to 3 seconds.  Add spaces before '('.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-08-02 14:18:23 +00:00
Wilco Dijkstra ad4caba414 malloc: Fix MAX_TCACHE_SMALL_SIZE
MAX_TCACHE_SMALL_SIZE should use chunk size since it is used after
checked_request2size.  Increase limit of tcache_max_bytes by 1 since all
comparisons use '<'.  As a result, the last tcache entry is now used as
expected.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-08-02 14:16:24 +00:00
Wilco Dijkstra 089b4fb90f malloc: Remove redundant NULL check
Remove a redundant NULL check from tcache_get_n.

Reviewed-by: Cupertino Miranda <cupertino.miranda@oracle.com>
2025-07-29 14:11:58 +00:00
Wilco Dijkstra f33bb12366 NEWS: Mention tcache improvements
Update NEWS with tcache improvements.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-07-08 16:31:01 +00:00
Wilco Dijkstra 681a24ae4d AArch64: Avoid memset ifunc in cpu-features.c [BZ #33112]
During early startup memcpy or memset must not be called since many targets
use ifuncs for them which won't be initialized yet.  Security hardening may
use -ftrivial-auto-var-init=zero which inserts calls to memset.  Redirect
memset to memset_generic by including dl-symbol-redir-ifunc.h in cpu-features.c.
This fixes BZ #33112.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2025-06-30 13:17:38 +00:00
Wilco Dijkstra 1061b75412 malloc: Cleanup tcache_init()
Cleanup tcache_init() by using the new __libc_malloc2 interface.

Reviewed-by: Cupertino Miranda <cupertino.miranda@oracle.com>
2025-06-26 15:08:17 +00:00
Wilco Dijkstra ba32fd7d04 malloc: Cleanup _mid_memalign
Remove unused 'address' parameter from _mid_memalign and callers.
Fix off-by-one alignment calculation in __libc_pvalloc.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-06-18 13:37:00 +00:00
Wilco Dijkstra 09795c5612 AArch64: Fix builderror with GCC 12.1/12.2
Early versions of GCC 12 didn't support -mtune=neoverse-v2, so use
-mtune=neoverse-v1 instead.

Reported-by: Yury Khrustalev <yury.khrustalev@arm.com>
2025-06-06 13:22:27 +00:00
Wilco Dijkstra 7e10e30e64 malloc: Count tcache entries downwards
Currently tcache requires 2 global variable accesses to determine
whether a block can be added to the tcache.  Change the counts array
to 'num_slots' to indicate the number of entries that could be added.
If 'num_slots' reaches zero, no more blocks can be added.  If the entries
pointer is not NULL, at least one block is available for allocation.

Now each tcache bin can support a different maximum number of entries,
and they can be individually switched on or off (a zero initialized
num_slots+entry means the tcache bin is not available for free or malloc).

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-06-03 17:16:39 +00:00
Wilco Dijkstra aa18367c11 AArch64: Improve enabling of SVE for libmvec
When using a -mcpu option in CFLAGS, GCC can report errors when building libmvec.
Fix this by overriding both -mcpu and -march with a generic variant with SVE added.
Also use a tune for a modern SVE core.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2025-05-29 16:58:49 +00:00
Wilco Dijkstra 919bf1489a malloc: Fix malloc init order
__ptmalloc_init was called too early in __libc_early_init: it uses
__libc_initial which is not set yet.  Fix this by moving initialization
to the end of __libc_early_init.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-05-27 15:25:30 +00:00
Wilco Dijkstra 7ad95d5506 libmvec: Add inputs for asinpi(f), acospi(f), atanpi(f) and atan2pi(f)
Add initial inputs for asinpi(f), acospi(f), atanpi(f) and atan2pi(f) based
on existing asin/acos/atan inputs.

Benchtests now works on the new libmvec function.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2025-05-23 11:27:44 +00:00
Wilco Dijkstra 2071666d03 AArch64: Fix typo in math-vector.h
Fix typo atanpi2->atan2pi in math-vector.h.
2025-05-20 13:44:16 +00:00
Wilco Dijkstra b990b0aee2 AArch64: Cleanup SVE config and defines
Now we finally support modern GCC and binutils, it's time for a cleanup.
Remove HAVE_AARCH64_SVE_ASM define and conditional compilation.  Remove SVE
configure checks for SVE, ACLE and variant-PCS support.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2025-05-20 10:33:55 +00:00
Wilco Dijkstra 2c421fc430 AArch64: Cleanup PAC and BTI
Now we finally support modern GCC and binutils, it's time for a cleanup.
Use PAC and BTI instructions unconditionally and use proper assembler syntax.
Remove the PR target/94791 strip_pac workarounds for buggy GCCs.  Remove the
PAC/BTI configure checks - always emit GNU property notes on assembly files.
Change cfi_window_save to the correct cfi_negate_ra_state unwind directive.

Reviewed-by: Matthieu Longo <matthieu.longo@arm.com>
2025-05-19 15:35:32 +00:00
Wilco Dijkstra 36189c76fb malloc: Improve performance of __libc_calloc
Improve performance of __libc_calloc by splitting it into 2 parts: first handle
the tcache fastpath, then do the rest in a separate tailcalled function.
This results in significant performance gains since __libc_calloc doesn't need
to setup a frame.

On Neoverse V2, bench-calloc-simple improves by 5.0% overall.
Bench-calloc-thread 1 improves by 24%.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-05-14 09:22:32 +00:00
Wilco Dijkstra 25d37948c9 malloc: Improve malloc initialization
Move malloc initialization to __libc_early_init.  Use a hidden __ptmalloc_init
for initialization and a weak call to avoid pulling in the system malloc in a
static binary.  All previous initialization checks can now be removed.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2025-05-12 16:10:28 +00:00
Wilco Dijkstra 5d10174581 malloc: Inline tcache_try_malloc
Inline tcache_try_malloc into calloc since it is the only caller.  Also fix
usize2tidx and use it in __libc_malloc, __libc_calloc and _mid_memalign.
The result is simpler, cleaner code.

Reviewed-by: DJ Delorie <dj@redhat.com>
2025-05-01 20:01:53 +00:00
Wilco Dijkstra c968fe5062 malloc: Use tailcalls in __libc_free
Use tailcalls to avoid the overhead of a frame on the free fastpath.
Move tcache initialization to _int_free_chunk().  Add malloc_printerr_tail()
which can be tailcalled without forcing a frame like no-return functions.
Change tcache_double_free_verify() to retry via __libc_free() after clearing
the key.

Reviewed-by: Florian Weimer  <fweimer@redhat.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-04-15 11:14:58 +00:00