Skip to content

Commit 1dbba36

Browse files
committed
aio: Regularize io_method=worker naming conventions.
method_worker.c didn't keep up with the pattern of PgAioXXX for type names in the pgaio module. Add the missing "Pg" prefix used else where. Likewise for pgaio_choose_idle_worker() which alone failed to use a pgaio_worker_XXX() name refecting its submodule. Rename. Standardize on parameter names num_staged_ios, staged_ios for the internal submission function. Rename the array of handle IDs in PgAioSubmissionQueue to sqes, since that's a term of art seen in many of these types of systems.
1 parent 7d430a5 commit 1dbba36

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
@@ -51,26 +51,26 @@
5151
#define IO_WORKER_WAKEUP_FANOUT 2
5252

5353

54-
typedef struct AioWorkerSubmissionQueue
54+
typedef struct PgAioWorkerSubmissionQueue
5555
{
5656
uint32 size;
5757
uint32 mask;
5858
uint32 head;
5959
uint32 tail;
60-
uint32 ios[FLEXIBLE_ARRAY_MEMBER];
61-
} AioWorkerSubmissionQueue;
60+
uint32 sqes[FLEXIBLE_ARRAY_MEMBER];
61+
} PgAioWorkerSubmissionQueue;
6262

63-
typedef struct AioWorkerSlot
63+
typedef struct PgAioWorkerSlot
6464
{
6565
Latch *latch;
6666
bool in_use;
67-
} AioWorkerSlot;
67+
} PgAioWorkerSlot;
6868

69-
typedef struct AioWorkerControl
69+
typedef struct PgAioWorkerControl
7070
{
7171
uint64 idle_worker_mask;
72-
AioWorkerSlot workers[FLEXIBLE_ARRAY_MEMBER];
73-
} AioWorkerControl;
72+
PgAioWorkerSlot workers[FLEXIBLE_ARRAY_MEMBER];
73+
} PgAioWorkerControl;
7474

7575

7676
static size_t pgaio_worker_shmem_size(void);
@@ -95,8 +95,8 @@ int io_workers = 3;
9595

9696
static int io_worker_queue_size = 64;
9797
static int MyIoWorkerId;
98-
static AioWorkerSubmissionQueue *io_worker_submission_queue;
99-
static AioWorkerControl *io_worker_control;
98+
static PgAioWorkerSubmissionQueue *io_worker_submission_queue;
99+
static PgAioWorkerControl *io_worker_control;
100100

101101

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

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

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

119119
static size_t
@@ -161,7 +161,7 @@ pgaio_worker_shmem_init(bool first_time)
161161
}
162162

163163
static int
164-
pgaio_choose_idle_worker(void)
164+
pgaio_worker_choose_idle(void)
165165
{
166166
int worker;
167167

@@ -178,7 +178,7 @@ pgaio_choose_idle_worker(void)
178178
static bool
179179
pgaio_worker_submission_queue_insert(PgAioHandle *ioh)
180180
{
181-
AioWorkerSubmissionQueue *queue;
181+
PgAioWorkerSubmissionQueue *queue;
182182
uint32 new_head;
183183

184184
queue = io_worker_submission_queue;
@@ -190,7 +190,7 @@ pgaio_worker_submission_queue_insert(PgAioHandle *ioh)
190190
return false; /* full */
191191
}
192192

193-
queue->ios[queue->head] = pgaio_io_get_id(ioh);
193+
queue->sqes[queue->head] = pgaio_io_get_id(ioh);
194194
queue->head = new_head;
195195

196196
return true;
@@ -199,14 +199,14 @@ pgaio_worker_submission_queue_insert(PgAioHandle *ioh)
199199
static uint32
200200
pgaio_worker_submission_queue_consume(void)
201201
{
202-
AioWorkerSubmissionQueue *queue;
202+
PgAioWorkerSubmissionQueue *queue;
203203
uint32 result;
204204

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

209-
result = queue->ios[queue->tail];
209+
result = queue->sqes[queue->tail];
210210
queue->tail = (queue->tail + 1) & (queue->size - 1);
211211

212212
return result;
@@ -239,37 +239,37 @@ pgaio_worker_needs_synchronous_execution(PgAioHandle *ioh)
239239
}
240240

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

249-
Assert(nios <= PGAIO_SUBMIT_BATCH_SIZE);
249+
Assert(num_staged_ios <= PGAIO_SUBMIT_BATCH_SIZE);
250250

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

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

272-
pgaio_debug_io(DEBUG4, ios[i],
272+
pgaio_debug_io(DEBUG4, staged_ios[i],
273273
"choosing worker %d",
274274
worker);
275275
}
@@ -482,7 +482,7 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
482482
IO_WORKER_WAKEUP_FANOUT);
483483
for (int i = 0; i < nwakeups; ++i)
484484
{
485-
if ((worker = pgaio_choose_idle_worker()) < 0)
485+
if ((worker = pgaio_worker_choose_idle()) < 0)
486486
break;
487487
latches[nlatches++] = io_worker_control->workers[worker].latch;
488488
}

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
@@ -2175,6 +2172,9 @@ PgAioTargetID
21752172
PgAioTargetInfo
21762173
PgAioUringContext
21772174
PgAioWaitRef
2175+
PgAioWorkerControl
2176+
PgAioWorkerSlot
2177+
PgAioWorkerSubmissionQueue
21782178
PgArchData
21792179
PgBackendGSSStatus
21802180
PgBackendSSLStatus

0 commit comments

Comments
 (0)