Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e93b629

Browse files
committed
Remove volatile qualifiers from bufmgr.c and freelist.c
Prior to commit 0709b7e, access to variables within a spinlock-protected critical section had to be done through a volatile pointer, but that should no longer be necessary. Review by Andres Freund
1 parent 8004953 commit e93b629

File tree

3 files changed

+59
-65
lines changed

3 files changed

+59
-65
lines changed

src/backend/storage/buffer/bufmgr.c

+47-48
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ int effective_io_concurrency = 0;
9292
int target_prefetch_pages = 0;
9393

9494
/* local state for StartBufferIO and related functions */
95-
static volatile BufferDesc *InProgressBuf = NULL;
95+
static BufferDesc *InProgressBuf = NULL;
9696
static bool IsForInput;
9797

9898
/* local state for LockBufferForCleanup */
99-
static volatile BufferDesc *PinCountWaitBuf = NULL;
99+
static BufferDesc *PinCountWaitBuf = NULL;
100100

101101
/*
102102
* Backend-Private refcount management:
@@ -395,24 +395,24 @@ static Buffer ReadBuffer_common(SMgrRelation reln, char relpersistence,
395395
ForkNumber forkNum, BlockNumber blockNum,
396396
ReadBufferMode mode, BufferAccessStrategy strategy,
397397
bool *hit);
398-
static bool PinBuffer(volatile BufferDesc *buf, BufferAccessStrategy strategy);
399-
static void PinBuffer_Locked(volatile BufferDesc *buf);
400-
static void UnpinBuffer(volatile BufferDesc *buf, bool fixOwner);
398+
static bool PinBuffer(BufferDesc *buf, BufferAccessStrategy strategy);
399+
static void PinBuffer_Locked(BufferDesc *buf);
400+
static void UnpinBuffer(BufferDesc *buf, bool fixOwner);
401401
static void BufferSync(int flags);
402402
static int SyncOneBuffer(int buf_id, bool skip_recently_used);
403-
static void WaitIO(volatile BufferDesc *buf);
404-
static bool StartBufferIO(volatile BufferDesc *buf, bool forInput);
405-
static void TerminateBufferIO(volatile BufferDesc *buf, bool clear_dirty,
403+
static void WaitIO(BufferDesc *buf);
404+
static bool StartBufferIO(BufferDesc *buf, bool forInput);
405+
static void TerminateBufferIO(BufferDesc *buf, bool clear_dirty,
406406
int set_flag_bits);
407407
static void shared_buffer_write_error_callback(void *arg);
408408
static void local_buffer_write_error_callback(void *arg);
409-
static volatile BufferDesc *BufferAlloc(SMgrRelation smgr,
409+
static BufferDesc *BufferAlloc(SMgrRelation smgr,
410410
char relpersistence,
411411
ForkNumber forkNum,
412412
BlockNumber blockNum,
413413
BufferAccessStrategy strategy,
414414
bool *foundPtr);
415-
static void FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln);
415+
static void FlushBuffer(BufferDesc *buf, SMgrRelation reln);
416416
static void AtProcExit_Buffers(int code, Datum arg);
417417
static void CheckForBufferLeaks(void);
418418
static int rnode_comparator(const void *p1, const void *p2);
@@ -663,7 +663,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
663663
BlockNumber blockNum, ReadBufferMode mode,
664664
BufferAccessStrategy strategy, bool *hit)
665665
{
666-
volatile BufferDesc *bufHdr;
666+
BufferDesc *bufHdr;
667667
Block bufBlock;
668668
bool found;
669669
bool isExtend;
@@ -927,7 +927,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
927927
*
928928
* No locks are held either at entry or exit.
929929
*/
930-
static volatile BufferDesc *
930+
static BufferDesc *
931931
BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
932932
BlockNumber blockNum,
933933
BufferAccessStrategy strategy,
@@ -941,7 +941,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
941941
LWLock *oldPartitionLock; /* buffer partition lock for it */
942942
BufFlags oldFlags;
943943
int buf_id;
944-
volatile BufferDesc *buf;
944+
BufferDesc *buf;
945945
bool valid;
946946

