@@ -733,63 +733,6 @@ mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
733
733
return true;
734
734
}
735
735
736
- /*
737
- * mdwriteback() -- Tell the kernel to write pages back to storage.
738
- *
739
- * This accepts a range of blocks because flushing several pages at once is
740
- * considerably more efficient than doing so individually.
741
- */
742
- void
743
- mdwriteback (SMgrRelation reln , ForkNumber forknum ,
744
- BlockNumber blocknum , BlockNumber nblocks )
745
- {
746
- Assert ((io_direct_flags & IO_DIRECT_DATA ) == 0 );
747
-
748
- /*
749
- * Issue flush requests in as few requests as possible; have to split at
750
- * segment boundaries though, since those are actually separate files.
751
- */
752
- while (nblocks > 0 )
753
- {
754
- BlockNumber nflush = nblocks ;
755
- off_t seekpos ;
756
- MdfdVec * v ;
757
- int segnum_start ,
758
- segnum_end ;
759
-
760
- v = _mdfd_getseg (reln , forknum , blocknum , true /* not used */ ,
761
- EXTENSION_DONT_OPEN );
762
-
763
- /*
764
- * We might be flushing buffers of already removed relations, that's
765
- * ok, just ignore that case. If the segment file wasn't open already
766
- * (ie from a recent mdwrite()), then we don't want to re-open it, to
767
- * avoid a race with PROCSIGNAL_BARRIER_SMGRRELEASE that might leave
768
- * us with a descriptor to a file that is about to be unlinked.
769
- */
770
- if (!v )
771
- return ;
772
-
773
- /* compute offset inside the current segment */
774
- segnum_start = blocknum / RELSEG_SIZE ;
775
-
776
- /* compute number of desired writes within the current segment */
777
- segnum_end = (blocknum + nblocks - 1 ) / RELSEG_SIZE ;
778
- if (segnum_start != segnum_end )
779
- nflush = RELSEG_SIZE - (blocknum % ((BlockNumber ) RELSEG_SIZE ));
780
-
781
- Assert (nflush >= 1 );
782
- Assert (nflush <= nblocks );
783
-
784
- seekpos = (off_t ) BLCKSZ * (blocknum % ((BlockNumber ) RELSEG_SIZE ));
785
-
786
- FileWriteback (v -> mdfd_vfd , seekpos , (off_t ) BLCKSZ * nflush , WAIT_EVENT_DATA_FILE_FLUSH );
787
-
788
- nblocks -= nflush ;
789
- blocknum += nflush ;
790
- }
791
- }
792
-
793
736
/*
794
737
* mdread() -- Read the specified block from a relation.
795
738
*/
@@ -923,6 +866,63 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
923
866
register_dirty_segment (reln , forknum , v );
924
867
}
925
868
869
+ /*
870
+ * mdwriteback() -- Tell the kernel to write pages back to storage.
871
+ *
872
+ * This accepts a range of blocks because flushing several pages at once is
873
+ * considerably more efficient than doing so individually.
874
+ */
875
+ void
876
+ mdwriteback (SMgrRelation reln , ForkNumber forknum ,
877
+ BlockNumber blocknum , BlockNumber nblocks )
878
+ {
879
+ Assert ((io_direct_flags & IO_DIRECT_DATA ) == 0 );
880
+
881
+ /*
882
+ * Issue flush requests in as few requests as possible; have to split at
883
+ * segment boundaries though, since those are actually separate files.
884
+ */
885
+ while (nblocks > 0 )
886
+ {
887
+ BlockNumber nflush = nblocks ;
888
+ off_t seekpos ;
889
+ MdfdVec * v ;
890
+ int segnum_start ,
891
+ segnum_end ;
892
+
893
+ v = _mdfd_getseg (reln , forknum , blocknum , true /* not used */ ,
894
+ EXTENSION_DONT_OPEN );
895
+
896
+ /*
897
+ * We might be flushing buffers of already removed relations, that's
898
+ * ok, just ignore that case. If the segment file wasn't open already
899
+ * (ie from a recent mdwrite()), then we don't want to re-open it, to
900
+ * avoid a race with PROCSIGNAL_BARRIER_SMGRRELEASE that might leave
901
+ * us with a descriptor to a file that is about to be unlinked.
902
+ */
903
+ if (!v )
904
+ return ;
905
+
906
+ /* compute offset inside the current segment */
907
+ segnum_start = blocknum / RELSEG_SIZE ;
908
+
909
+ /* compute number of desired writes within the current segment */
910
+ segnum_end = (blocknum + nblocks - 1 ) / RELSEG_SIZE ;
911
+ if (segnum_start != segnum_end )
912
+ nflush = RELSEG_SIZE - (blocknum % ((BlockNumber ) RELSEG_SIZE ));
913
+
914
+ Assert (nflush >= 1 );
915
+ Assert (nflush <= nblocks );
916
+
917
+ seekpos = (off_t ) BLCKSZ * (blocknum % ((BlockNumber ) RELSEG_SIZE ));
918
+
919
+ FileWriteback (v -> mdfd_vfd , seekpos , (off_t ) BLCKSZ * nflush , WAIT_EVENT_DATA_FILE_FLUSH );
920
+
921
+ nblocks -= nflush ;
922
+ blocknum += nflush ;
923
+ }
924
+ }
925
+
926
926
/*
927
927
* mdnblocks() -- Get the number of blocks stored in a relation.
928
928
*
0 commit comments