diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/storage/smgr/md.c | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 3d955aa72b3..42e35012552 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -734,63 +734,6 @@ mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum) } /* - * mdwriteback() -- Tell the kernel to write pages back to storage. - * - * This accepts a range of blocks because flushing several pages at once is - * considerably more efficient than doing so individually. - */ -void -mdwriteback(SMgrRelation reln, ForkNumber forknum, - BlockNumber blocknum, BlockNumber nblocks) -{ - Assert((io_direct_flags & IO_DIRECT_DATA) == 0); - - /* - * Issue flush requests in as few requests as possible; have to split at - * segment boundaries though, since those are actually separate files. - */ - while (nblocks > 0) - { - BlockNumber nflush = nblocks; - off_t seekpos; - MdfdVec *v; - int segnum_start, - segnum_end; - - v = _mdfd_getseg(reln, forknum, blocknum, true /* not used */ , - EXTENSION_DONT_OPEN); - - /* - * We might be flushing buffers of already removed relations, that's - * ok, just ignore that case. If the segment file wasn't open already - * (ie from a recent mdwrite()), then we don't want to re-open it, to - * avoid a race with PROCSIGNAL_BARRIER_SMGRRELEASE that might leave - * us with a descriptor to a file that is about to be unlinked. - */ - if (!v) - return; - - /* compute offset inside the current segment */ - segnum_start = blocknum / RELSEG_SIZE; - - /* compute number of desired writes within the current segment */ - segnum_end = (blocknum + nblocks - 1) / RELSEG_SIZE; - if (segnum_start != segnum_end) - nflush = RELSEG_SIZE - (blocknum % ((BlockNumber) RELSEG_SIZE)); - - Assert(nflush >= 1); - Assert(nflush <= nblocks); - - seekpos = (off_t) BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)); - - FileWriteback(v->mdfd_vfd, seekpos, (off_t) BLCKSZ * nflush, WAIT_EVENT_DATA_FILE_FLUSH); - - nblocks -= nflush; - blocknum += nflush; - } -} - -/* * mdread() -- Read the specified block from a relation. */ void @@ -924,6 +867,63 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, } /* + * mdwriteback() -- Tell the kernel to write pages back to storage. + * + * This accepts a range of blocks because flushing several pages at once is + * considerably more efficient than doing so individually. + */ +void +mdwriteback(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, BlockNumber nblocks) +{ + Assert((io_direct_flags & IO_DIRECT_DATA) == 0); + + /* + * Issue flush requests in as few requests as possible; have to split at + * segment boundaries though, since those are actually separate files. + */ + while (nblocks > 0) + { + BlockNumber nflush = nblocks; + off_t seekpos; + MdfdVec *v; + int segnum_start, + segnum_end; + + v = _mdfd_getseg(reln, forknum, blocknum, true /* not used */ , + EXTENSION_DONT_OPEN); + + /* + * We might be flushing buffers of already removed relations, that's + * ok, just ignore that case. If the segment file wasn't open already + * (ie from a recent mdwrite()), then we don't want to re-open it, to + * avoid a race with PROCSIGNAL_BARRIER_SMGRRELEASE that might leave + * us with a descriptor to a file that is about to be unlinked. + */ + if (!v) + return; + + /* compute offset inside the current segment */ + segnum_start = blocknum / RELSEG_SIZE; + + /* compute number of desired writes within the current segment */ + segnum_end = (blocknum + nblocks - 1) / RELSEG_SIZE; + if (segnum_start != segnum_end) + nflush = RELSEG_SIZE - (blocknum % ((BlockNumber) RELSEG_SIZE)); + + Assert(nflush >= 1); + Assert(nflush <= nblocks); + + seekpos = (off_t) BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)); + + FileWriteback(v->mdfd_vfd, seekpos, (off_t) BLCKSZ * nflush, WAIT_EVENT_DATA_FILE_FLUSH); + + nblocks -= nflush; + blocknum += nflush; + } +} + +/* * mdnblocks() -- Get the number of blocks stored in a relation. * * Important side effect: all active segments of the relation are opened |