Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b9d5e77

Browse files
anarazelCommitfest Bot
authored and
Commitfest Bot
committed
bufmgr: use AIO in checkpointer, bgwriter
This is far from ready - just included to be able to exercise AIO writes and get some preliminary numbers. In all likelihood this will instead be based on-top of work by Thomas Munro instead of the preceding commit. TODO; - This doesn't implement bgwriter_flush_after, checkpointer_flush_after I think that's not too hard to do, it's mainly round tuits. - The queuing logic doesn't carefully respect pin limits That might be ok for checkpointer and bgwriter, but the infrastructure should be usable outside of this as well.
1 parent 6074c30 commit b9d5e77

File tree

9 files changed

+586
-58
lines changed

9 files changed

+586
-58
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@
3838
#include "postmaster/auxprocess.h"
3939
#include "postmaster/bgwriter.h"
4040
#include "postmaster/interrupt.h"
41+
#include "storage/aio.h"
4142
#include "storage/aio_subsys.h"
4243
#include "storage/buf_internals.h"
4344
#include "storage/bufmgr.h"
4445
#include "storage/condition_variable.h"
4546
#include "storage/fd.h"
47+
#include "storage/io_queue.h"
4648
#include "storage/lwlock.h"
4749
#include "storage/proc.h"
4850
#include "storage/procsignal.h"
@@ -90,6 +92,7 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)
9092
sigjmp_buf local_sigjmp_buf;
9193
MemoryContext bgwriter_context;
9294
bool prev_hibernate;
95+
IOQueue *ioq;
9396
WritebackContext wb_context;
9497

9598
Assert(startup_data_len == 0);
@@ -131,6 +134,7 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)
131134
ALLOCSET_DEFAULT_SIZES);
132135
MemoryContextSwitchTo(bgwriter_context);
133136

137+
ioq = io_queue_create(128, 0);
134138
WritebackContextInit(&wb_context, &bgwriter_flush_after);
135139

136140
/*
@@ -228,12 +232,22 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)
228232
/* Clear any already-pending wakeups */
229233
ResetLatch(MyLatch);
230234

235+
/*
236+
* FIXME: this is theoretically racy, but I didn't want to copy
237+
* ProcessMainLoopInterrupts() remaining body here.
238+
*/
239+
if (ShutdownRequestPending)
240+
{
241+
io_queue_wait_all(ioq);
242+
io_queue_free(ioq);
243+
}
244+
231245
ProcessMainLoopInterrupts();
232246

233247
/*
234248
* Do one cycle of dirty-buffer writing.
235249
*/
236-
can_hibernate = BgBufferSync(&wb_context);
250+
can_hibernate = BgBufferSync(ioq, &wb_context);
237251

238252
/* Report pending statistics to the cumulative stats system */
239253
pgstat_report_bgwriter();
@@ -250,6 +264,9 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)
250264
smgrdestroyall();
251265
}
252266

267+
/* finish IO before sleeping, to avoid blocking other backends */
268+
io_queue_wait_all(ioq);
269+
253270
/*
254271
* Log a new xl_running_xacts every now and then so replication can
255272
* get into a consistent state faster (think of suboverflowed

src/backend/postmaster/checkpointer.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
#include "postmaster/bgwriter.h"
5050
#include "postmaster/interrupt.h"
5151
#include "replication/syncrep.h"
52+
#include "storage/aio.h"
5253
#include "storage/aio_subsys.h"
5354
#include "storage/bufmgr.h"
5455
#include "storage/condition_variable.h"
5556
#include "storage/fd.h"
57+
#include "storage/io_queue.h"
5658
#include "storage/ipc.h"
5759
#include "storage/lwlock.h"
5860
#include "storage/pmsignal.h"
@@ -766,7 +768,7 @@ ImmediateCheckpointRequested(void)
766768
* fraction between 0.0 meaning none, and 1.0 meaning all done.
767769
*/
768770
void
769-
CheckpointWriteDelay(int flags, double progress)
771+
CheckpointWriteDelay(IOQueue *ioq, int flags, double progress)
770772
{
771773
static int absorb_counter = WRITES_PER_ABSORB;
772774

@@ -800,6 +802,13 @@ CheckpointWriteDelay(int flags, double progress)
800802
/* Report interim statistics to the cumulative stats system */
801803
pgstat_report_checkpointer();
802804

805+
/*
806+
* Ensure all pending IO is submitted to avoid unnecessary delays for
807+
* other processes.
808+
*/
809+
io_queue_wait_all(ioq);
810+
811+
803812
/*
804813
* This sleep used to be connected to bgwriter_delay, typically 200ms.
805814
* That resulted in more frequent wakeups if not much work to do.

0 commit comments

Comments
 (0)