Re: database vacuum from cron hanging

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: alvherre(at)alvh(dot)no-ip(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: database vacuum from cron hanging
Date: 2005-10-12 16:00:15
Message-ID: 2035.1129132815@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> writes:
> bufmgr.s file coming in separate (off-list) email.

Yup, here is the smoking gun! This code in PinBuffer

LockBufHdr_NoHoldoff(buf);
buf->refcount++;
result = (buf->flags & BM_VALID) != 0;
UnlockBufHdr_NoHoldoff(buf);

is translated as

movb $1, %al
cmpb $0,28(%ebx)
jne 1f
lock
xchgb %al,28(%ebx) <-- acquire spinlock
1:
testb %al, %al
jne .L228 <-- (failure case is out-of-line)
.L221:
movl 20(%ebx), %ecx <-- fetch refcount
movw 16(%ebx), %ax
incl %ecx <-- increment refcount
movb $0, 28(%ebx) <-- release spinlock
shrl %eax
movl %ecx, 20(%ebx) <-- store back refcount
andl $1, %eax
movl %eax, %edi

For comparison, gcc 4.0.1 on my Fedora machine produces

movb $1, %al
cmpb $0,28(%ebx)
jne 1f
lock
xchgb %al,28(%ebx) <-- acquire spinlock
1:
testb %al, %al
jne .L117
incl 20(%ebx) <-- increment refcount
movw 16(%ebx), %ax
movb $0, 28(%ebx) <-- release spinlock
movl %eax, %edi
shrl %edi
andl $1, %edi
movl PrivateRefCount, %eax

which is safe.

What we probably need to do is insert some "volatile" qualifiers
to force the compiler to behave better. What happens to the code
if you change PinBuffer to be declared as

static bool
PinBuffer(volatile BufferDesc *buf)

?

regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2005-10-12 16:19:55 Re: database vacuum from cron hanging
Previous Message Kevin Grittner 2005-10-12 15:22:29 Re: database vacuum from cron hanging