mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
malloc: Change calloc when tagging is disabled
When glibc is built with memory tagging support (USE_MTAG) but it is not enabled at runtime (mtag_enabled) then unconditional memset was used even though that can be often avoided. This is for performance when tagging is supported but not enabled. The extra check should have no overhead: tag_new_zero_region already had a runtime check which the compiler can now optimize away. Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
@ -3591,11 +3591,9 @@ __libc_calloc (size_t n, size_t elem_size)
|
|||||||
mchunkptr oldtop;
|
mchunkptr oldtop;
|
||||||
INTERNAL_SIZE_T sz, oldtopsize;
|
INTERNAL_SIZE_T sz, oldtopsize;
|
||||||
void *mem;
|
void *mem;
|
||||||
#ifndef USE_MTAG
|
|
||||||
unsigned long clearsize;
|
unsigned long clearsize;
|
||||||
unsigned long nclears;
|
unsigned long nclears;
|
||||||
INTERNAL_SIZE_T *d;
|
INTERNAL_SIZE_T *d;
|
||||||
#endif
|
|
||||||
ptrdiff_t bytes;
|
ptrdiff_t bytes;
|
||||||
|
|
||||||
if (__glibc_unlikely (__builtin_mul_overflow (n, elem_size, &bytes)))
|
if (__glibc_unlikely (__builtin_mul_overflow (n, elem_size, &bytes)))
|
||||||
@ -3674,12 +3672,13 @@ __libc_calloc (size_t n, size_t elem_size)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mchunkptr p = mem2chunk (mem);
|
mchunkptr p = mem2chunk (mem);
|
||||||
|
|
||||||
/* If we are using memory tagging, then we need to set the tags
|
/* If we are using memory tagging, then we need to set the tags
|
||||||
regardless of MORECORE_CLEARS, so we zero the whole block while
|
regardless of MORECORE_CLEARS, so we zero the whole block while
|
||||||
doing so. */
|
doing so. */
|
||||||
#ifdef USE_MTAG
|
if (__glibc_unlikely (mtag_enabled))
|
||||||
return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
|
return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
|
||||||
#else
|
|
||||||
INTERNAL_SIZE_T csz = chunksize (p);
|
INTERNAL_SIZE_T csz = chunksize (p);
|
||||||
|
|
||||||
/* Two optional cases in which clearing not necessary */
|
/* Two optional cases in which clearing not necessary */
|
||||||
@ -3733,7 +3732,6 @@ __libc_calloc (size_t n, size_t elem_size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user