From: David Laight <David.Laight@ACULAB.COM>
To: "'Michael J. Baars'" <mjbaars1977.gcc@cyberfiber.eu>,
Andrew Pinski <pinskia@gmail.com>
Cc: GCC Mailing List <gcc@gcc.gnu.org>, LKML <linux-kernel@vger.kernel.org>
Subject: RE: problems with memory allocation and the alignment check
Date: Tue, 23 Feb 2021 11:46:28 +0000 [thread overview]
Message-ID: <bea4697e847e4b5aa548e62e284d56ca@AcuMS.aculab.com> (raw)
In-Reply-To: <d9a2cdcf116ed32874ed02bd6fa60ad899ce5f50.camel@cyberfiber.eu>
> > > I just wrote this little program to demonstrate a possible flaw in both malloc and calloc.
> > >
> > > If I allocate a the simplest memory region from main(), one out of three optimization flags fail.
> > > If I allocate the same region from a function, three out of three optimization flags fail.
> > >
> > > Does someone know if this really is a flaw, and if so, is it a gcc or a kernel flaw?
> >
> > There is no flaw. GCC (kernel, glibc) all assume unaligned accesses
> > on x86 will not cause an exception.
>
> Is this just an assumption or more like a fact? I agree with you that byte aligned is more or less the
> same as unaligned.
They require that such accesses don't cause an exception.
While the misaligned accesses are slightly slower (apart from locked accesses
that cross page boundaries) the cost of avoiding them is typically higher.
This is particularly true for functions like strlen() which are often
called for short strings.
Care does have to be taken to stop strlen() reading across a page boundary.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2021-02-23 11:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-22 9:08 Michael J. Baars
2021-02-22 9:29 ` Andrew Pinski
2021-02-22 9:37 ` Michael J. Baars
2021-02-22 9:41 ` Andrew Pinski
2021-02-22 10:04 ` Michael J. Baars
2021-02-24 7:05 ` Michael J. Baars
2021-02-23 11:46 ` David Laight [this message]
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=bea4697e847e4b5aa548e62e284d56ca@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=gcc@gcc.gnu.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjbaars1977.gcc@cyberfiber.eu \
--cc=pinskia@gmail.com \
/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: link
Be 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
all inboxes | Powered by JetHome®