947947
/* create a tag so we can lookup the buffer */
@@ -1281,7 +1281,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
12811281
* to acquire the necessary locks; if so, don't mess it up.
12821282
*/
12831283
static void
1284-
InvalidateBuffer(volatile BufferDesc *buf)
1284+
InvalidateBuffer(BufferDesc *buf)
12851285
{
12861286
BufferTag oldTag;
12871287
uint32 oldHash; /* hash value for oldTag */
@@ -1380,7 +1380,7 @@ InvalidateBuffer(volatile BufferDesc *buf)
13801380
void
13811381
MarkBufferDirty(Buffer buffer)
13821382
{
1383-
volatile BufferDesc *bufHdr;
1383+
BufferDesc *bufHdr;
13841384

13851385
if (!BufferIsValid(buffer))
13861386
elog(ERROR, "bad buffer ID: %d", buffer);
@@ -1436,7 +1436,7 @@ ReleaseAndReadBuffer(Buffer buffer,
14361436
BlockNumber blockNum)
14371437
{
14381438
ForkNumber forkNum = MAIN_FORKNUM;
1439-
volatile BufferDesc *bufHdr;
1439+
BufferDesc *bufHdr;
14401440

14411441
if (BufferIsValid(buffer))
14421442
{
@@ -1485,7 +1485,7 @@ ReleaseAndReadBuffer(Buffer buffer,
14851485
* some callers to avoid an extra spinlock cycle.
14861486
*/
14871487
static bool
1488-
PinBuffer(volatile BufferDesc *buf, BufferAccessStrategy strategy)
1488+
PinBuffer(BufferDesc *buf, BufferAccessStrategy strategy)
14891489
{
14901490
Buffer b = BufferDescriptorGetBuffer(buf);
14911491
bool result;
@@ -1547,7 +1547,7 @@ PinBuffer(volatile BufferDesc *buf, BufferAccessStrategy strategy)
15471547
* its state can change under us.
15481548
*/
15491549
static void
1550-
PinBuffer_Locked(volatile BufferDesc *buf)
1550+
PinBuffer_Locked(BufferDesc *buf)
15511551
{
15521552
Buffer b;
15531553
PrivateRefCountEntry *ref;
@@ -1578,7 +1578,7 @@ PinBuffer_Locked(volatile BufferDesc *buf)
15781578
* Those that don't should pass fixOwner = FALSE.
15791579
*/
15801580
static void
1581-
UnpinBuffer(volatile BufferDesc *buf, bool fixOwner)
1581+
UnpinBuffer(BufferDesc *buf, bool fixOwner)
15821582
{
15831583
PrivateRefCountEntry *ref;
15841584
Buffer b = BufferDescriptorGetBuffer(buf);
@@ -1672,7 +1672,7 @@ BufferSync(int flags)
16721672
num_to_write = 0;
16731673
for (buf_id = 0; buf_id < NBuffers; buf_id++)
16741674
{
1675-
volatile BufferDesc *bufHdr = GetBufferDescriptor(buf_id);
1675+
BufferDesc *bufHdr = GetBufferDescriptor(buf_id);
16761676

16771677
/*
16781678
* Header spinlock is enough to examine BM_DIRTY, see comment in
@@ -1707,7 +1707,7 @@ BufferSync(int flags)
17071707
num_written = 0;
17081708
while (num_to_scan-- > 0)
17091709
{
1710-
volatile BufferDesc *bufHdr = GetBufferDescriptor(buf_id);
1710+
BufferDesc *bufHdr = GetBufferDescriptor(buf_id);
17111711

17121712
/*
17131713
* We don't need to acquire the lock here, because we're only looking
@@ -2079,7 +2079,7 @@ BgBufferSync(void)
20792079
static int
20802080
SyncOneBuffer(int buf_id, bool skip_recently_used)
20812081
{
2082-
volatile BufferDesc *bufHdr = GetBufferDescriptor(buf_id);
2082+
BufferDesc *bufHdr = GetBufferDescriptor(buf_id);
20832083
int result = 0;
20842084

20852085
ReservePrivateRefCountEntry();
@@ -2252,7 +2252,7 @@ CheckForBufferLeaks(void)
22522252
void
22532253
PrintBufferLeakWarning(Buffer buffer)
22542254
{
2255-
volatile BufferDesc *buf;
2255+
BufferDesc *buf;
22562256
int32 loccount;
22572257
char *path;
22582258
BackendId backend;
@@ -2324,7 +2324,7 @@ BufmgrCommit(void)
23242324
BlockNumber
23252325
BufferGetBlockNumber(Buffer buffer)
23262326
{
2327-
volatile BufferDesc *bufHdr;
2327+
BufferDesc *bufHdr;
23282328

23292329
Assert(BufferIsPinned(buffer));
23302330

@@ -2346,7 +2346,7 @@ void
23462346
BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum,
23472347
BlockNumber *blknum)
23482348
{
2349-
volatile BufferDesc *bufHdr;
2349+
BufferDesc *bufHdr;
23502350

23512351
/* Do the same checks as BufferGetBlockNumber. */
23522352
Assert(BufferIsPinned(buffer));
@@ -2382,7 +2382,7 @@ BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum,
23822382
* as the second parameter. If not, pass NULL.
23832383
*/
23842384
static void
2385-
FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
2385+
FlushBuffer(BufferDesc *buf, SMgrRelation reln)
23862386
{
23872387
XLogRecPtr recptr;
23882388
ErrorContextCallback errcallback;
@@ -2520,7 +2520,7 @@ RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)
25202520
bool
25212521
BufferIsPermanent(Buffer buffer)
25222522
{
2523-
volatile BufferDesc *bufHdr;
2523+
BufferDesc *bufHdr;
25242524

25252525
/* Local buffers are used only for temp relations. */
25262526
if (BufferIsLocal(buffer))
@@ -2550,7 +2550,7 @@ BufferIsPermanent(Buffer buffer)
25502550
XLogRecPtr
25512551
BufferGetLSNAtomic(Buffer buffer)
25522552
{
2553-
volatile BufferDesc *bufHdr = GetBufferDescriptor(buffer - 1);
2553+
BufferDesc *bufHdr = GetBufferDescriptor(buffer - 1);
25542554
char *page = BufferGetPage(buffer);
25552555
XLogRecPtr lsn;
25562556

@@ -2613,7 +2613,7 @@ DropRelFileNodeBuffers(RelFileNodeBackend rnode, ForkNumber forkNum,
26132613

26142614
for (i = 0; i < NBuffers; i++)
26152615
{
2616-
volatile BufferDesc *bufHdr = GetBufferDescriptor(i);
2616+
BufferDesc *bufHdr = GetBufferDescriptor(i);
26172617

26182618
/*
26192619
* We can make this a tad faster by prechecking the buffer tag before
@@ -2703,7 +2703,7 @@ DropRelFileNodesAllBuffers(RelFileNodeBackend *rnodes, int nnodes)
27032703
for (i = 0; i < NBuffers; i++)
27042704
{
27052705
RelFileNode *rnode = NULL;
2706-
volatile BufferDesc *bufHdr = GetBufferDescriptor(i);
2706+
BufferDesc *bufHdr = GetBufferDescriptor(i);
27072707

27082708
/*
27092709
* As in DropRelFileNodeBuffers, an unlocked precheck should be safe
@@ -2767,7 +2767,7 @@ DropDatabaseBuffers(Oid dbid)
27672767

27682768
for (i = 0; i < NBuffers; i++)
27692769
{
2770-
volatile BufferDesc *bufHdr = GetBufferDescriptor(i);
2770+
BufferDesc *bufHdr = GetBufferDescriptor(i);
27712771

27722772
/*
27732773
* As in DropRelFileNodeBuffers, an unlocked precheck should be safe
@@ -2799,7 +2799,7 @@ PrintBufferDescs(void)
27992799

28002800
for (i = 0; i < NBuffers; ++i)
28012801
{
2802-
volatile BufferDesc *buf = GetBufferDescriptor(i);
2802+
BufferDesc *buf = GetBufferDescriptor(i);
28032803
Buffer b = BufferDescriptorGetBuffer(buf);
28042804

28052805
/* theoretically we should lock the bufhdr here */
@@ -2822,7 +2822,7 @@ PrintPinnedBufs(void)
28222822

28232823
for (i = 0; i < NBuffers; ++i)
28242824
{
2825-
volatile BufferDesc *buf = GetBufferDescriptor(i);
2825+
BufferDesc *buf = GetBufferDescriptor(i);
28262826
Buffer b = BufferDescriptorGetBuffer(buf);
28272827

28282828
if (GetPrivateRefCount(b) > 0)
@@ -2863,7 +2863,7 @@ void
28632863
FlushRelationBuffers(Relation rel)
28642864
{
28652865
int i;
2866-
volatile BufferDesc *bufHdr;
2866+
BufferDesc *bufHdr;
28672867

28682868
/* Open rel at the smgr level if not already done */
28692869
RelationOpenSmgr(rel);
@@ -2955,7 +2955,7 @@ void
29552955
FlushDatabaseBuffers(Oid dbid)
29562956
{
29572957
int i;
2958-
volatile BufferDesc *bufHdr;
2958+
BufferDesc *bufHdr;
29592959

29602960
/* Make sure we can handle the pin inside the loop */
29612961
ResourceOwnerEnlargeBuffers(CurrentResourceOwner);
@@ -3064,7 +3064,7 @@ IncrBufferRefCount(Buffer buffer)
30643064
void
30653065
MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
30663066
{
3067-
volatile BufferDesc *bufHdr;
3067+
BufferDesc *bufHdr;
30683068
Page page = BufferGetPage(buffer);
30693069

30703070
if (!BufferIsValid(buffer))
@@ -3198,7 +3198,7 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
31983198
void
31993199
UnlockBuffers(void)
32003200
{
3201-
volatile BufferDesc *buf = PinCountWaitBuf;
3201+
BufferDesc *buf = PinCountWaitBuf;
32023202

32033203
if (buf)
32043204
{
@@ -3224,7 +3224,7 @@ UnlockBuffers(void)
32243224
void
32253225
LockBuffer(Buffer buffer, int mode)
32263226
{
3227-
volatile BufferDesc *buf;
3227+
BufferDesc *buf;
32283228

32293229
Assert(BufferIsValid(buffer));
32303230
if (BufferIsLocal(buffer))
@@ -3250,7 +3250,7 @@ LockBuffer(Buffer buffer, int mode)
32503250
bool
32513251
ConditionalLockBuffer(Buffer buffer)
32523252
{
3253-
volatile BufferDesc *buf;
3253+
BufferDesc *buf;
32543254

32553255
Assert(BufferIsValid(buffer));
32563256
if (BufferIsLocal(buffer))
@@ -3280,7 +3280,7 @@ ConditionalLockBuffer(Buffer buffer)
32803280
void
32813281
LockBufferForCleanup(Buffer buffer)
32823282
{
3283-
volatile BufferDesc *bufHdr;
3283+
BufferDesc *bufHdr;
32843284

32853285
Assert(BufferIsValid(buffer));
32863286
Assert(PinCountWaitBuf == NULL);
@@ -3392,7 +3392,7 @@ HoldingBufferPinThatDelaysRecovery(void)
33923392
bool
33933393
ConditionalLockBufferForCleanup(Buffer buffer)
33943394
{
3395-
volatile BufferDesc *bufHdr;
3395+
BufferDesc *bufHdr;
33963396

33973397
Assert(BufferIsValid(buffer));
33983398

@@ -3445,7 +3445,7 @@ ConditionalLockBufferForCleanup(Buffer buffer)
34453445
* WaitIO -- Block until the IO_IN_PROGRESS flag on 'buf' is cleared.
34463446
*/
34473447
static void
3448-
WaitIO(volatile BufferDesc *buf)
3448+
WaitIO(BufferDesc *buf)
34493449
{
34503450
/*
34513451
* Changed to wait until there's no IO - Inoue 01/13/2000
@@ -3492,7 +3492,7 @@ WaitIO(volatile BufferDesc *buf)
34923492
* FALSE if someone else already did the work.
34933493
*/
34943494
static bool
3495-
StartBufferIO(volatile BufferDesc *buf, bool forInput)
3495+
StartBufferIO(BufferDesc *buf, bool forInput)
34963496
{
34973497
Assert(!InProgressBuf);
34983498

@@ -3558,8 +3558,7 @@ StartBufferIO(volatile BufferDesc *buf, bool forInput)
35583558
* be 0, or BM_VALID if we just finished reading in the page.
35593559
*/
35603560
static void
3561-
TerminateBufferIO(volatile BufferDesc *buf, bool clear_dirty,
3562-
int set_flag_bits)
3561+
TerminateBufferIO(BufferDesc *buf, bool clear_dirty, int set_flag_bits)
35633562
{
35643563
Assert(buf == InProgressBuf);
35653564

@@ -3590,7 +3589,7 @@ TerminateBufferIO(volatile BufferDesc *buf, bool clear_dirty,
35903589
void
35913590
AbortBufferIO(void)
35923591
{
3593-
volatile BufferDesc *buf = InProgressBuf;
3592+
BufferDesc *buf = InProgressBuf;
35943593

35953594
if (buf)
35963595
{
@@ -3643,7 +3642,7 @@ AbortBufferIO(void)
36433642
static void
36443643
shared_buffer_write_error_callback(void *arg)
36453644
{
3646-
volatile BufferDesc *bufHdr = (volatile BufferDesc *) arg;
3645+
BufferDesc *bufHdr = (BufferDesc *) arg;
36473646

36483647
/* Buffer is pinned, so we can read the tag without locking the spinlock */
36493648
if (bufHdr != NULL)
@@ -3662,7 +3661,7 @@ shared_buffer_write_error_callback(void *arg)
36623661
static void
36633662
local_buffer_write_error_callback(void *arg)
36643663
{
3665-
volatile BufferDesc *bufHdr = (volatile BufferDesc *) arg;
3664+
BufferDesc *bufHdr = (BufferDesc *) arg;
36663665

36673666
if (bufHdr != NULL)
36683667
{

0 commit comments

Comments
 (0)