diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-05-10 20:38:49 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-05-10 20:38:49 +0000 |
commit | 642107d5baa06c21bc9d9a937e4710008e4826a9 (patch) | |
tree | 2d4cef5702ca144fb89c0e131b3fcbb598a9f3dc /src/backend/storage/buffer/bufmgr.c | |
parent | a26ad8a643d4ae44be16a773e19f7ae32df048ac (diff) | |
download | postgresql-642107d5baa06c21bc9d9a937e4710008e4826a9.tar.gz postgresql-642107d5baa06c21bc9d9a937e4710008e4826a9.zip |
Avoid unnecessary lseek() calls by cleanups in md.c. mdfd_lstbcnt was
not being consulted anywhere, so remove it and remove the _mdnblocks()
calls that were used to set it. Change smgrextend interface to pass in
the target block number (ie, current file length) --- the caller always
knows this already, having already done smgrnblocks(), so it's silly to
do it over again inside mdextend. Net result: extension of a file now
takes one lseek(SEEK_END) and a write(), not three lseeks and a write.
Diffstat (limited to 'src/backend/storage/buffer/bufmgr.c')
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 45dcdaed6a9..b8d3e51b5d5 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.109 2001/03/22 03:59:44 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.110 2001/05/10 20:38:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -173,9 +173,9 @@ ReadBufferWithBufferLock(Relation reln, bool bufferLockHeld) { BufferDesc *bufHdr; - int extend; /* extending the file by one block */ int status; bool found; + bool extend; /* extending the file by one block */ bool isLocalBuf; extend = (blockNum == P_NEW); @@ -207,21 +207,13 @@ ReadBufferWithBufferLock(Relation reln, /* if it's already in the buffer pool, we're done */ if (found) { - /* - * This happens when a bogus buffer was returned previously and is - * floating around in the buffer pool. A routine calling this - * would want this extended. + * Could see found && extend if a buffer was already created for + * the next page position, but then smgrextend failed to write + * the page. Must fall through and try to extend file again. */ - if (extend) - { - /* new buffers are zero-filled */ - MemSet((char *) MAKE_PTR(bufHdr->data), 0, BLCKSZ); - smgrextend(DEFAULT_SMGR, reln, - (char *) MAKE_PTR(bufHdr->data)); - } - return BufferDescriptorGetBuffer(bufHdr); - + if (!extend) + return BufferDescriptorGetBuffer(bufHdr); } /* @@ -232,17 +224,25 @@ ReadBufferWithBufferLock(Relation reln, { /* new buffers are zero-filled */ MemSet((char *) MAKE_PTR(bufHdr->data), 0, BLCKSZ); - status = smgrextend(DEFAULT_SMGR, reln, + status = smgrextend(DEFAULT_SMGR, reln, bufHdr->tag.blockNum, (char *) MAKE_PTR(bufHdr->data)); } else { - status = smgrread(DEFAULT_SMGR, reln, blockNum, + status = smgrread(DEFAULT_SMGR, reln, bufHdr->tag.blockNum, (char *) MAKE_PTR(bufHdr->data)); } if (isLocalBuf) + { + /* No shared buffer state to update... */ + if (status == SM_FAIL) + { + bufHdr->flags |= BM_IO_ERROR; + return InvalidBuffer; + } return BufferDescriptorGetBuffer(bufHdr); + } /* lock buffer manager again to update IO IN PROGRESS */ SpinAcquire(BufMgrLock); @@ -302,13 +302,11 @@ BufferAlloc(Relation reln, *buf2; BufferTag newTag; /* identity of requested block */ bool inProgress; /* buffer undergoing IO */ - bool newblock = FALSE; /* create a new tag so we can lookup the buffer */ /* assume that the relation is already open */ if (blockNum == P_NEW) { - newblock = TRUE; blockNum = smgrnblocks(DEFAULT_SMGR, reln); } @@ -1102,7 +1100,8 @@ BufferReplace(BufferDesc *bufHdr) /* * RelationGetNumberOfBlocks - * Returns the buffer descriptor associated with a page in a relation. + * Determines the current number of pages in the relation. + * Side effect: relation->rd_nblocks is updated. * * Note: * XXX may fail for huge relations. @@ -1112,9 +1111,16 @@ BufferReplace(BufferDesc *bufHdr) BlockNumber RelationGetNumberOfBlocks(Relation relation) { - return ((relation->rd_myxactonly) ? relation->rd_nblocks : - ((relation->rd_rel->relkind == RELKIND_VIEW) ? 0 : - smgrnblocks(DEFAULT_SMGR, relation))); + /* + * relation->rd_nblocks should be accurate already if the relation + * is myxactonly. (XXX how safe is that really?) Don't call smgr + * on a view, either. + */ + if (relation->rd_rel->relkind == RELKIND_VIEW) + relation->rd_nblocks = 0; + else if (!relation->rd_myxactonly) + relation->rd_nblocks = smgrnblocks(DEFAULT_SMGR, relation); + return relation->rd_nblocks; } /* --------------------------------------------------------------------- |