v1-0001-Release-io_uring-resources-on-shmem-exit.patch
text/x-patch
Filename: v1-0001-Release-io_uring-resources-on-shmem-exit.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0001
Subject: Release io_uring resources on shmem exit
| File | + | − |
|---|---|---|
| src/backend/storage/aio/method_io_uring.c | 23 | 0 |
From 9728c2c28420677719e45139d9cbf16526cb1656 Mon Sep 17 00:00:00 2001
From: Lucas DRAESCHER <git@draescher.fr>
Date: Tue, 17 Mar 2026 17:26:11 +0100
Subject: [PATCH v1] Release io_uring resources on shmem exit
io_uring_queue_init() allocates resources for each io_uring instance, but
pgaio_uring_shmem_init() never registered a cleanup callback to free them.
Add an on_shmem_exit() callback that calls io_uring_queue_exit().
The callback and its registration follow the same pattern as
pgaio_worker_die() in method_worker.c.
---
src/backend/storage/aio/method_io_uring.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/backend/storage/aio/method_io_uring.c b/src/backend/storage/aio/method_io_uring.c
index 4867ded35ea..61984b798a9 100644
--- a/src/backend/storage/aio/method_io_uring.c
+++ b/src/backend/storage/aio/method_io_uring.c
@@ -37,6 +37,7 @@
#include "miscadmin.h"
#include "storage/aio_internal.h"
#include "storage/fd.h"
+#include "storage/ipc.h"
#include "storage/proc.h"
#include "storage/shmem.h"
#include "storage/lwlock.h"
@@ -277,6 +278,26 @@ pgaio_uring_shmem_size(void)
return sz;
}
+/*
+ * on_shmem_exit() callback that releases the io_uring queues in
+ * pgaio_uring_shmem_init.
+ */
+static void
+pgaio_uring_die(int code, Datum arg)
+{
+ if (pgaio_uring_contexts != NULL)
+ {
+ int TotalProcs = pgaio_uring_procs();
+
+ elog(DEBUG1, "cleaning up %d io_uring processes", TotalProcs);
+
+ for (int i = 0; i < TotalProcs; i++)
+ io_uring_queue_exit(&pgaio_uring_contexts[i].io_uring_ring);
+
+ pgaio_uring_contexts = NULL;
+ }
+}
+
static void
pgaio_uring_shmem_init(bool first_time)
{
@@ -393,6 +414,8 @@ pgaio_uring_shmem_init(bool first_time)
LWLockInitialize(&context->completion_lock, LWTRANCHE_AIO_URING_COMPLETION);
}
+
+ on_shmem_exit(pgaio_uring_die, 0);
}
static void
--
2.53.0