Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uYkXu-00AbdF-N9 for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Jul 2025 12:02:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uYkXs-001YwS-Ml for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Jul 2025 12:02:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uYkXs-001Yw9-9E for pgsql-hackers@lists.postgresql.org; Mon, 07 Jul 2025 12:02:04 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uYkXq-00625p-0j for pgsql-hackers@lists.postgresql.org; Mon, 07 Jul 2025 12:02:03 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 746D243A12; Mon, 7 Jul 2025 12:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1751889717; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7qg6c2ca3h67C7vaqRX57d1ZoVViJJZSVQ5qk1MZYcs=; b=OT04poWq098RO8P4GDuChewmF2Wzhw18JI8pnfR0e2MwFTIAtwaM8uSXMmyHKyDOcmIzxD 917mldHxfYaex5W5YqIk8NQdCYHzi4ws28rG2f4zWjvHkxZ2P7g4QatKYM6wW06hn0qcBa UeQhuGLq8CxtZtFOoGOLX/6GjuT8ENwSuLgJ7WWDETb+nWCLAK+eVx2zDfZXoHmqHtPP/A QynDEV6LupJ7KSHyunVwoZnCkG85TfEFBZUSHlvnR4gPBZ8+FjR2jRpXYrK9rDV2mOfT4B UvUoKfj84PGHFhyzocYyqtOwoAScvcb6Ih2zZn9jLevtRczqb+zbyhT8xu6AuA== Message-ID: <8b3341ee-1f8e-4dbb-8046-410f71d4a0cb@vondra.me> Date: Mon, 7 Jul 2025 14:01:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Adding basic NUMA awareness - Preliminary feedback and outline for an extensible approach To: =?UTF-8?Q?C=C3=A9dric_Villemain?= , PostgreSQL Hackers References: <099b9433-2855-4f1b-b421-d078a5d82017@vondra.me> <1caea3b1-3e0b-4bdb-a630-75671f1f837a@data-bene.io> Content-Language: en-US From: Tomas Vondra In-Reply-To: <1caea3b1-3e0b-4bdb-a630-75671f1f837a@data-bene.io> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdefudejgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomhepvfhomhgrshcugghonhgurhgruceothhomhgrshesvhhonhgurhgrrdhmvgeqnecuggftrfgrthhtvghrnhepgfdvkeeuieefgeffieduveeukeelleejleeigfetvdfgffdvhfduteeitdfgkeefnecuffhomhgrihhnpehorhgrtghlvgdrtghomhenucfkphepkeeirdegledrvdeftddrvddtieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekiedrgeelrddvfedtrddvtdeipdhhvghloheplgdutddrudefjedrtddrvdgnpdhmrghilhhfrhhomhepthhomhgrshesvhhonhgurhgrrdhmvgdpnhgspghrtghpthhtohepvddprhgtphhtthhopegtvggurhhitgdrvhhilhhlvghmrghinhesuggrthgrqdgsvghnvgdrihhopdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/5/25 09:09, Cédric Villemain wrote: > Hi Tomas, > > > I haven't yet had time to fully read all the work and proposals around > NUMA and related features, but I hope to catch up over the summer. > > However, I think it's important to share some thoughts before it's too > late, as you might find them relevant to the NUMA management code. > > >> 6) v1-0006-NUMA-pin-backends-to-NUMA-nodes.patch >> >> This is an experimental patch, that simply pins the new process to the >> NUMA node obtained from the freelist. >> >> Driven by GUC "numa_procs_pin" (default: off). > > > In my work on more careful PostgreSQL resource management, I've come to > the conclusion that we should avoid pushing policy too deeply into the > PostgreSQL core itself. Therefore, I'm quite skeptical about integrating > NUMA-specific management directly into core PostgreSQL in such a way. > > > We are working on a PROFILE and PROFILE MANAGER specification to provide > PostgreSQL with only the APIs and hooks needed so that extensions can > manage whatever they want externally. > > The basic syntax (not meant to be discussed here, and even the names > might change) is roughly as follows, just to illustrate the intent: > > > CREATE PROFILE MANAGER manager_name [IF NOT EXISTS] >   [ HANDLER handler_function | NO HANDLER ] >   [ VALIDATOR validator_function | NO VALIDATOR ] >   [ OPTIONS ( option 'value' [, ... ] ) ] > > CREATE PROFILE profile_name >   [IF NOT EXISTS] >   USING profile_manager >     SET key = value [, key = value]... >   [USING profile_manager >     SET key = value [, key = value]...] >   [...]; > > CREATE PROFILE MAPPING >   [IF NOT EXISTS] >   FOR PROFILE profile_name >   [MATCH [ ALL | ANY ] ( >     [ROLE role_name], >     [BACKEND TYPE backend_type], >     [DATABASE database_name], >     [APPLICATION appname] >   )]; > > ## PROFILE RESOLUTION ORDER > > 1. ALTER ROLE IN DATABASE > 2. ALTER ROLE > 3. ALTER DATABASE > 4. First matching PROFILE MAPPING (global or specific) > 5. No profile (fallback) > > As currently designed, this approach allows quite a lot of flexibility: > > * pg_psi is used to ensure the spec is suitable for a cgroup profile > manager (moving PIDs as needed; NUMA and cgroups could work well > together, see e.g. this Linux kernel summary: https://blogs.oracle.com/ > linux/post/numa-balancing ) > > * Someone else could implement support for Windows or BSD specifics. > > * Others might use it to integrate PostgreSQL's own resources (e.g., > "areas" of shared buffers) into policies. > > Hope this perspective is helpful. Can you explain how you want to manage this by an extension defined at the SQL level, when most of this stuff has to be done when setting up shared memory, which is waaaay before we have any access to catalogs? regards -- Tomas Vondra