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.96) (envelope-from ) id 1vw1hZ-00G9iB-0w for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 17:32:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vw1hW-005EXf-1P for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 17:32:30 +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.96) (envelope-from ) id 1vw1hV-005EXA-1W for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 17:32:30 +0000 Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vw1hS-00000001XGE-0ELy for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 17:32:28 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id EB85BEC010E; Fri, 27 Feb 2026 12:32:25 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 27 Feb 2026 12:32:25 -0500 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:subject :subject:to:to; s=fm3; t=1772213545; x=1772299945; bh=3gmug7ipSp hhkhU7GpH8pC5RkQ7nk624SxCk2CzwmWo=; b=j5S8HByrc8pAYFwZwKyGZzjebK u/a+1+wmCTHZJPS1UEMb1EcxvUM+X1782XC56bQejuuaMf1ZIIfdNb+emBFAIPRi SXEcDqDoKCgiNPTrIOIxIF5aXOWVqUAuagJAGOr8dsrtfQX3oOavnPAImTp+yVOh C9gBKDLjizFhpJhlHmE6bOzqQRMYxMYw3SIQzMkHAbqcSJ1wKTZ4xswIUMybsyZU yFRlbjBLmvE5ns7WGL4owfQGqoURCeg7tQB0W56m0bBjiHF84iOevFAHiMeolVm8 GCLY6rThI887ZOhihhD7juR919hPB6CCDbNTHpLqxKUsQAjuqkHWJ0yaNH2Q== 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:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1772213545; x=1772299945; bh=3gmug7ipSphhkhU7GpH8pC5RkQ7nk624SxC k2CzwmWo=; b=O0w7/AAJA3eTww+GDO8X436uTGf2G1aWiMtV+IYBZzSLXJVwJPj qZzh4glSoCfy9DOCYqhwkLjD3y+nEw4x9L4z8iLns2KGcbnp31KmGmiTdLtusGmK teu0in7uXmv8HFfWUSEFAEryOMBUhSh/avMom/nnhjKpjDTq5k3NXVz1jojCR75M upeQfoPa3+bJIQbtG4st6aKviEuFZVyVXU6dclEgiF3S3FaI8dxnTThWlHoWwbKI Ud268eyY9P31DOLTJsq1OjZxs2DHMV4E7My5GCa4nqA3/ZYx0a81ZHciUEwLsz6j 3MlXteF1PhlfJuXaqjSl/ZtrUh1bLOXF5cg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvgeelieduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepgedtveeifeehjeefveelgeehgeeigeffiefhgfekleethfehueekueefleeg uddunecuffhomhgrihhnpehpohhsthhgrhdrvghsnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggv pdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehmrg hsrghordhfuhhjihhisehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgr tghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Feb 2026 12:32:25 -0500 (EST) Date: Fri, 27 Feb 2026 12:32:24 -0500 From: Andres Freund To: Fujii Masao Cc: PostgreSQL Hackers Subject: Re: Release postmaster working memory context in slotsync worker Message-ID: 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, On 2026-02-28 01:25:12 +0900, Fujii Masao wrote: > Child processes do not need the postmaster's working memory context and > release it at the start of their main function. However, the slotsync worker > appears to have missed this step. > > To avoid this unnecessary memory usage, I'd like to propose that the slotsync > worker release the postmaster's working memory context at startup. > A patch is attached. Obviously this inconsistency is not good. However: I think we should consider *not* releasing postmaster memory. Freeing the memory actually can lead to an *increase* in memory usage and a slight *decrease* in connection startup performance. The reason for that is that with fork, memory allocated in postmaster is handled by copy-on-write in the children. If the memory allocated by postmaster is freed in the children, the process of freeing requires some modifications to copy-on-write memory (leading to an increase in memory usage and page faults) and it allows the system allocator to reuse the malloc'd regions, which then leads to more copy on write. It's however annoying that the memory shows up in pg_backend_memory_contexts, so maybe what postmaster children should do is to instead is to move its parent to be NULL? That will still incur COW copying (due to modifying PostmasterContext's ->{parent,prevchild,nextchild} pointers), but only a single page, instead of multiple pages. Or perhaps PostmasterContext should just not be below TopMemoryContext, then we wouldn't need to do anything. The tradeoff might be different if postmaster modified its allocated memory more, since that also leads to CoW, but from what I can tell, that doesn't happen very much. See [1] for some numbers. Perhaps this is not worth worrying about - currently with openssl linked in, the bulk of the overhead is from that. But as the numbers in [1] show, the MemoryContextDelete(PostmasterContext) does make a difference. Greetings, Andres Freund [1] https://postgr.es/m/hgs2vs74tzxigf2xqosez7rpf3ia5e7izalg5gz3lv3nqfptxx%40thanmprbpl4el