23d0127096cb ("fs/sync.c: make sync_file_range(2) use WB_SYNC_NONE writeback") claims that sync_file_range(2) syscall was "created for userspace to be able to issue background writeout and so waiting for in-flight IO is undesirable there" and changes the writeback (back) to WB_SYNC_NONE. This claim is only partially true. It is true for users that use the flag SYNC_FILE_RANGE_WRITE by itself, as does PostgreSQL, the user that was the reason for changing to WB_SYNC_NONE writeback. However, that claim is not true for users that use that flag combination SYNC_FILE_RANGE_{WAIT_BEFORE|WRITE|_WAIT_AFTER}. Those users explicitly requested to wait for in-flight IO as well as to writeback of dirty pages. Re-brand that flag combination as SYNC_FILE_RANGE_WRITE_AND_WAIT and use WB_SYNC_ALL writeback to perform the full range sync request.
Unified · Split
| @@ -292,8 +292,14 @@ int sync_file_range(struct file *file, loff_t offset, loff_t nbytes, · 291 unmodified lines | |||
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | if (flags & SYNC_FILE_RANGE_WRITE) { | 294 | if (flags & SYNC_FILE_RANGE_WRITE) { |
| 295 | int sync_mode = WB_SYNC_NONE; | ||
| 296 | |||
| 297 | if ((flags & SYNC_FILE_RANGE_WRITE_AND_WAIT) == | ||
| 298 | SYNC_FILE_RANGE_WRITE_AND_WAIT) | ||
| 299 | sync_mode = WB_SYNC_ALL; | ||
| 300 | |||
| 295 | ret = __filemap_fdatawrite_range(mapping, offset, endbyte, | 301 | ret = __filemap_fdatawrite_range(mapping, offset, endbyte, |
| 296 | WB_SYNC_NONE); | 302 | sync_mode); |
| 297 | if (ret < 0) | 303 | if (ret < 0) |
| 298 | goto out; | 304 | goto out; |
| 299 | } | 305 | } |
| @@ -306,9 +312,9 @@ out: · 6 unmodified lines | |||
| 306 | } | 312 | } |
| 307 | 313 | ||
| 308 | /* | 314 | /* |
| 309 | * sys_sync_file_range() permits finely controlled syncing over a segment of | 315 | * ksys_sync_file_range() permits finely controlled syncing over a segment of |
| 310 | * a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is | 316 | * a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is |
| 311 | * zero then sys_sync_file_range() will operate from offset out to EOF. | 317 | * zero then ksys_sync_file_range() will operate from offset out to EOF. |
| 312 | * | 318 | * |
| 313 | * The flag bits are: | 319 | * The flag bits are: |
| 314 | * | 320 | * |
| @@ -325,7 +331,7 @@ out: · 10 unmodified lines | |||
| 325 | * Useful combinations of the flag bits are: | 331 | * Useful combinations of the flag bits are: |
| 326 | * | 332 | * |
| 327 | * SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE: ensures that all pages | 333 | * SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE: ensures that all pages |
| 328 | * in the range which were dirty on entry to sys_sync_file_range() are placed | 334 | * in the range which were dirty on entry to ksys_sync_file_range() are placed |
| 329 | * under writeout. This is a start-write-for-data-integrity operation. | 335 | * under writeout. This is a start-write-for-data-integrity operation. |
| 330 | * | 336 | * |
| 331 | * SYNC_FILE_RANGE_WRITE: start writeout of all dirty pages in the range which | 337 | * SYNC_FILE_RANGE_WRITE: start writeout of all dirty pages in the range which |
| @@ -337,10 +343,13 @@ out: · 5 unmodified lines | |||
| 337 | * earlier SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE operation to wait | 343 | * earlier SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE operation to wait |
| 338 | * for that operation to complete and to return the result. | 344 | * for that operation to complete and to return the result. |
| 339 | * | 345 | * |
| 340 | * SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER: | 346 | * SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER |
| 347 | * (a.k.a. SYNC_FILE_RANGE_WRITE_AND_WAIT): | ||
| 341 | * a traditional sync() operation. This is a write-for-data-integrity operation | 348 | * a traditional sync() operation. This is a write-for-data-integrity operation |
| 342 | * which will ensure that all pages in the range which were dirty on entry to | 349 | * which will ensure that all pages in the range which were dirty on entry to |
| 343 | * sys_sync_file_range() are committed to disk. | 350 | * ksys_sync_file_range() are written to disk. It should be noted that disk |
| 351 | * caches are not flushed by this call, so there are no guarantees here that the | ||
| 352 | * data will be available on disk after a crash. | ||
| 344 | * | 353 | * |
| 345 | * | 354 | * |
| 346 | * SYNC_FILE_RANGE_WAIT_BEFORE and SYNC_FILE_RANGE_WAIT_AFTER will detect any | 355 | * SYNC_FILE_RANGE_WAIT_BEFORE and SYNC_FILE_RANGE_WAIT_AFTER will detect any |
| @@ -320,6 +320,9 @@ struct fscrypt_key { · 319 unmodified lines | |||
| 320 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 | 320 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 |
| 321 | #define SYNC_FILE_RANGE_WRITE 2 | 321 | #define SYNC_FILE_RANGE_WRITE 2 |
| 322 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 | 322 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 |
| 323 | #define SYNC_FILE_RANGE_WRITE_AND_WAIT (SYNC_FILE_RANGE_WRITE | \ | ||
| 324 | SYNC_FILE_RANGE_WAIT_BEFORE | \ | ||
| 325 | SYNC_FILE_RANGE_WAIT_AFTER) | ||
| 323 | 326 | ||
| 324 | /* | 327 | /* |
| 325 | * Flags for preadv2/pwritev2: | 328 | * Flags for preadv2/pwritev2: |