summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2023-05-19 11:42:06 +0000
committerPeter Eisentraut2023-05-19 11:42:06 +0000
commit4c9deebd37ecbeb1bbf6baaf43bafc2f84b9011b (patch)
tree782bf72e775a72b905a2bb06b4b1f2be0243c754
parent0b8ace8d773257fffeaceda196ed94877c2b74df (diff)
Move mdwriteback() to better place
The previous order in the file didn't make sense and matched neither the header file nor the smgr API. Discussion: https://www.postgresql.org/message-id/flat/22fed8ba-01c3-2008-a256-4ea912d68fab%40enterprisedb.com
-rw-r--r--src/backend/storage/smgr/md.c114
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