forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit643c27e
committed
Increase distance between flush requests during bulk file copies.
copy_file() reads and writes data 64KB at a time (with default BLCKSZ),and historically has issued a pg_flush_data request after each write.This turns out to interact really badly with macOS's new APFS filesystem: a large file copy takes over 100X longer than it ought to onAPFS, as reported by Brent Dearth. While that's arguably a macOS bug,it's not clear whether Apple will do anything about it in the nearfuture, and in any case experimentation suggests that issuing flushesa bit less often can be helpful on other platforms too.Hence, rearrange the logic in copy_file() so that flush requests areissued once per N writes rather than every time through the loop.I set the FLUSH_DISTANCE to 32MB on macOS (any less than that stillresults in a noticeable speed degradation on APFS), but 1MB elsewhere.In limited testing on Linux and FreeBSD, this seems slightly fasterthan the previous code, and certainly no worse. It helps noticeablyon macOS even with the older HFS filesystem.A simpler change would have been to just increase the size of thecopy buffer without changing the loop logic, but that seems likelyto trash the processor cache without really helping much.Back-patch to 9.6 where we introduced msync() as an implementationoption for pg_flush_data(). The problem seems specific to APFS'smmap/msync support, so I don't think we need to go further back.Discussion:https://postgr.es/m/CADkxhTNv-j2jw2g8H57deMeAbfRgYBoLmVuXkC=YCFBXRuCOww@mail.gmail.com1 parent8ec5429 commit643c27e
1 file changed
+30
-8
lines changedLines changed: 30 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
139 | 139 |
| |
140 | 140 |
| |
141 | 141 |
| |
| 142 | + | |
142 | 143 |
| |
143 |
| - | |
| 144 | + | |
144 | 145 |
| |
145 | 146 |
| |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
146 | 160 |
| |
147 | 161 |
| |
148 | 162 |
| |
| |||
163 | 177 |
| |
164 | 178 |
| |
165 | 179 |
| |
| 180 | + | |
166 | 181 |
| |
167 | 182 |
| |
168 | 183 |
| |
169 | 184 |
| |
170 | 185 |
| |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
171 | 197 |
| |
172 | 198 |
| |
173 | 199 |
| |
| |||
190 | 216 |
| |
191 | 217 |
| |
192 | 218 |
| |
193 |
| - | |
194 |
| - | |
195 |
| - | |
196 |
| - | |
197 |
| - | |
198 |
| - | |
199 |
| - | |
200 | 219 |
| |
201 | 220 |
| |
| 221 | + | |
| 222 | + | |
| 223 | + | |
202 | 224 |
| |
203 | 225 |
| |
204 | 226 |
| |
|
0 commit comments
Comments
(0)