public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/nsz/mtag] malloc: Change calloc when tagging is disabled
@ 2021-03-04 16:25 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-04 16:25 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d65f2fedcdda4774b9918dd974985002ae171346
commit d65f2fedcdda4774b9918dd974985002ae171346
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Feb 16 17:02:44 2021 +0000
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.
Diff:
---
malloc/malloc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 9002d51d7b..b1ee0f450b 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3591,11 +3591,9 @@ __libc_calloc (size_t n, size_t elem_size)
mchunkptr oldtop;
INTERNAL_SIZE_T sz, oldtopsize;
void *mem;
-#ifndef USE_MTAG
unsigned long clearsize;
unsigned long nclears;
INTERNAL_SIZE_T *d;
-#endif
ptrdiff_t 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;
mchunkptr p = mem2chunk (mem);
+
/* If we are using memory tagging, then we need to set the tags
regardless of MORECORE_CLEARS, so we zero the whole block while
doing so. */
-#ifdef USE_MTAG
- return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
-#else
+ if (__glibc_unlikely (mtag_enabled))
+ return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
+
INTERNAL_SIZE_T csz = chunksize (p);
/* Two optional cases in which clearing not necessary */
@@ -3733,7 +3732,6 @@ __libc_calloc (size_t n, size_t elem_size)
}
return mem;
-#endif
}
/*
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/nsz/mtag] malloc: Change calloc when tagging is disabled
@ 2021-03-19 11:57 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-19 11:57 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=15d1d073d1595202b2be48a3788af5b315602ece
commit 15d1d073d1595202b2be48a3788af5b315602ece
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Feb 16 17:02:44 2021 +0000
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>
Diff:
---
malloc/malloc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 01cf6e9325..0b2aff3768 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3591,11 +3591,9 @@ __libc_calloc (size_t n, size_t elem_size)
mchunkptr oldtop;
INTERNAL_SIZE_T sz, oldtopsize;
void *mem;
-#ifndef USE_MTAG
unsigned long clearsize;
unsigned long nclears;
INTERNAL_SIZE_T *d;
-#endif
ptrdiff_t 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;
mchunkptr p = mem2chunk (mem);
+
/* If we are using memory tagging, then we need to set the tags
regardless of MORECORE_CLEARS, so we zero the whole block while
doing so. */
-#ifdef USE_MTAG
- return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
-#else
+ if (__glibc_unlikely (mtag_enabled))
+ return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
+
INTERNAL_SIZE_T csz = chunksize (p);
/* Two optional cases in which clearing not necessary */
@@ -3733,7 +3732,6 @@ __libc_calloc (size_t n, size_t elem_size)
}
return mem;
-#endif
}
/*
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/nsz/mtag] malloc: Change calloc when tagging is disabled
@ 2021-03-11 17:40 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-11 17:40 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f33e5f9a8301e7905985301b479fc4bc29d0063d
commit f33e5f9a8301e7905985301b479fc4bc29d0063d
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Feb 16 17:02:44 2021 +0000
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>
Diff:
---
malloc/malloc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 01cf6e9325..0b2aff3768 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3591,11 +3591,9 @@ __libc_calloc (size_t n, size_t elem_size)
mchunkptr oldtop;
INTERNAL_SIZE_T sz, oldtopsize;
void *mem;
-#ifndef USE_MTAG
unsigned long clearsize;
unsigned long nclears;
INTERNAL_SIZE_T *d;
-#endif
ptrdiff_t 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;
mchunkptr p = mem2chunk (mem);
+
/* If we are using memory tagging, then we need to set the tags
regardless of MORECORE_CLEARS, so we zero the whole block while
doing so. */
-#ifdef USE_MTAG
- return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
-#else
+ if (__glibc_unlikely (mtag_enabled))
+ return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
+
INTERNAL_SIZE_T csz = chunksize (p);
/* Two optional cases in which clearing not necessary */
@@ -3733,7 +3732,6 @@ __libc_calloc (size_t n, size_t elem_size)
}
return mem;
-#endif
}
/*
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/nsz/mtag] malloc: Change calloc when tagging is disabled
@ 2021-03-11 17:39 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-11 17:39 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f33e5f9a8301e7905985301b479fc4bc29d0063d
commit f33e5f9a8301e7905985301b479fc4bc29d0063d
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue Feb 16 17:02:44 2021 +0000
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>
Diff:
---
malloc/malloc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 01cf6e9325..0b2aff3768 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3591,11 +3591,9 @@ __libc_calloc (size_t n, size_t elem_size)
mchunkptr oldtop;
INTERNAL_SIZE_T sz, oldtopsize;
void *mem;
-#ifndef USE_MTAG
unsigned long clearsize;
unsigned long nclears;
INTERNAL_SIZE_T *d;
-#endif
ptrdiff_t 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;
mchunkptr p = mem2chunk (mem);
+
/* If we are using memory tagging, then we need to set the tags
regardless of MORECORE_CLEARS, so we zero the whole block while
doing so. */
-#ifdef USE_MTAG
- return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
-#else
+ if (__glibc_unlikely (mtag_enabled))
+ return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
+
INTERNAL_SIZE_T csz = chunksize (p);
/* Two optional cases in which clearing not necessary */
@@ -3733,7 +3732,6 @@ __libc_calloc (size_t n, size_t elem_size)
}
return mem;
-#endif
}
/*
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-19 11:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 16:25 [glibc/nsz/mtag] malloc: Change calloc when tagging is disabled Szabolcs Nagy
2021-03-11 17:39 Szabolcs Nagy
2021-03-11 17:40 Szabolcs Nagy
2021-03-19 11:57 Szabolcs Nagy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).