On Sun, 24 Feb 2013 11:50:14 +0100, richard -rw- weinberger said:
> On Sun, Feb 24, 2013 at 10:42 AM, Shraddha Kamat <sh200...@gmail.com> wrote:
> > what is the relation between atomic operations and memory alignment ?
> >
> > I read from UTLK that "an unaligned memory access is not atomic"
> >
> > please explain me , I am not able to get the relationship between
> > memory alignment and atomicity of the operation.
>
> Not all CPUs support unaligned memory access, such an access may cause a fault
> which needs to be fixed by the kernel...

There's a more subtle issue - an unaligned access can be split across a cache
line boundary, requiring 2 separate memory accesses to do the read or write.
This can result in CPU A fetching the first half of the variable, CPU B
updating both halves, and then A fetching the second half of the now updated
variable.. This can bite you even on CPUs that support unaligned accesses.

Attachment: pgpaOFflPKynw.pgp
Description: PGP signature

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Reply via email to