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 1qqjo1-000nq2-BG for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Oct 2023 00:44:01 +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 1qqjnz-0028xk-3G for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Oct 2023 00:43:59 +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 1qqjny-0028wA-17 for pgsql-hackers@lists.postgresql.org; Thu, 12 Oct 2023 00:43:59 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qqjnv-0002TK-R7 for pgsql-hackers@postgresql.org; Thu, 12 Oct 2023 00:43:57 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 9F16E32009D4; Wed, 11 Oct 2023 20:43:53 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 11 Oct 2023 20:43:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1697071433; x=1697157833; bh=sf MC9AGmk6slnz2bwT70BXSZjU53btos0ySycIglFds=; b=ETWfgjufIKSaWK1w3D XFUGphJliQfz7ONIAGeAUVljFRs7eHFmU0rt8av5RIAk7RyaYp+b2OlfoANE7oVu vt1jrG/0vgq5/vYEuYL9cc1rmNGPztXsIo/GSUj2FuY/k9C1zz6gzErZYchxSg0q fGHou8N+Ek7AyqfJ3Pk7jqM4s0GZcCPnqBi3yfbKk2lp0eCGMou9vt6uY5Hq5TQb qD6mj7q6hoF5lrVNZXSXvu0aL7JtXvthvI00YwuVFiE95o9cV0ZtGZfs8wdIm+zb n7IZz+ia+PWZOGM2KMCzTycnCfIrDgVcuCXWCFCNRkbzHS4n7vxTX9x+P7q9QfbK Eekg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1697071433; x=1697157833; bh=sfMC9AGmk6sln z2bwT70BXSZjU53btos0ySycIglFds=; b=UyIxe1B12F0CTIS2MGM/C0CCsi9RX BE7SVME6nVwfx+eHNEbqSLcZMXHtfq9KUarJhfQGh3wXKghYlEEt5OXG2je4h2eW wnXsNc3eQEaxw+6OmDgX8RgtroKlPlP+W5k6XHgd00ryzsUvL5n7stWXAv4wr2aL 5mR23UXWCAp/NVDLgcQo4jsaUSvzfQ56rBGw3znHpzeeEtQ4O4yJSiL5j5vK2yvT ZuLr9S8xOggzjh99HS6jA9L+OQ1nvHuhhDdrwFJpJ7i3bUgAAM46jzax12tXEyxE mZi8tdW0G8/aKcnk7KfJjiaAb174BiBzZPcX3/MlDj0NAu3GntUwmlNgA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrheelgdefhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedvffefvefhteevffegieetfefhtddvffejvefhueetgeeludehteevudei tedtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 11 Oct 2023 20:43:51 -0400 (EDT) Date: Wed, 11 Oct 2023 17:43:46 -0700 From: Andres Freund To: Melanie Plageman Cc: Pg Hackers , Peter Geoghegan , Jeff Davis , Robert Haas Subject: Re: Eager page freeze criteria clarification Message-ID: <20231012004346.dvdltiwjvsb7ei6v@awork3.anarazel.de> References: 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, Robert, Melanie and I spent an evening discussing this topic around pgconf.nyc. Here are, mildly revised, notes from that: First a few random points that didn't fit with the sketch of an approach below: - Are unlogged tables a problem for using LSN based heuristics for freezing? We concluded, no, not a problem, because aggressively freezing does not increase overhead meaningfully, as we would already dirty both the heap and VM page to set the all-visible flag. - "Unfreezing" pages that were frozen hours / days ago aren't too bad and can be desirable. The main thing we are worried about is repeated freezing / unfreezing of pages within a relatively short time period. - Computing an average "modification distance" as I (Andres) proposed efor each page is complicated / "fuzzy" The main problem is that it's not clear how to come up with a good number for workloads that have many more inserts into new pages than modifications of existing pages. It's also hard to use average for this kind of thing, e.g. in cases where new pages are frequently updated, but also some old data is updated, it's easy for the updates to the old data to completely skew the average, even though that shouldn't prevent us from freezing. - We also discussed an idea by Robert to track the number of times we need to dirty a page when unfreezing and to compare that to the number of pages dirtied overall (IIRC), but I don't think we really came to a conclusion around that - and I didn't write down anything so this is purely from memory. A rough sketch of a freezing heuristic: - We concluded that to intelligently control opportunistic freezing we need statistics about the number of freezes and unfreezes - We should track page freezes / unfreezes in shared memory stats on a per-relation basis - To use such statistics to control heuristics, we need to turn them into rates. For that we need to keep snapshots of absolute values at certain times (when vacuuming), allowing us to compute a rate. - If we snapshot some stats, we need to limit the amount of data that occupies - evict based on wall clock time (we don't care about unfreezing pages frozen a month ago) - "thin out" data when exceeding limited amount of stats per relation using random sampling or such - need a smarter approach than just keeping N last vacuums, as there are situations where a table is (auto-) vacuumed at a high frequency - only looking at recent-ish table stats is fine, because we - a) don't want to look at too old data, as we need to deal with changing workloads - b) if there aren't recent vacuums, falsely freezing is of bounded cost - shared memory stats being lost on crash-restart/failover might be a problem - we certainly don't want to immediate store these stats in a table, due to the xid consumption that'd imply - Attributing "unfreezes" to specific vacuums would be powerful: - "Number of pages frozen during vacuum" and "Number of pages unfrozen that were frozen during the same vacuum" provides numerator / denominator for an "error rate" - We can perform this attribution by comparing the page LSN with recorded start/end LSNs of recent vacuums - If the freezing error rate of recent vacuums is low, freeze more aggressively. This is important to deal with insert mostly workloads. - If old data is "unfrozen", that's fine, we can ignore such unfreezes when controlling "freezing aggressiveness" - Ignoring unfreezing of old pages is important to e.g. deal with workloads that delete old data - This approach could provide "goals" for opportunistic freezing in a somewhat understandable way. E.g. aiming to rarely unfreeze data that has been frozen within 1h/1d/... Around this point my laptop unfortunately ran out of battery. Possibly the attendees of this mini summit also ran out of steam (and tea). We had a few "disagreements" or "unresolved issues": - How aggressive should we be when we have no stats? - Should the freezing heuristic take into account whether freezing would require an FPI? Or whether page was not in s_b, or ... I likely mangled this substantially, both when taking notes during the lively discussion, and when revising them to make them a bit more readable. Greetings, Andres Freund