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 1qP12G-009jVT-HN for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 13:28:08 +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 1qP12E-00A890-40 for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 13:28:06 +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 1qP12D-00A88r-Qk for pgsql-hackers@lists.postgresql.org; Thu, 27 Jul 2023 13:28:05 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qP129-000hN1-MH; Thu, 27 Jul 2023 13:28:04 +0000 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-98e39784a85so475241566b.1; Thu, 27 Jul 2023 06:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690464479; x=1691069279; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=T/IbGoAU4ye4vZIGUme+mXfkJZ2zfnJpPT/AXOeBEbE=; b=JnJZC94o4xAF0guhK5wY6TL25vYXdKJZxb7rDrjicuCrNMAOtsqop4Kn4NjYW2dO82 TZWb8VAALtEO52heTa1gT/gT1+fTw4ooWqM2+YiSTCRY5k5Mgm33nGSiDc1eh8ArEHre Y4cfti+W+IAc03Xq9b4pR34eZ8sq6jjTv4RLyfSY3HrsPvZOAeDkmeT0EHnwQzI6nswg MjUe1bC0zdhKE5mJAb/1nhpwcevGOI9scjk4Vp7sIa5y5Ukp96aYxBkqZv8VLrlI+sFS MEZxjlmlUwoUiUtjfSROzxtOzBQhj2ZVDt6jW6yAdz7msOh0xLmW46VOgarVBdoqqEy+ xuZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690464479; x=1691069279; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T/IbGoAU4ye4vZIGUme+mXfkJZ2zfnJpPT/AXOeBEbE=; b=k206BTG37Sh52spC7mRNacbT6Ml9kQaJRKumFvns9L24rXWVIKbpbb1I391KYrVpxG bvCWhKxDLCi+RbHaRbOXQV8/7estlfOlhzDm5PUmXb++kOnljiZkjt12VmCZshIILXOF rHFYU89lP+GkLHmcMbXA1L9/hQK6JuG6zgVJ6h2aMs/4z9K4s6iFquQ63CfSgaslixKw v0yBnJ0iyfVNLa4w+fUhmPQeXsiZtf68olnbMco50yGoWeiJ+HqBZKINfY2ZXr0kZYec Wg09MrrOpAhNfKYm492bXZvaG+1XcP2I/VndQ4fHJlpvbFtZ6JBQt4nBnfzMmPz03A+L GAJg== X-Gm-Message-State: ABy/qLYTzWyMqz+DjLymfTxIP17Vs92OVgITwPX113Pn0mIxaffkYklD YdyWfSmPHtPe50bjGmf+c50= X-Google-Smtp-Source: APBJJlEYii1Sw0JkKPeaQirYgm6Fk4WW2pjJoGGrEVrLAI6A+H0BS4FhFlDb29VAjx5ZaiFnWVcN+Q== X-Received: by 2002:a17:906:8a79:b0:993:da0b:8783 with SMTP id hy25-20020a1709068a7900b00993da0b8783mr2112483ejc.3.1690464479175; Thu, 27 Jul 2023 06:27:59 -0700 (PDT) Received: from [192.168.3.128] ([147.161.229.10]) by smtp.gmail.com with ESMTPSA id jt9-20020a170906dfc900b0098e2969ed44sm777291ejc.45.2023.07.27.06.27.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jul 2023 06:27:58 -0700 (PDT) Message-ID: <2ce25d83-39ea-569d-b73f-d4e9a3eb9cc1@gmail.com> Date: Thu, 27 Jul 2023 15:27:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: Let's make PostgreSQL multi-threaded Content-Language: en-US To: Andres Freund , "Jonathan S. Katz" Cc: Heikki Linnakangas , Tom Lane , pgsql-hackers References: <31cc6df9-53fe-3cd9-af5b-ac0d801163f4@iki.fi> <4178104.1685978307@sss.pgh.pa.us> <4ce6c0f8-e8a4-1672-93fd-49d3fa975ee5@iki.fi> <20230607213721.al3etgcgtija3ytz@awork3.anarazel.de> From: David Geier In-Reply-To: <20230607213721.al3etgcgtija3ytz@awork3.anarazel.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 6/7/23 23:37, Andres Freund wrote: > I think we're starting to hit quite a few limits related to the process model, > particularly on bigger machines. The overhead of cross-process context > switches is inherently higher than switching between threads in the same > process - and my suspicion is that that overhead will continue to > increase. Once you have a significant number of connections we end up spending > a *lot* of time in TLB misses, and that's inherent to the process model, > because you can't share the TLB across processes. Another problem I haven't seen mentioned yet is the excessive kernel memory usage because every process has its own set of page table entries (PTEs). Without huge pages the amount of wasted memory can be huge if shared buffers are big. For example with 256 GiB of used shared buffers a single process needs about 256 MiB for the PTEs (for simplicity I ignored the tree structure of the page tables and just took the number of 4k pages times 4 bytes per PTE). With 512 connections, which is not uncommon for machines with many cores, a total of 128 GiB of memory is just spent on page tables. We used non-transparent huge pages to work around this limitation but they come with plenty of provisioning challenges, especially in cloud infrastructures where different services run next to each other on the same server. Transparent huge pages have unpredictable performance disadvantages. Also if some backends only use shared buffers sparsely, memory is wasted for the remaining, unused range inside the huge page. -- David Geier (ServiceNow)