public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] cheri: malloc: Use memcpy for obstack internal copy Date: Mon, 9 Jan 2023 11:17:44 +0000 (GMT) [thread overview] Message-ID: <20230109111744.448BC3858D20@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=807b692012ae921ac388cb2ea852645ee2ce4027 commit 807b692012ae921ac388cb2ea852645ee2ce4027 Author: Szabolcs Nagy <szabolcs.nagy@arm.com> Date: Thu Jan 5 18:12:36 2023 +0000 cheri: malloc: Use memcpy for obstack internal copy Internally obstack used a backward word at a time copy. This can be an aliasing violation and likely slower than memcpy on most targets. The code is a badly written memcpy with performance issues such as the h->object_base indirection cannot be hoisted out of the loop. On CHERI architecture this is needed for copying pointers correctly. Diff: --- malloc/obstack.c | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/malloc/obstack.c b/malloc/obstack.c index aad6a34f58..2056a5fe9f 100644 --- a/malloc/obstack.c +++ b/malloc/obstack.c @@ -57,6 +57,7 @@ # include <stdint.h> +# include <string.h> /* Determine default alignment. */ union fooround @@ -79,15 +80,6 @@ enum DEFAULT_ROUNDING = sizeof (union fooround) }; -/* When we copy a long block of data, this is the unit to do it with. - On some machines, copying successive ints does not work; - in such a case, redefine COPYING_UNIT to 'long' (if that works) - or 'char' as a last resort. */ -# ifndef COPYING_UNIT -# define COPYING_UNIT int -# endif - - /* The functions allocating more room by calling 'obstack_chunk_alloc' jump to the handler pointed to by 'obstack_alloc_failed_handler'. This can be set to a user defined function which should either @@ -273,25 +265,8 @@ _obstack_newchunk (struct obstack *h, int length) object_base = __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask); - /* Move the existing object to the new chunk. - Word at a time is fast and is safe if the object - is sufficiently aligned. */ - if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT) - { - for (i = obj_size / sizeof (COPYING_UNIT) - 1; - i >= 0; i--) - ((COPYING_UNIT *) object_base)[i] - = ((COPYING_UNIT *) h->object_base)[i]; - /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT, - but that can cross a page boundary on a machine - which does not do strict alignment for COPYING_UNITS. */ - already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT); - } - else - already = 0; - /* Copy remaining bytes one by one. */ - for (i = already; i < obj_size; i++) - object_base[i] = h->object_base[i]; + /* Move the existing object to the new chunk. */ + memcpy (object_base, h->object_base, obj_size); /* If the object just copied was the only data in OLD_CHUNK, free that chunk and remove it from the chain.
reply other threads:[~2023-01-09 11:17 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230109111744.448BC3858D20@sourceware.org \ --to=nsz@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).