Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ecAAy-0000sq-Dc for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jan 2018 13:24:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ecAAw-0003ZV-M7 for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jan 2018 13:24:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ecAAv-0003ZL-U6 for pgsql-hackers@lists.postgresql.org; Thu, 18 Jan 2018 13:24:14 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ecAAs-0003dC-7k for pgsql-hackers@postgresql.org; Thu, 18 Jan 2018 13:24:12 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 8EC8620AF3; Thu, 18 Jan 2018 08:24:07 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Thu, 18 Jan 2018 08:24:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=3KYa6M 54XwBokoFL0tiowbYowTOUxnuX/ZG3EMRQA20=; b=f2ft1dxghYA0EHjQYVvK0I fZ6nZUQzVsOMEBRBnCuz0TPSSBnmXwWYFArK40HBYSU/5ge8ZmMBOeyomjB+puyH puog5wkU8vtLOomjqdbnwrTbXIojUjsvxoRYHoZxQ5TcFeTu4db5xDyyIKVcpKBM kefoiYpCJakAIXOfUr/PctLIUkJvaPN4/1eJ6TH4yUHj86s8pIs6rciw7OFBxrwV aplHLvmvbxd1psOzGChOgPp4Mo1niFV8fqIH9EJjtYxQLcaFYh75xg4FlLAjHpvM yw+ULyN8+uxjd2OFwpz/1NlyXOPGi7dnoZ6JSC7ANGC7mBeneAh9bjlicCd03t2Q == X-ME-Sender: Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 48A4C24691; Thu, 18 Jan 2018 08:24:07 -0500 (EST) Subject: Re: PATCH: logical_work_mem and logical streaming of large in-progress transactions To: Tomas Vondra , Greg Stark References: <688b0b7f-2f6c-d827-c27b-216a8e3ea700@2ndquadrant.com> <5d00346a-b565-7fde-c6da-35f39c72936a@2ndquadrant.com> Cc: PostgreSQL Hackers From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <4d7ed7b8-df43-9b79-b04e-ad4c43ef519c@2ndquadrant.com> Date: Thu, 18 Jan 2018 08:24:06 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/12/18 23:19, Tomas Vondra wrote: > Wouldn't the 'toplevel_by_lsn' be suitable for this? Subtransactions > don't really commit independently, but as part of the toplevel xact. And > that list is ordered by LSN, which is pretty much exactly the order in > which we see the transactions. Yes indeed. There is even ReorderBufferGetOldestTXN(). > Another somewhat non-intuitive detail is that because ReorderBuffer > switched to Generation allocator for changes (which usually represent > 99% of the memory used during decoding), it does not reuse memory the > way AllocSet does. Actually, it does not reuse memory at all, aiming to > eventually give the memory back to libc (which AllocSet can't do). > > Because of this evicting the youngest transactions seems like a quite > bad idea, because those chunks will not be reused and there may be other > chunks on the blocks, preventing their release. Right. But this raises the question whether we are doing the memory accounting on the right level. If we are doing all this tracking based on ReorderBufferChanges, but then serializing changes possibly doesn't actually free any memory in the operating system, that's no good. Can we get some usage statistics out of the memory context? It seems like we need to keep serializing transactions until we actually see the memory context size drop. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services