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 1v956Z-009fea-1W for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Oct 2025 17:16:02 +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 1v956Y-007NnO-0E for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Oct 2025 17:16:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v956X-007NnF-Mn for pgsql-hackers@lists.postgresql.org; Wed, 15 Oct 2025 17:16:00 +0000 Received: from relay3-d.mail.gandi.net ([2001:4b98:dc4:8::223]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v956U-002MZI-16 for pgsql-hackers@lists.postgresql.org; Wed, 15 Oct 2025 17:16:00 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id D39C01FD8E; Wed, 15 Oct 2025 17:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1760548552; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s2dRy02D6zHs7aYxvAJhIImt7Q7rlp8224hy4LdKenA=; b=fw6OfiTwVdkhaOdqlq7mh0+b0E79d8Br8gOynU6FumeYMF3/yfbATbqFnWR9Lyo4ybHshO QH8OifGalnqdabPFqdUvTUkwMNaFjryKTu+YgkrmxBdjyURE2nkcZIiH0kI0+kuwEQR6JA uqJU7OMtGuRbnIZfYfhi3lgNFZ2s6/ML3xHCQkG3P98hXyJesaJSV9JFIEVlb5v7TFFTe/ PwTz5Xgj0KruiFMCnbp2CytQ/qiekG+TsAdIlVte3zd45TJ+VliTKlmZlrcIqYyFPdgHyD gm5pEGyFc58XpGRPm2wz1GhVlsojzShMynYkwUMr6t0JfkEruIgGxm9iRVwOAA== Message-ID: <70128d4f-e93a-4795-a11c-e1b94d7aca73@vondra.me> Date: Wed, 15 Oct 2025 19:15:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Adding basic NUMA awareness From: Tomas Vondra To: Alexey Makhmutov , PostgreSQL Hackers Cc: Jakub Wartak , Andres Freund References: <5a2410f8-62a9-4483-bf0a-3a8331fb0808@vondra.me> <71a46484-053c-4b81-ba32-ddac050a8b5d@vondra.me> <1b5bf372-6d40-4022-bf4f-367ffb61ee51@vondra.me> <51e51832-7f47-412a-a1a6-b972101cc8cb@vondra.me> <874435bd-5e25-4a7c-a5d5-8ef0c262d788@vondra.me> <6636d842-e8a5-44bc-a206-6df415380a7b@vondra.me> <659c44a5-f616-492c-ab81-60273d2fe7f6@vondra.me> <9c31717c-fe38-4824-9bb7-e4f0ac4f1991@vondra.me> Content-Language: en-US In-Reply-To: <9c31717c-fe38-4824-9bb7-e4f0ac4f1991@vondra.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/13/25 13:09, Tomas Vondra wrote: > On 10/13/25 01:58, Alexey Makhmutov wrote: >> Hi Tomas, >> >> Thank you very much for working on this problem and the entire line of >> patches prepared! I've tried to play with these patches a little and >> here are some my observations and suggestions. >> >> In the current implementation we try to use all available NUMA nodes on >> the machine, however it's often useful to limit the database only to a >> set of specific nodes, so that other nodes can be used for other >> processes. In my testing I was trying to use one node out of four for >> the client program, so I'd liked to limit the database to the remaining >> nodes. I use a systemd service with AllowedMemoryNodes/AllowedCPUs to >> start the cluster, so the obvious choice for me was to use the >> 'numa_get_membind' function instead of 'numa_num_configured_nodes' to >> get the list of usable nodes. However, it is much easier to work with >> logical nodes in the [0; n] range inside the PG code, so I've decided to >> add mapping between 'logical nodes' (0-n in PG) to a set of physical >> nodes actually returned by 'numa_get_membind'. We may need to map number >> in both directions, so two translation tables are allocated and filled >> at the first usage of 'pg_numa' functions. It also seems to be a good >> idea to isolate all 'libnuma' calls inside 'pg_numa.c', so to keep all >> 'numa_...' calls in it and this also allows us to hide this mapping in >> static functions. Here is the patch, which I've used to test this idea: >> https://github.com/Lerm/postgres/ >> commit/9ec625c2bf564f5432375ec1d7ad02e4b2559161. This idea probably >> could be extended by adding some view to expose this mapping to the user >> (at least for testing purposes) and allow to explicitly override this >> mapping with a GUC setting. With such GUC setting we would be able to >> control PG memory usage on NUMA nodes without the need for systemd >> resource control or numactl parameters. >> > > I've argued to keep this out of scope for v1, to keep it smaller and > simpler. I'm not against adding that feature, though. If someone writes > a patch to support this. I suppose the commit you linked is a step in > that direction. > On second thought, I probably spoke too soon ... What I wanted to keep out of scope for v1 is ability to pick NUMA nodes from Postgres, e.g. setting a GUC to limit which NUMA nodes to use, etc. But that's not what you proposed here, clearly. You're saying we should find which NUMA nodes the process is allowed to run, and use those. Instead of just using all *configured* nodes. And I agree with that. I'll take a look at your commit 9ec625c. I'm not sure it's a good idea to have our internal "logical" node ID, and a mapping to external node ID values (exposed by the libnuma). I was thinking maybe we should use just the external IDs, but it's true that'd be tricky when iterating through nodes, etc. So maybe having such mapping is a good approach. Another thing I wasn't sure about is checking for memory-only nodes. For example rpi5 has a NUMA node for each 1GB of memory, and each CPU is mapped to all those nodes. For buffers this probably does not matter, but we probably should not use those NUMA nodes for PGPROC partitioning. regards -- Tomas Vondra