v2-0001-aio-warn-user-if-combined-io_uring-memory-mapping.patch

application/x-patch

Filename: v2-0001-aio-warn-user-if-combined-io_uring-memory-mapping.patch
Type: application/x-patch
Part: 0
Message: Re: postmaster uses more CPU in 18 beta1 with io_method=io_uring
From 72cd5da67c5c60d150ac4780acf8c3d81323b810 Mon Sep 17 00:00:00 2001
From: Jakub Wartak <jakub.wartak@enterprisedb.com>
Date: Mon, 22 Sep 2025 10:00:47 +0200
Subject: [PATCH v2] aio: warn user if combined io_uring memory mappings are
 unavailable

In f54af9f2 we have added solution to avoid connection and disconnection hit
caused by io_uring managing large number of memory mappings. Unfortunately
it is available only on more modern Linux kernels (6.5) therefore notify user
in visible way if this optimization is not available.

Author: Jakub Wartak <jakub.wartak@enterprisedb.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAFbpF8OA44_UG+RYJcWH9WjF7E3GA6gka3gvH6nsrSnEe9H0NA@mail.gmail.com
---
 doc/src/sgml/config.sgml                  |  6 ++++++
 src/backend/storage/aio/method_io_uring.c | 10 ++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index e9b420f3ddb..15dd955a0c3 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -2784,6 +2784,12 @@ include_dir 'conf.d'
         <para>
          This parameter can only be set at server start.
         </para>
+        <para>
+         Note that for optimum performance with <literal>io_uring</literal>
+         Linux kernel version >= 6.5 is recommended. Older Linux versions,
+         high values of <xref linkend="guc-max-connections"/> will slow down connection
+         establishment and termination.
+        </para>
        </listitem>
       </varlistentry>
 
diff --git a/src/backend/storage/aio/method_io_uring.c b/src/backend/storage/aio/method_io_uring.c
index bb06da63a8e..36b9fabf7c5 100644
--- a/src/backend/storage/aio/method_io_uring.c
+++ b/src/backend/storage/aio/method_io_uring.c
@@ -207,8 +207,9 @@ pgaio_uring_check_capabilities(void)
 			 * pgaio_uring_shmem_init().
 			 */
 			errno = -ret;
-			elog(DEBUG1,
-				 "cannot use combined memory mapping for io_uring, ring creation failed: %m");
+			ereport(WARNING,
+					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+					 errmsg("io_uring combined memory mapping creation failed: %m. Upgrade kernel to 6.5+ for improved performance")));
 
 		}
 
@@ -217,8 +218,9 @@ pgaio_uring_check_capabilities(void)
 	}
 #else
 	{
-		elog(DEBUG1,
-			 "can't use combined memory mapping for io_uring, kernel or liburing too old");
+		ereport(WARNING,
+				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+				 errmsg("io_uring combined memory mapping creation failed: %m. Upgrade kernel to 6.5+ for improved performance")));
 	}
 #endif
 
-- 
2.39.5