Re: sinval synchronization considered harmful

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: sinval synchronization considered harmful
Дата
Msg-id CA+TgmobXqaqx7g52uH4F+VVwcmvTd9L-ZjzdT4FTvCgTvUARYg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: sinval synchronization considered harmful  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Ответы Re: sinval synchronization considered harmful
Re: sinval synchronization considered harmful
Список pgsql-hackers
On Thu, Jul 21, 2011 at 12:16 PM, Kevin Grittner
<Kevin.Grittner@wicourts.gov> wrote:
> Very impressive!  Those numbers definitely justify some #ifdef code
> to provide alternatives for weak memory ordering machines versus
> others.  With the number of CPUs climbing as it is, this is very
> important work!

Thanks.  I'm not thinking so much about #ifdef (although that could
work, too) as I am about providing some primitives to allow this sort
of code-writing to be done in a somewhat less ad-hoc fashion.  It
seems like there are basically two categories of machines we need to
worry about.

1. Machines with strong memory ordering.  On this category of machines
(which include x86), the CPU basically does not perform loads or
stores out of order.  On some of these machines, it is apparently
possible for there to be some ordering of stores relative to loads,
but if the program stores two values or loads two values, those
operations will performed in the same order they appear in the
program.  The main thing you need to make your code work reliably on
these machines is a primitive that keeps the compiler from reordering
your code during optimization.  On x86, certain categories of exotic
instructions do require

2. Machines with weak memory ordering.  On this category of machines
(which includes PowerPC, Dec Alpha, and maybe some others), the CPU
reorders memory accesses arbitrarily unless you explicitly issue
instructions that enforce synchronization.  You still need to keep the
compiler from moving things around, too.  Alpha is particularly
pernicious, because something like a->b can fetch the pointed-to value
before loading the pointer itself.  This is otherwise known as "we
have basically no cache coherency circuits on this chip at all".  On
these machines, you need to issue an explicit memory barrier
instruction at each sequence point, or just acquire and release a
spinlock.

So you can imagine a primitive that is defined to be a compiler
barrier on machines with strong memory ordering, and as a memory
fencing instruction on machines with weak memory ordering.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: Policy on pulling in code from other projects?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: sinval synchronization considered harmful