Skip to content

Commit b2afb06

Browse files
committed
aio: Regularize IO worker internal naming.
Adopt PgAioXXX convention for pgaio module type names. Rename a function that didn't use a pgaio_worker_ submodule prefix. Rename the internal submit function's arguments to match the indirectly relevant function pointer declaration and nearby examples. Rename the array of handle IDs in PgAioSubmissionQueue to sqes, a term of art seen in the systems it emulates, also clarifying that they're not IO handle pointers as the old name might imply. No change in behavior, just type, variable and function name cleanup. Back-patch to 18. Discussion: https://postgr.es/m/CA%2BhUKG%2BwbaZZ9Nwc_bTopm4f-7vDmCwLk80uKDHj9mq%2BUp0E%2Bg%40mail.gmail.com
1 parent 20b8b5d commit b2afb06

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/backend/storage/aio/method_worker.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@
5252
#define IO_WORKER_WAKEUP_FANOUT 2
5353

5454

55-
typedef struct AioWorkerSubmissionQueue
55+
typedef struct PgAioWorkerSubmissionQueue
5656
{
5757
uint32 size;
5858
uint32 mask;
5959
uint32 head;
6060
uint32 tail;
61-
uint32 ios[FLEXIBLE_ARRAY_MEMBER];
62-
} AioWorkerSubmissionQueue;
61+
uint32 sqes[FLEXIBLE_ARRAY_MEMBER];
62+
} PgAioWorkerSubmissionQueue;
6363

64-
typedef struct AioWorkerSlot
64+
typedef struct PgAioWorkerSlot
6565
{
6666
Latch *latch;
6767
bool in_use;
68-
} AioWorkerSlot;
68+
} PgAioWorkerSlot;
6969

70-
typedef struct AioWorkerControl
70+
typedef struct PgAioWorkerControl
7171
{
7272
uint64 idle_worker_mask;
73-
AioWorkerSlot workers[FLEXIBLE_ARRAY_MEMBER];
74-
} AioWorkerControl;
73+
PgAioWorkerSlot workers[FLEXIBLE_ARRAY_MEMBER];
74+
} PgAioWorkerControl;
7575

7676

7777
static size_t pgaio_worker_shmem_size(void);
@@ -96,8 +96,8 @@ int io_workers = 3;
9696

9797
static int io_worker_queue_size = 64;
9898
static int MyIoWorkerId;
99-
static AioWorkerSubmissionQueue *io_worker_submission_queue;
100-
static AioWorkerControl *io_worker_control;
99+
static PgAioWorkerSubmissionQueue *io_worker_submission_queue;
100+
static PgAioWorkerControl *io_worker_control;
101101

102102

103103
static size_t
@@ -106,15 +106,15 @@ pgaio_worker_queue_shmem_size(int *queue_size)
106106
/* Round size up to next power of two so we can make a mask. */
107107
*queue_size = pg_nextpower2_32(io_worker_queue_size);
108108

109-
return offsetof(AioWorkerSubmissionQueue, ios) +
109+
return offsetof(PgAioWorkerSubmissionQueue, sqes) +
110110
sizeof(uint32) * *queue_size;
111111
}
112112

113113
static size_t
114114
pgaio_worker_control_shmem_size(void)
115115
{
116-
return offsetof(AioWorkerControl, workers) +
117-
sizeof(AioWorkerSlot) * MAX_IO_WORKERS;
116+
return offsetof(PgAioWorkerControl, workers) +
117+
sizeof(PgAioWorkerSlot) * MAX_IO_WORKERS;
118118
}
119119

120120
static size_t
@@ -162,7 +162,7 @@ pgaio_worker_shmem_init(bool first_time)
162162
}
163163

