0008.patch_txt

application/octet-stream

Filename: 0008.patch_txt
Type: application/octet-stream
Part: 0
Message: Re: Adding basic NUMA awareness
From a727635b92e2cfac6dbcf59b05c37eafbfa506f2 Mon Sep 17 00:00:00 2001
From: Jakub Wartak <jakub.wartak@enterprisedb.com>
Date: Tue, 4 Nov 2025 10:34:39 +0100
Subject: [PATCH] 0008

---
 src/include/port/pg_numa.h |  2 ++
 src/port/pg_numa.c         | 54 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/src/include/port/pg_numa.h b/src/include/port/pg_numa.h
index aa524f6f7f3..16e4605fa27 100644
--- a/src/include/port/pg_numa.h
+++ b/src/include/port/pg_numa.h
@@ -19,6 +19,8 @@ extern PGDLLIMPORT int pg_numa_query_pages(int pid, unsigned long count, void **
 extern PGDLLIMPORT int pg_numa_get_max_node(void);
 extern PGDLLIMPORT Size pg_numa_page_size(void);
 extern PGDLLIMPORT void pg_numa_move_to_node(char *startptr, char *endptr, int node);
+extern void numa_warn(int num, char *fmt,...) pg_attribute_printf(2, 3);
+extern void numa_error(char *where);
 
 extern PGDLLIMPORT int numa_flags;
 
diff --git a/src/port/pg_numa.c b/src/port/pg_numa.c
index 8ee0e7d211c..b90b462ba9b 100644
--- a/src/port/pg_numa.c
+++ b/src/port/pg_numa.c
@@ -14,13 +14,15 @@
  */
 
 #include "c.h"
+/* XXX: JW: had to add it */
+#include "postgres.h"
 #include <unistd.h>
 
 #include "miscadmin.h"
 #include "port/pg_numa.h"
 #include "storage/pg_shmem.h"
 
-int	numa_flags;
+int			numa_flags;
 
 /*
  * At this point we provide support only for Linux thanks to libnuma, but in
@@ -139,6 +141,56 @@ pg_numa_move_to_node(char *startptr, char *endptr, int node)
 	numa_tonode_memory(startptr, sz, node);
 }
 
+#ifndef FRONTEND
+/*
+ * The libnuma built-in code can be seen here:
+ * https://github.com/numactl/numactl/blob/master/libnuma.c
+ *
+ */
+void
+numa_warn(int num, char *fmt,...)
+{
+	va_list		ap;
+	int			olde = errno;
+	int			needed;
+	StringInfoData msg;
+
+	initStringInfo(&msg);
+
+	va_start(ap, fmt);
+	needed = appendStringInfoVA(&msg, fmt, ap);
+	va_end(ap);
+	if (needed > 0)
+	{
+		enlargeStringInfo(&msg, needed);
+		va_start(ap, fmt);
+		appendStringInfoVA(&msg, fmt, ap);
+		va_end(ap);
+	}
+
+	ereport(WARNING,
+			(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+			 errmsg_internal("libnuma: WARNING: %s", msg.data)));
+
+	pfree(msg.data);
+
+	errno = olde;
+}
+
+void
+numa_error(char *where)
+{
+	int			olde = errno;
+
+	/*
+	 * XXX: for now we issue just WARNING, but long-term that might depend on
+	 * numa_set_strict() here.
+	 */
+	elog(WARNING, "libnuma: ERROR: %s", where);
+	errno = olde;
+}
+#endif							/* FRONTEND */
+
 #else
 
 /* Empty wrappers */
-- 
2.39.5