aio: Async fsyncs for crash recovery and checkpointer
Thread notes
1 note#performance#moderate#enhancement
hackorum-bot#performance#moderate#enhancement
@global #performance #moderate #enhancement
Hi,
This patch implements async fsyncs for crash recovery and checkpoints
by using the AIO system. I got the idea from Andres' older work [1]https://github.com/anarazel/postgres/commit/9829a1f18176e572759ecf8b8bb99205a71a476f https://github.com/anarazel/postgres/commit/2e180547aef6fe2a409cc144e04cbc2f0a607bed.
----------
High level design and implementation details:
- Since there is no interface like read-stream for the fsyncs, each
user has its own AIO functions like register_one(), drain_one() and
drain_all().
- Number of in-flight I/Os are determined by
GetFsyncConcurrencyLimit(). It uses both io_max_concurrency and the
file descriptor budget to determine max number of available in-flight
fsync I/Os.
- I/O workers need re-open files to do async I/O. Some targets open
files by path (for example, SyncDataDirectory()). This path needs to
be copied to shared memory so that worker processes can re-open these
files. However, adding 'char path[MAXPGPATH]' to PgAioTargetData seems
overkill because of the size; so it is not implemented for now. I am
open to suggestions.
----------
Patches:
- 0001 is just a base patch for adding fsync support to the AIO
system. There is no user of this patch yet.
- 0002 makes SyncDataDirectory() use async fsyncs. Its files are
identified only by path; I/O workers cannot re-open them. So, this
path is asynchronous with io_uring, while worker behaves like sync.
pre_sync_fname() doesn't use AIO because it is already very fast, less
than 1/1000 of of datadir_fsync_fname() time in my benchmarks.
- 0003 makes ProcessSyncRequests() use async fsyncs. Its files use the
smgr target and can be re-opened by an I/O worker, so both worker and
io_uring can execute these fsyncs asynchronously.
- 0004 adds a FileTag-based target for SLRU files. This gives I/O
workers enough information to re-open SLRU segments, so they can use
async fsyncs in the worker mode.
- benchmark-repro.sh is a benchmark script that I used.
----------
Benchmark:
I used a simple benchmark script generated by an LLM. I checked the
script, and it works correctly. The numbers below use the default
settings + the following:
```
checkpoint_timeout = '1h'
max_wal_size = '32GB'
checkpoint_flush_after = 0
bgwriter_lru_maxpages = 0
autovacuum = off
```
io_min_workers, io_max_workers and io_max_concurrency are default in
[2]: io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 94.1 | 1.00x worker | 67.1 | 1.40x io_uring | 57.1 | 1.65x
benchmark [3]io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 97.3 | 1.00x worker | 48.7 | 2.00x io_uring | 37.4 | 2.60x.
You can run the attached benchmark script by './benchmark-repro.sh
{--syncdatadirectory, --checkpointer, --slru}' command.
- SyncDataDirectory() synced a data directory containing 4000 small relations:
[2]: io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 94.1 | 1.00x worker | 67.1 | 1.40x io_uring | 57.1 | 1.65x
io_method | startup (ms) | speedup vs sync
-----------+----------------------+----------------
sync | 1411.8 | 1.00x
worker | 1210.6 | 1.17x
io_uring | 310.3 | 4.55
[3]: io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 97.3 | 1.00x worker | 48.7 | 2.00x io_uring | 37.4 | 2.60x
io_method | startup (ms) | speedup vs sync
-----------+----------------------+----------------
sync | 1310.6 | 1.00x
worker | 1210.0 | 1.08x
io_uring | 310.6 | 4.22x
- Checkpointer benchmark dirtied 4000 relation files before checkpoint:
[2]: io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 94.1 | 1.00x worker | 67.1 | 1.40x io_uring | 57.1 | 1.65x
io_method | checkpoint (ms) | speedup vs sync
-----------+----------------------+----------------
sync | 1860.5 | 1.00x
worker | 697.1 | 2.67x
io_uring | 478.4 | 3.89x
[3]: io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 97.3 | 1.00x worker | 48.7 | 2.00x io_uring | 37.4 | 2.60x
io_method | checkpoint (ms) | speedup vs sync
-----------+----------------------+----------------
sync | 1875.5 | 1.00x
worker | 541.1 | 3.47x
io_uring | 479.9 | 3.91x
- SLRU benchmark created 640000 transactions, producing ~30 files to sync:
[2]: io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 94.1 | 1.00x worker | 67.1 | 1.40x io_uring | 57.1 | 1.65x
io_method | SLRU checkpoint (ms) | speedup vs sync
-----------+----------------------+----------------
sync | 94.1 | 1.00x
worker | 67.1 | 1.40x
io_uring | 57.1 | 1.65x
[3]: io_method | SLRU checkpoint (ms) | speedup vs sync -----------+----------------------+---------------- sync | 97.3 | 1.00x worker | 48.7 | 2.00x io_uring | 37.4 | 2.60x
io_method | SLRU checkpoint (ms) | speedup vs sync
-----------+----------------------+----------------
sync | 97.3 | 1.00x
worker | 48.7 | 2.00x
io_uring | 37.4 | 2.60x
Any feedback would be appreciated.
[1]: https://github.com/anarazel/postgres/commit/9829a1f18176e572759ecf8b8bb99205a71a476f https://github.com/anarazel/postgres/commit/2e180547aef6fe2a409cc144e04cbc2f0a607bed
https://github.com/anarazel/postgres/commit/9829a1f18176e572759ecf8b8bb99205a71a476f
https://github.com/anarazel/postgres/commit/2e180547aef6fe2a409cc144e04cbc2f0a607bed
--
Regards,
Nazir Bilal Yavuz
Microsoft
Attachments:
t253548_1v1-0001-aio-Add-fsync-support.patchtext/x-patch; charset=US-ASCII; name=v1-0001-aio-Add-fsync-support.patchDownload+52-3
v1-0002-Issue-SyncDataDirectory-fsyncs-through-AIO.patchtext/x-patch; charset=US-ASCII; name=v1-0002-Issue-SyncDataDirectory-fsyncs-through-AIO.patchDownload+265-44
v1-0003-Issue-checkpointer-fsyncs-asynchronously.patchtext/x-patch; charset=US-ASCII; name=v1-0003-Issue-checkpointer-fsyncs-asynchronously.patchDownload+645-163
v1-0004-Allow-IO-workers-to-execute-SLRU-fsyncs.patchtext/x-patch; charset=US-ASCII; name=v1-0004-Allow-IO-workers-to-execute-SLRU-fsyncs.patchDownload+263-24
Hi Nazir!
Thanks for working on this. The overall direction looks promising and
the patch splits are easy to follow. I reviewed the v1 series and
found a few issues/questions.
pg_stat_io.fsync_time no longer measures fsync wait time. In
mdsyncfiletag(), the time attributed to IOOP_FSYNC is measured around
FileStartSync(). With io_method=worker or io_method=io_uring,
FileStartSync() generally returns after submitting the operation,
before the fsync has completed. As a result, pg_stat_io.fsync_time
records mostly submission overhead rather than time spent waiting for
the fsync. This appears inconsistent with the documented meaning of
fsync_time, which is "time spent waiting for fsync operations." It
also makes the statistic method-dependent - synchronous execution
includes the fsync itself, while worker and io_uring execution
generally do not. A synchronous fallback under the worker method would
change the semantics. Should the timing instead be accounted when
completion is observed or the request is reaped? Alternatively, if
asynchronous fsyncs require different accounting semantics, should
those semantics be explicitly defined and documented?
SLRU reopen errors terminate I/O workers and lose the original errno.
sync_aio_reopen() raises ERROR if an I/O worker cannot reopen an
SLRU segment. The worker’s exception-recovery path completes every
reopen failure as ENOENT. An ENOENT here can be an expected race -
the SLRU segment may have been truncated after the fsync was submitted
but before the worker reopened it. ProcessSyncRequests() already has
cancellation and FILE_POSSIBLY_DELETED() handling for this case.
However, before that logic sees the result, the I/O worker has emitted
an error and exited. Repeated SLRU truncation concurrent with
checkpoints could therefore cause unnecessary logging and worker
churn. There is also an errno-preservation issue. Failures such as
EACCES, EMFILE, or EIO are delivered to the issuing process as ENOENT.
The worker’s initial error report may contain the original %m , but
the AIO completion result does not. The checkpointer may consequently
treat the first failure as a possible deletion race and retry it, then
eventually report a misleading “No such file or directory” error.
Could the reopen interface return an errno for ordinary open failures
instead of raising ERROR ? The worker could complete the request with
-errno and continue processing. That would preserve the actual error,
allow the existing cancellation/retry logic to handle ENOENT, and
reserve worker termination for genuinely unexpected failures.
The new worker-side SLRU target does not appear to be covered by the
test. The updated test_slru_page_sync() test uses ".sync_handler =
SYNC_HANDLER_NONE". That causes SlruSyncFileTag() to select
PGAIO_TID_SYNC rather than PGAIO_TID_SYNC_FILETAG. Since
PGAIO_TID_SYNC has no reopen callback, io_method=worker executes
this request synchronously in the submitting process instead of
handing it to an I/O worker. The test therefore covers the refactored
local fsync path, but not the main path introduced by patch 0004.
Could we add a TAP test to cover this?
Best Regards,
Nitin Jadhav
Azure Database for PostgreSQL
Microsoft
Hi Nitin,
On Mon, 31 Aug 2026 at 18:20, Nitin Jadhav
<nitinjadhavpostgres@gmail.com> wrote:
Thanks for working on this. The overall direction looks promising and
the patch splits are easy to follow. I reviewed the v1 series and
found a few issues/questions.
Thank you for looking into this!
pg_stat_io.fsync_time no longer measures fsync wait time. In
mdsyncfiletag(), the time attributed to IOOP_FSYNC is measured around
FileStartSync(). With io_method=worker or io_method=io_uring,
FileStartSync() generally returns after submitting the operation,
before the fsync has completed. As a result, pg_stat_io.fsync_time
records mostly submission overhead rather than time spent waiting for
the fsync. This appears inconsistent with the documented meaning of
fsync_time, which is "time spent waiting for fsync operations." It
also makes the statistic method-dependent - synchronous execution
includes the fsync itself, while worker and io_uring execution
generally do not. A synchronous fallback under the worker method would
change the semantics. Should the timing instead be accounted when
completion is observed or the request is reaped? Alternatively, if
asynchronous fsyncs require different accounting semantics, should
those semantics be explicitly defined and documented?
Yes, you are right. We can copy the timing calculation used for async
read I/Os. So, it means that total time of fsyncs will be submission
of I/O + wait time for pgaio_wref_wait() in the drain() functions. If
we do that, we don't need to change documentation because this will
represent the total "time spent waiting for fsync operations."
regardless of io_method.
SLRU reopen errors terminate I/O workers and lose the original errno.
sync_aio_reopen() raises ERROR if an I/O worker cannot reopen an
SLRU segment. The worker’s exception-recovery path completes every
reopen failure as ENOENT. An ENOENT here can be an expected race -
the SLRU segment may have been truncated after the fsync was submitted
but before the worker reopened it. ProcessSyncRequests() already has
cancellation and FILE_POSSIBLY_DELETED() handling for this case.
However, before that logic sees the result, the I/O worker has emitted
an error and exited. Repeated SLRU truncation concurrent with
checkpoints could therefore cause unnecessary logging and worker
churn. There is also an errno-preservation issue. Failures such as
EACCES, EMFILE, or EIO are delivered to the issuing process as ENOENT.
The worker’s initial error report may contain the original %m , but
the AIO completion result does not. The checkpointer may consequently
treat the first failure as a possible deletion race and retry it, then
eventually report a misleading “No such file or directory” error.
Could the reopen interface return an errno for ordinary open failures
instead of raising ERROR ? The worker could complete the request with
-errno and continue processing. That would preserve the actual error,
allow the existing cancellation/retry logic to handle ENOENT, and
reserve worker termination for genuinely unexpected failures.
Yes, this is a valid problem. Thank you for the detailed explanation.
I will change the reopen interface so that ordinary failures return
-errno. The I/O worker can then complete the request and continue
processing, while errors raised for unexpected failures will retain
the existing worker-termination path.
The new worker-side SLRU target does not appear to be covered by the
test. The updated test_slru_page_sync() test uses ".sync_handler =
SYNC_HANDLER_NONE". That causes SlruSyncFileTag() to select
PGAIO_TID_SYNC rather than PGAIO_TID_SYNC_FILETAG. Since
PGAIO_TID_SYNC has no reopen callback, io_method=worker executes
this request synchronously in the submitting process instead of
handing it to an I/O worker. The test therefore covers the refactored
local fsync path, but not the main path introduced by patch 0004.
Could we add a TAP test to cover this?
You are right. However, I think what needs to be done is having a
general AIO fsync tests (which will cover the path you mentioned too)
in the test_aio test suite. I will try to implement it in the v2.
--
Regards,
Nazir Bilal Yavuz
Microsoft
Hi Nazir,
The overall direction looks good to me. A few points:
This patch implements async fsyncs for crash recovery and checkpoints by
using the AIO system.
For crash recovery, Linux already has `recovery_init_sync_method=syncfs` as an
alternative to per-file fsyncs. I think it would be useful to include that in
the `SyncDataDirectory()` benchmark.
I will change the reopen interface so that ordinary failures return
`-errno`.
Agreed. I think all AIO target reopen callbacks should follow this convention.
Relation fsyncs can hit the same problem through `smgr_aio_reopen()`, not only
SLRUs.
It uses both io_max_concurrency and the file descriptor budget to determine
max number of available in-flight fsync I/Os.
I wonder whether submitting a batch of concurrent fsyncs could cause an I/O
storm and hurt foreground I/O latency.
The `max_safe_fds / 6` cap protects the `AllocateDesc` budget used by
`OpenTransientFile()`, while relation fsyncs use VFDs. Should the descriptor
cap apply only to handlers that use `OpenTransientFile()`?
Best regards,
Yuhang Qiu
Hi,
Thank you for looking into this!
On Thu, 3 Sept 2026 at 16:15, Yuhang Qiu <iamqyh@gmail.com> wrote:
The overall direction looks good to me. A few points:
This patch implements async fsyncs for crash recovery and checkpoints by
using the AIO system.For crash recovery, Linux already has `recovery_init_sync_method=syncfs` as an
alternative to per-file fsyncs. I think it would be useful to include that in
the `SyncDataDirectory()` benchmark.
Good point. I tested recovery_init_sync_method=syncfs and it seems it
is better than or on par with fsync and AIO. Here are two different
benchmark results:
io_method | recovery_init_sync_method | startup (ms) | speedup
-----------+---------------------------+----------------------+----------------
sync | fsync | 609.4 | 1.00x
worker | fsync | 610.8 | 1.00x
io_uring | fsync | 308.6 | 1.97x
sync | syncfs | 210.7 | 2.89x
io_method | recovery_init_sync_method | startup (ms) | speedup
-----------+---------------------------+----------------------+----------------
sync | fsync | 609.2 | 1.00x
worker | fsync | 610.0 | 1.00x
io_uring | fsync | 211.0 | 2.89x
sync | syncfs | 209.0 | 2.91x
I will change the reopen interface so that ordinary failures return
`-errno`.Agreed. I think all AIO target reopen callbacks should follow this convention.
Relation fsyncs can hit the same problem through `smgr_aio_reopen()`, not only
SLRUs.
I played with that a bit but there were some problems; it was more
complicated than I thought. If we want to return -errno, we lose quite
a bit of error information because we don't reach the actual error
message. We short-circuit these error messages to return -errno and
continue without terminating the worker process.
For now, ordinary reopen failures for both relation and SLRU fsyncs
return -errno. This allows the checkpointer to apply its cancellation,
retry, and error-handling policy without terminating the I/O worker.
Read and write IO reopening retains its existing error handling. I
will continue working to improve this.
It uses both io_max_concurrency and the file descriptor budget to determine
max number of available in-flight fsync I/Os.I wonder whether submitting a batch of concurrent fsyncs could cause an I/O
storm and hurt foreground I/O latency.
I think this is a valid concern. With io_method=worker, fsyncs also
share the worker pool with reads so that could cause a performance
problems. However, I think increasing the number of worker processes
should solve this problem.
The `max_safe_fds / 6` cap protects the `AllocateDesc` budget used by
`OpenTransientFile()`, while relation fsyncs use VFDs. Should the descriptor
cap apply only to handlers that use `OpenTransientFile()`?
Done. Relation fsync requests now use io_max_concurrency as their
limit. For handlers that hold transient descriptors in the
issuingprocess, the limit is also capped at max_safe_fds / 6.
Here are some additional updates compared to v1:
- 0001 enables fsync on tests so CI will run tests with fsync enabled.
- 0002 clears SMGR caches for the worker processes. These caches are
created on the smgr_reopen path and not get destroyed later so these
remain for the lifetime of worker processes. Patch clears the SMGR
cache after a checkpoint and when the worker is not busy. I created
another thread for this [1]/messages/by-id/CAN55FZ2BesKUnajdgpw1fPSe3S6_CHOugryaUEtD7vdP=dRKEQ@mail.gmail.com.
- 0005 for reopen error changes.
- 0008 is for doc changes.
I am still working on the tests; no tests are included yet.
[1]: /messages/by-id/CAN55FZ2BesKUnajdgpw1fPSe3S6_CHOugryaUEtD7vdP=dRKEQ@mail.gmail.com
--
Regards,
Nazir Bilal Yavuz
Microsoft
Attachments:
v2-0001-ci-Temporarily-enable-fsync-everywhere.patchtext/x-patch; charset=US-ASCII; name=v2-0001-ci-Temporarily-enable-fsync-everywhere.patchDownload+4-3
v2-0002-aio-worker-Free-SMGR-objects-when-idle.patchtext/x-patch; charset=US-ASCII; name=v2-0002-aio-worker-Free-SMGR-objects-when-idle.patchDownload+12-1
v2-0003-aio-Add-fsync-support.patchtext/x-patch; charset=US-ASCII; name=v2-0003-aio-Add-fsync-support.patchDownload+56-3
v2-0004-aio-Issue-SyncDataDirectory-fsyncs-through-AIO.patchtext/x-patch; charset=US-ASCII; name=v2-0004-aio-Issue-SyncDataDirectory-fsyncs-through-AIO.patchDownload+263-44
v2-0005-aio-Allow-AIO-reopen-callbacks-to-return-errors.patchtext/x-patch; charset=US-ASCII; name=v2-0005-aio-Allow-AIO-reopen-callbacks-to-return-errors.patchDownload+81-56
v2-0006-aio-Issue-checkpointer-fsyncs-asynchronously.patchtext/x-patch; charset=US-ASCII; name=v2-0006-aio-Issue-checkpointer-fsyncs-asynchronously.patchDownload+893-195
v2-0007-aio-Allow-IO-workers-to-execute-SLRU-fsyncs.patchtext/x-patch; charset=US-ASCII; name=v2-0007-aio-Allow-IO-workers-to-execute-SLRU-fsyncs.patchDownload+213-25
v2-0008-aio-doc-Document-AIO-fsync.patchtext/x-patch; charset=US-ASCII; name=v2-0008-aio-doc-Document-AIO-fsync.patchDownload+30-3
Hi Nazir,
Thanks for the comparison. The main benefit of this patch series seems
to be in checkpointing rather than crash recovery, so I think further
testing should focus on that.
For now, ordinary reopen failures for both relation and SLRU fsyncs
return -errno.Done. Relation fsync requests now use io_max_concurrency as their
limit.
These two changes LGTM.
However, I think increasing the number of worker processes
should solve this problem.
Increasing the worker count may help with worker availability, but it
doesn't address contention for storage bandwidth.
One more point: when a worker calls pg_fsync() or pg_fdatasync(), it checks
its own enableFsync. If the issuer has reloaded fsync=on but the worker
still has the old off value, the worker can skip the sync and report
success. Should the issuer's setting or the worker's determine whether
the sync is performed?
Best regards,
Yuhang Qiu
Hi Nazir,
Thanks for the updated patch set. I reviewed v2. The changes address
my earlier comments about fsync timing and reopen-error handling. In
particular, wait time is now accounted for when the issuer actually
blocks for completion, and ordinary reopen failures preserve the errno
without terminating the I/O worker.
I found two further points, and the worker-side SLRU test-coverage
question from v1 still appears applicable.
An I/O worker can skip a required fsync after fsync is enabled. As
Yuhang noted, there appears to be a race when reloading fsync from off
to on. pgaio_io_start_fsync() makes the dispatch decision using the
issuing process's enableFsync. Therefore, once the checkpointer has
processed the new configuration and sees fsync=on, it can submit the
operation to an I/O worker. However, worker execution eventually calls
pg_fsync() or pg_fdatasync(). Those functions check the worker
process's own enableFsync. An I/O worker can consume and execute a
queued request before processing its pending configuration reload. If
the worker still has the old fsync=off value, pg_fsync() returns
success without issuing the syscall. The checkpointer then treats the
operation as successfully completed even though the required
synchronization did not occur. The unsafe direction is specifically
off to on; the reverse direction can cause an unnecessary fsync but
does not lose durability. Could the decision to perform the fsync be
captured in the AIO operation when it is submitted, with worker
execution using a syscall helper that does not re-evaluate the
worker-local enableFsync value? Alternatively, the worker would need
to guarantee that it has applied the relevant configuration generation
before executing the request. I think this should be treated as
blocking because it can allow a checkpoint to complete without
executing a required fsync.
Worker SMGR cleanup appears dependent on the worker becoming idle.
Patch 0002 calls smgrdestroyall() only after the worker finds that no
request is available. This means a continuously busy worker may never
perform the cleanup. Worker-side relation reopening calls smgropen(),
and those unpinned SMgrRelation objects remain in the worker's SMGR
hash until smgrdestroyall() is called. With sustained I/O over many
distinct relations, a worker whose queue never becomes empty could
therefore retain an increasing number of SMGR entries, including
entries for relations that have since been dropped. Would it be safer
to check FirstCallSinceLastCheckpoint() at a safe point after
completing each request, before consuming the next request, rather
than only on the idle path? At that point any descriptor reopened for
the completed operation has already been released.
The worker-side SLRU path does not appear to have targeted test
coverage. The test_slru_page_sync() still registers the test SLRU with
SYNC_HANDLER_NONE. Consequently, SlruSyncFileTag() selects
PGAIO_TID_SYNC, which has no reopen callback and is executed
synchronously in the submitting process under io_method=worker.
Best Regards,
Nitin Jadhav
Azure Database for PostgreSQL
Microsoft
Hi,
On Tue, 22 Sept 2026 at 07:03, Yuhang Qiu <iamqyh@gmail.com> wrote:
Thanks for the comparison. The main benefit of this patch series seems
to be in checkpointing rather than crash recovery, so I think further
testing should focus on that.
I agree. Crash recovery is useful but checkpoint's impact is much
greater than that IMO.
However, I think increasing the number of worker processes
should solve this problem.Increasing the worker count may help with worker availability, but it
doesn't address contention for storage bandwidth.
Could you please elaborate more on this?
One more point: when a worker calls pg_fsync() or pg_fdatasync(), it checks
its own enableFsync. If the issuer has reloaded fsync=on but the worker
still has the old off value, the worker can skip the sync and report
success. Should the issuer's setting or the worker's determine whether
the sync is performed?
Nice find. I think it makes sense to use the issuing process's
enableFsync. Done like that in v3-0002.
--
Regards,
Nazir Bilal Yavuz
Microsoft
Attachments:
v3-0001-ci-Temporarily-enable-fsync-everywhere.patchtext/x-patch; charset=US-ASCII; name=v3-0001-ci-Temporarily-enable-fsync-everywhere.patchDownload+4-3
v3-0002-aio-Add-fsync-support.patchtext/x-patch; charset=US-ASCII; name=v3-0002-aio-Add-fsync-support.patchDownload+154-21
v3-0003-aio-worker-Bound-SMGR-cache-growth.patchtext/x-patch; charset=US-ASCII; name=v3-0003-aio-worker-Bound-SMGR-cache-growth.patchDownload+36-1
v3-0004-aio-Issue-SyncDataDirectory-fsyncs-through-AIO.patchtext/x-patch; charset=US-ASCII; name=v3-0004-aio-Issue-SyncDataDirectory-fsyncs-through-AIO.patchDownload+263-44
v3-0005-aio-Allow-AIO-reopen-callbacks-to-return-errors.patchtext/x-patch; charset=US-ASCII; name=v3-0005-aio-Allow-AIO-reopen-callbacks-to-return-errors.patchDownload+81-56
v3-0006-aio-Issue-checkpointer-fsyncs-asynchronously.patchtext/x-patch; charset=US-ASCII; name=v3-0006-aio-Issue-checkpointer-fsyncs-asynchronously.patchDownload+952-195
v3-0007-aio-Allow-IO-workers-to-execute-SLRU-fsyncs.patchtext/x-patch; charset=US-ASCII; name=v3-0007-aio-Allow-IO-workers-to-execute-SLRU-fsyncs.patchDownload+213-25
v3-0008-aio-doc-Document-AIO-fsync.patchtext/x-patch; charset=US-ASCII; name=v3-0008-aio-doc-Document-AIO-fsync.patchDownload+29-3
Hi,
On Tue, 22 Sept 2026 at 18:21, Nitin Jadhav
<nitinjadhavpostgres@gmail.com> wrote:
I found two further points, and the worker-side SLRU test-coverage
question from v1 still appears applicable.An I/O worker can skip a required fsync after fsync is enabled. As
Yuhang noted, there appears to be a race when reloading fsync from off
to on. pgaio_io_start_fsync() makes the dispatch decision using the
issuing process's enableFsync.
You are right, that is fixed in v3 [1]/messages/by-id/CAN55FZ2NT6529QhB_dcrZ5LaSL20aayhP33ZisZVFSg2hOqLXg@mail.gmail.com. I used the issuing process's enableFsync
Worker SMGR cleanup appears dependent on the worker becoming idle.
Patch 0002 calls smgrdestroyall() only after the worker finds that no
request is available. This means a continuously busy worker may never
perform the cleanup. Worker-side relation reopening calls smgropen(),
and those unpinned SMgrRelation objects remain in the worker's SMGR
hash until smgrdestroyall() is called. With sustained I/O over many
distinct relations, a worker whose queue never becomes empty could
therefore retain an increasing number of SMGR entries, including
entries for relations that have since been dropped. Would it be safer
to check FirstCallSinceLastCheckpoint() at a safe point after
completing each request, before consuming the next request, rather
than only on the idle path? At that point any descriptor reopened for
the completed operation has already been released.
We have created another thread for this. Now, we have a dedicated SMGR
entry limits, and the worker can't surpass this limit. For more
information you can look [2]/messages/by-id/CAN55FZ2BesKUnajdgpw1fPSe3S6_CHOugryaUEtD7vdP=dRKEQ@mail.gmail.com, but briefly, SMGR entries can't surpass
this limit when the worker is busy; they are cleaned when we reach
this limit. Also, SMGR entries are cleaned before the worker goes to
idle. These should solve the problem.
The worker-side SLRU path does not appear to have targeted test
coverage. The test_slru_page_sync() still registers the test SLRU with
SYNC_HANDLER_NONE. Consequently, SlruSyncFileTag() selects
PGAIO_TID_SYNC, which has no reopen callback and is executed
synchronously in the submitting process under io_method=worker.
Yes, that is not tested. I will add that.
[1]: /messages/by-id/CAN55FZ2NT6529QhB_dcrZ5LaSL20aayhP33ZisZVFSg2hOqLXg@mail.gmail.com
[2]: /messages/by-id/CAN55FZ2BesKUnajdgpw1fPSe3S6_CHOugryaUEtD7vdP=dRKEQ@mail.gmail.com
--
Regards,
Nazir Bilal Yavuz
Microsoft