164164
static int
165-
pgaio_choose_idle_worker(void)
165+
pgaio_worker_choose_idle(void)
166166
{
167167
int worker;
168168

@@ -180,7 +180,7 @@ pgaio_choose_idle_worker(void)
180180
static bool
181181
pgaio_worker_submission_queue_insert(PgAioHandle *ioh)
182182
{
183-
AioWorkerSubmissionQueue *queue;
183+
PgAioWorkerSubmissionQueue *queue;
184184
uint32 new_head;
185185

186186
queue = io_worker_submission_queue;
@@ -192,7 +192,7 @@ pgaio_worker_submission_queue_insert(PgAioHandle *ioh)
192192
return false; /* full */
193193
}
194194

195-
queue->ios[queue->head] = pgaio_io_get_id(ioh);
195+
queue->sqes[queue->head] = pgaio_io_get_id(ioh);
196196
queue->head = new_head;
197197

198198
return true;
@@ -201,14 +201,14 @@ pgaio_worker_submission_queue_insert(PgAioHandle *ioh)
201201
static uint32
202202
pgaio_worker_submission_queue_consume(void)
203203
{
204-
AioWorkerSubmissionQueue *queue;
204+
PgAioWorkerSubmissionQueue *queue;
205205
uint32 result;
206206

207207
queue = io_worker_submission_queue;
208208
if (queue->tail == queue->head)
209209
return UINT32_MAX; /* empty */
210210

211-
result = queue->ios[queue->tail];
211+
result = queue->sqes[queue->tail];
212212
queue->tail = (queue->tail + 1) & (queue->size - 1);
213213

214214
return result;
@@ -241,37 +241,37 @@ pgaio_worker_needs_synchronous_execution(PgAioHandle *ioh)
241241
}
242242

243243
static void
244-
pgaio_worker_submit_internal(int nios, PgAioHandle *ios[])
244+
pgaio_worker_submit_internal(int num_staged_ios, PgAioHandle **staged_ios)
245245
{
246246
PgAioHandle *synchronous_ios[PGAIO_SUBMIT_BATCH_SIZE];
247247
int nsync = 0;
248248
Latch *wakeup = NULL;
249249
int worker;
250250

251-
Assert(nios <= PGAIO_SUBMIT_BATCH_SIZE);
251+
Assert(num_staged_ios <= PGAIO_SUBMIT_BATCH_SIZE);
252252

253253
LWLockAcquire(AioWorkerSubmissionQueueLock, LW_EXCLUSIVE);
254-
for (int i = 0; i < nios; ++i)
254+
for (int i = 0; i < num_staged_ios; ++i)
255255
{
256-
Assert(!pgaio_worker_needs_synchronous_execution(ios[i]));
257-
if (!pgaio_worker_submission_queue_insert(ios[i]))
256+
Assert(!pgaio_worker_needs_synchronous_execution(staged_ios[i]));
257+
if (!pgaio_worker_submission_queue_insert(staged_ios[i]))
258258
{
259259
/*
260260
* We'll do it synchronously, but only after we've sent as many as
261261
* we can to workers, to maximize concurrency.
262262
*/
263-
synchronous_ios[nsync++] = ios[i];
263+
synchronous_ios[nsync++] = staged_ios[i];
264264
continue;
265265
}
266266

267267
if (wakeup == NULL)
268268
{
269269
/* Choose an idle worker to wake up if we haven't already. */
270-
worker = pgaio_choose_idle_worker();
270+
worker = pgaio_worker_choose_idle();
271271
if (worker >= 0)
272272
wakeup = io_worker_control->workers[worker].latch;
273273

274-
pgaio_debug_io(DEBUG4, ios[i],
274+
pgaio_debug_io(DEBUG4, staged_ios[i],
275275
"choosing worker %d",
276276
worker);
277277
}
@@ -490,7 +490,7 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
490490
IO_WORKER_WAKEUP_FANOUT);
491491
for (int i = 0; i < nwakeups; ++i)
492492
{
493-
if ((worker = pgaio_choose_idle_worker()) < 0)
493+
if ((worker = pgaio_worker_choose_idle()) < 0)
494494
break;
495495
latches[nlatches++] = io_worker_control->workers[worker].latch;
496496
}

src/tools/pgindent/typedefs.list

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ AggStrategy
5555
AggTransInfo
5656
Aggref
5757
AggregateInstrumentation
58-
AioWorkerControl
59-
AioWorkerSlot
60-
AioWorkerSubmissionQueue
6158
AlenState
6259
Alias
6360
AllocBlock
@@ -2179,6 +2176,9 @@ PgAioTargetInfo
21792176
PgAioUringCaps
21802177
PgAioUringContext
21812178
PgAioWaitRef
2179+
PgAioWorkerControl
2180+
PgAioWorkerSlot
2181+
PgAioWorkerSubmissionQueue
21822182
PgArchData
21832183
PgBackendGSSStatus
21842184
PgBackendSSLStatus

0 commit comments

Comments
 (0)