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 1uZs5Y-009Nhj-Li for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 14:17:28 +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 1uZs5W-00DM5Z-Pv for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 14:17:27 +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 1uZs5W-00DM5Q-CV for pgsql-hackers@lists.postgresql.org; Thu, 10 Jul 2025 14:17:27 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uZs5V-006aOZ-05 for pgsql-hackers@lists.postgresql.org; Thu, 10 Jul 2025 14:17:26 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-454df871875so2291415e9.0 for ; Thu, 10 Jul 2025 07:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752157043; x=1752761843; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x8JH14R90ZhdwgMIF3GRtyCE9NOb3GGk+BfpOpZYBsA=; b=lbfL0DRalTJ3is9hDOGj9KNTy0LVms2VqzHd8JhUj378dlfUAp9yyq1+kFigrR4eTw OZ3yevUKkcIBI3SuVkMfmARZjgFTwiBF6PmVReOOtO3HOfBqJIZERziCQflbv/krLPTK sIV5BdL51vG9wpVU+KbAt22Ozlv+MPtEQM3wHPUbB98jpruTtABhdQAaV2ifT+DhbOAr FVkkPTZU19s3i4U429+F8R/d4zUzugAvVPL6GI96OnoHA0/zaOT3f1u7b2gkLAhOItJm W6Ka6gOKX6MoDYxoEZDdAIu2QfT+M2nnIIh5sv88Td0b/x3BDujYbvjMiT0n0wtb7ZvP hsmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752157043; x=1752761843; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=x8JH14R90ZhdwgMIF3GRtyCE9NOb3GGk+BfpOpZYBsA=; b=lAeQaN6bM1jVGMPL4fx4jIDu/GOtEHXGV+XiO/w8GbixuKfphK12+B3Q5bbeDAxeLt lyGfWjEBvslgyPLPRvh1viv0VyCXqCATjjCskEfrOuAroxeSbEhvM0Mu0XB5Zf2Yqr1o ZmnKbfZKJ8tbo86zJ3LKhSkKfC6SaCTijLqXbQfpK0u9fcL+oDUmMEME1eEzVbRs/isj PYgfnanImym8wPjyp2oSB0pYzwHnPgPcNz+8cUmJqs87un+3vyAPsyM5y37NwFWuQOtJ r7X94+n0W43TLywEZ+2o991O8FRnu4INM5B0FgYmySnB3nlpZUdYS7pOFxHUp2fTuwOF wRzA== X-Forwarded-Encrypted: i=1; AJvYcCUNGwgL2hFu2cU7FE47y2BsEqMufyu8s+6lQ2dL4XWD81A+36Dht1jJS4mTcsaciqMkoBW4ch5F6kgvQ6R7@lists.postgresql.org X-Gm-Message-State: AOJu0Ywpq/kuBnyL5SfxNEjHQR7nFhcCM9mEQWQhWuNCque3ZbA2bcKt 3jhD6jyfP5HB7BQeib+GN7QFB2sYR3/JPyJwO61bxNaFZ21IM59uHE4Z X-Gm-Gg: ASbGncuT8pP5gPbCI2+az0mqo/t/VYLfYncXaz0GHYUsttH4sG/jvKWcVNlocd/bG8D Q9obptIDw0siMMc51D9q6xW/cD0haqv4BxeBC9dgcQ4wOG22VPg5LcLwh9hGGHZ/NqMREfXLnwi +h5iHSHaEu9ojmtbuqCotkYY6zTWrzCuK9/IfRiRfsCIeAyxhBkIGu1tPiAd2Hdoaybb/k19cab YyXrsRyK2DT3vpNi4c9x0dQdsJnXY/kIWA5R9Jy3ahi8NAPKRUrIwHjtm2AXLDY3ZxSADei+B08 TK+P/IZ+urfD+mMAI+lDim1ZIuplm3YI6tjZ5sORXnCOh2art/WEXMz0PTidFSv9hVYkwNaHCgY 9TaM1J6MMQ7dDLtdwrcLm3zgEafMSjEgTn9XyMSNMgs/so/MaZa9b2L8rY7woSaxr3IPKYzUXNj RxW5znmKVuSNzFL1r8k8Q3HIZ0DhY/ X-Google-Smtp-Source: AGHT+IFfFwpgln8oISmv5uURGtbmhopBKfAccdwgNdihwtGoUYoSptlCyZB/oIEi6L6Rjz1M4CAvKg== X-Received: by 2002:a05:600c:4f87:b0:451:edc8:7806 with SMTP id 5b1f17b1804b1-454d53f34camr61848075e9.32.1752157042793; Thu, 10 Jul 2025 07:17:22 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-181-182.eu-west-3.compute.amazonaws.com. [15.237.181.182]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8e0d719sm2008767f8f.54.2025.07.10.07.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 07:17:22 -0700 (PDT) Date: Thu, 10 Jul 2025 14:17:21 +0000 From: Bertrand Drouvot To: Andres Freund Cc: Tomas Vondra , PostgreSQL Hackers Subject: Re: Adding basic NUMA awareness Message-ID: References: <099b9433-2855-4f1b-b421-d078a5d82017@vondra.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Jul 09, 2025 at 03:42:26PM -0400, Andres Freund wrote: > Hi, > > Thanks for working on this! Indeed, thanks! > On 2025-07-01 21:07:00 +0200, Tomas Vondra wrote: > > 1) v1-0001-NUMA-interleaving-buffers.patch > > > > This is the main thing when people think about NUMA - making sure the > > shared buffers are allocated evenly on all the nodes, not just on a > > single node (which can happen easily with warmup). The regular memory > > interleaving would address this, but it also has some disadvantages. > > > > Firstly, it's oblivious to the contents of the shared memory segment, > > and we may not want to interleave everything. It's also oblivious to > > alignment of the items (a buffer can easily end up "split" on multiple > > NUMA nodes), or relationship between different parts (e.g. there's a > > BufferBlock and a related BufferDescriptor, and those might again end up > > on different nodes). > > Two more disadvantages: > > With OS interleaving postgres doesn't (not easily at least) know about what > maps to what, which means postgres can't do stuff like numa aware buffer > replacement. > > With OS interleaving the interleaving is "too fine grained", with pages being > mapped at each page boundary, making it less likely for things like one > strategy ringbuffer to reside on a single numa node. > > There's a secondary benefit of explicitly assigning buffers to nodes, > > using this simple scheme - it allows quickly determining the node ID > > given a buffer ID. This is helpful later, when building freelist. I do think this is a big advantage as compare to the OS interleaving. > I wonder if we should *increase* the size of shared_buffers whenever huge > pages are in use and there's padding space due to the huge page > boundaries. Pretty pointless to waste that memory if we can instead use if for > the buffer pool. Not that big a deal with 2MB huge pages, but with 1GB huge > pages... I think that makes sense, except maybe for operations that need to scan the whole buffer pool (i.e related to BUF_DROP_FULL_SCAN_THRESHOLD)? > > 5) v1-0005-NUMA-interleave-PGPROC-entries.patch > > > > Another area that seems like it might benefit from NUMA is PGPROC, so I > > gave it a try. It turned out somewhat challenging. Similarly to buffers > > we have two pieces that need to be located in a coordinated way - PGPROC > > entries and fast-path arrays. But we can't use the same approach as for > > buffers/descriptors, because > > > > (a) Neither of those pieces aligns with memory page size (PGPROC is > > ~900B, fast-path arrays are variable length). > > > (b) We could pad PGPROC entries e.g. to 1KB, but that'd still require > > rather high max_connections before we use multiple huge pages. > > Right now sizeof(PGPROC) happens to be multiple of 64 (i.e. the most common > cache line size) Oh right, it's currently 832 bytes and the patch extends that to 840 bytes. With a bit of reordering: diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 5cb1632718e..2ed2f94202a 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -194,8 +194,6 @@ struct PGPROC * vacuum must not remove tuples deleted by * xid >= xmin ! */ - int procnumber; /* index in ProcGlobal->allProcs */ - int pid; /* Backend's process ID; 0 if prepared xact */ int pgxactoff; /* offset into various ProcGlobal->arrays with @@ -243,6 +241,7 @@ struct PGPROC /* Support for condition variables. */ proclist_node cvWaitLink; /* position in CV wait list */ + int procnumber; /* index in ProcGlobal->allProcs */ /* Info about lock the process is currently waiting for, if any. */ /* waitLock and waitProcLock are NULL if not currently waiting. */ @@ -268,6 +267,7 @@ struct PGPROC */ XLogRecPtr waitLSN; /* waiting for this LSN or higher */ int syncRepState; /* wait state for sync rep */ + int numa_node; dlist_node syncRepLinks; /* list link if process is in syncrep queue */ /* @@ -321,9 +321,6 @@ struct PGPROC PGPROC *lockGroupLeader; /* lock group leader, if I'm a member */ dlist_head lockGroupMembers; /* list of members, if I'm a leader */ dlist_node lockGroupLink; /* my member link, if I'm a member */ - - /* NUMA node */ - int numa_node; }; That could be back to 832 (the order does not make sense logically speaking though). Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com