Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTYOx-0004Sy-UE for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Sep 2022 00:49:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oTYOw-0000kL-M2 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Sep 2022 00:49:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTYOw-0000kC-CY for pgsql-hackers@lists.postgresql.org; Thu, 01 Sep 2022 00:49:46 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oTYOp-0002K2-TB for pgsql-hackers@lists.postgresql.org; Thu, 01 Sep 2022 00:49:45 +0000 Received: by mail-wm1-x32e.google.com with SMTP id h1so8188312wmd.3 for ; Wed, 31 Aug 2022 17:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; 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; bh=A0pF/3d1pntKqIHx5LlKxKH2d3t1VUCZXaZvnhh0/0M=; b=BSG4Pt0lSzX0fAkcmomcZ58zJE70CY7D9wDOstibQBD8MGjVrcIqZibDscuuU4ayKN S/LcED5iMm9Sxd01BTuH30aXOekIEEUjt7QsHSKtZntD8cEKzt1/eftWlRqx8EInjuqD H9Jo72aZRUe/clteMmLArn2Oaw8MUEkmu1EpS2a3It7hl5fBjqzA1W+pExF21i30IZTV VVtYQ3cumvoGZ0jTq4rKsRU2dUOo5zoyOjpfZMA6nzvyDna/sOtNwmhwQllad97alPoq FaMYMuFKBcX0ltkbawugW6pBZY1VqHhQ7IEO92yG0Z6nMOZVL+c0yXeSQ+C1MG2EIaIJ X8cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=A0pF/3d1pntKqIHx5LlKxKH2d3t1VUCZXaZvnhh0/0M=; b=ntir31crlBENqrSAMbmpJJsDswNdgtjvIlttNzaFFq7f23Wzz4pJOQRO348iyi+79h NZu65pJS/GAAE4yJkTHcZqnUfR5Cko8iOnsKON96qCaDDRcu6gBMdj/KNn8dkI9m1rtC +E84a/jOJBcpETX+NujvXCR0IHMiClPFHuBGYDapuSVfuqY2b3ijp2hWdZOVFDjsYLET A7qRI96U+vdPc1ggdhAfpYLwI6jWNhGTMd6+IzCo9cN8nqGK6FzkYZxrGDeAgJc5pYC4 21NvQ9l/PX4I23ABpxm/kzxmUTAS76+zLs2UP2jHQK9tFIJyHGZbHQ8+MHmIaWdvNjRm 4yvg== X-Gm-Message-State: ACgBeo11CBDpMWvkXrOeeDPhlUOR/Af4jRaY64aUxEjjI3VfZ3AaE/hO IrZkwu0CJw/HL3PmQDIij5rNP34CM6/fpDx7z30bgMeghe9g2ebSAQAeQqDxc26vZDAv+AbXL/V VfjiyN+RAhFrlrF19eE48K6+t+OpM9dpAjN08BS4QxiIbPXl8oe+qWKImBsYY6wOsZ3XPokxnC3 Jn38l4HtP2fqNbl/BzLXKl7/otziAPHqZ9a0EWY8omrnz/xWODD6F2 X-Google-Smtp-Source: AA6agR5JW2nMemI+7Q3pXcC6izvdYsX0YGz8aH9yioEJAPmq0HDZ0RMnzn18RypslsM+QJZ1x2NK0Q== X-Received: by 2002:a05:600c:4fc4:b0:3a5:c9ed:ca2 with SMTP id o4-20020a05600c4fc400b003a5c9ed0ca2mr3525147wmq.73.1661993378242; Wed, 31 Aug 2022 17:49:38 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-229-52.bb.vodafone.cz. [86.49.229.52]) by smtp.gmail.com with ESMTPSA id u14-20020adfdd4e000000b0021f131de6aesm13292478wrm.34.2022.08.31.17.49.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Aug 2022 17:49:37 -0700 (PDT) Message-ID: Date: Thu, 1 Sep 2022 02:49:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: Reducing the chunk header sizes on all memory context types Content-Language: en-US To: Tom Lane Cc: David Rowley , Amit Kapila , Andres Freund , Robert Haas , Yura Sokolov , PostgreSQL Developers References: <3137572.1661780863@sss.pgh.pa.us> <3205803.1661786437@sss.pgh.pa.us> <3478405.1661824539@sss.pgh.pa.us> <3605020.1661865981@sss.pgh.pa.us> <3613565.1661869054@sss.pgh.pa.us> <60560f75-8b15-a7cc-67bc-a7bf3e8472ee@enterprisedb.com> <209211.1661991821@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: <209211.1661991821@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/1/22 02:23, Tom Lane wrote: > Tomas Vondra writes: >> Focusing on the aset, vast majority of allocations (60M out of 64M) is >> small enough to use power-of-2 logic, and we go from 6.3GB to 8.2GB, so >> ~30%. Not great, not terrible. > > Not sure why this escaped me before, but I remembered another argument > for not forcibly adding space for a sentinel: if you don't have room, > that means the chunk end is up against the header for the next chunk, > which means that any buffer overrun will clobber that header. So we'll > detect the problem anyway if we validate the headers to a reasonable > extent. > > The hole in this argument is that the very last chunk allocated in a > block might have no following chunk to validate. But we could probably > special-case that somehow, maybe by laying down a sentinel in the free > space, where it will get overwritten by the next chunk when that does > get allocated. > > 30% memory bloat seems like a high price to pay if it's adding negligible > detection ability, which it seems is true if this argument is valid. > Is there reason to think we can't validate headers enough to catch > clobbers? > I'm not quite convinced the 30% figure is correct - it might be if you ignore cases exceeding allocChunkLimit, but that also makes it pretty bogus (because large allocations represent ~2x as much space). You're probably right we'll notice the clobber cases due to corruption of the next chunk header. The annoying thing is having a corrupted header only tells you there's a corruption somewhere, but it may be hard to know which part of the code caused it. I was hoping the sentinel would make it easier, because we mark it as NOACCESS for valgrind. But now I see we mark the first part of a MemoryChunk too, so maybe that's enough. OTOH we have platforms where valgrind is either not supported or no one runs tests with (e.g. on rpi4 it'd take insane amounts of code). In that case the sentinel might be helpful, especially considering alignment on those platforms can cause funny memory issues, as evidenced by this thread. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company