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 1u0XG7-002qX4-Kp for pgsql-committers@arkaria.postgresql.org; Fri, 04 Apr 2025 02:58:19 +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 1u0XG5-00CWkO-Vi for pgsql-committers@arkaria.postgresql.org; Fri, 04 Apr 2025 02:58:17 +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 1u0XG5-00CWi1-Nk for pgsql-committers@lists.postgresql.org; Fri, 04 Apr 2025 02:58:17 +0000 Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u0XG3-002qIH-2L for pgsql-committers@lists.postgresql.org; Fri, 04 Apr 2025 02:58:16 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id A23CD44281; Fri, 4 Apr 2025 02:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1743735492; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8FKM1bw4+1TwjhjhncA7kJ571nNTksW0x1SKZv2SpLg=; b=ngvRgsAltc3V/ejhXecwYQtlHo+w6kNul+0y3yejjfm6f6Xzyv1yEGkr/UZea6n04Ap0QI JTTj1WHx16wFgbWNxSyU2X9rNh1RIpSCzEga50VWb2S2EFXXcj8gIBz/BeEa67mlEFf1A0 ozXf0P8qUQ072ZPzcKiZfAVtU1ipDnfGghXrWdfxXIo0BgaWiKMdASp1bnIdLRy1FTRNaY Pl+6fQDmMksO+FvHVSC7DG7e2qYVWpD9XyDiemcUnHGizhyTeUpYWld9TDOzYQXNfEfLf5 Li/Ypk31PGBopZKdB1iQ8ZD16MPqJu+/9uowGwTcs84wA7t68U7TfuWiWB6QRw== Message-ID: <3d36f787-8ba5-4aa2-abb1-7ade129a7b0e@vondra.me> Date: Fri, 4 Apr 2025 04:58:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pgsql: Improve accounting for memory used by shared hash tables From: Tomas Vondra To: David Rowley , Tomas Vondra Cc: pgsql-committers@lists.postgresql.org References: <46c20602-41e3-47b7-aa1d-7d1d2478e4f6@vondra.me> Content-Language: en-US In-Reply-To: <46c20602-41e3-47b7-aa1d-7d1d2478e4f6@vondra.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-State: clean X-GND-Score: 0 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduledtfedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecunecujfgurhepkfffgggfuffhvfevfhgjtgfgsehtjeertddtvdejnecuhfhrohhmpefvohhmrghsucggohhnughrrgcuoehtohhmrghssehvohhnughrrgdrmhgvqeenucggtffrrghtthgvrhhnpefhgefgleejvefgjeetuedvhffhudetveelgfeugfduledvffejleegjefhteffkeenucfkphepkeeirdegledrvddvledrudelfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekiedrgeelrddvvdelrdduleefpdhhvghloheplgdutddrudefjedrtddrvdgnpdhmrghilhhfrhhomhepthhomhgrshesvhhonhgurhgrrdhmvgdpnhgspghrtghpthhtohepfedprhgtphhtthhopegughhrohiflhgvhihmlhesghhmrghilhdrtghomhdprhgtphhtthhopehtohhmrghsrdhvohhnughrrgesphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepphhgshhqlhdqtghomhhmihhtthgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/4/25 02:41, Tomas Vondra wrote: > On 4/4/25 01:43, Tomas Vondra wrote: >> On 4/4/25 00:57, David Rowley wrote: >>> On Thu, 3 Apr 2025 at 04:16, Tomas Vondra wrote: >>>> Improve accounting for memory used by shared hash tables >>> >>> I've not looked into why, but this is causing an issue in the >>> join_rel_hash during add_join_rel(). See the attached script. >>> >>> ERROR: pfree called with invalid pointer 0x60a15edc44e0 (header >>> 0x0000002000000008) >>> >> >> Thanks for the report and reproducer. I'll take a look tomorrow. >> > > I took a quick look, and I think the reason is fairly simple - the > commit allocates the header and the directory as a single chunk. And for > shared hash tables that's fine, because those have non-expandable > directory. But the patch does the same thing for non-shared hash tables > (not intentionally), which means that if we end up expanding the hash, > it fails in dir_realloc(). Because hashp->dir is not a separately > allocated chunk. > > This is clearly a bug in the patch, I should have caught this during a > review. But I'm also quite surprised none of the regression tests seems > to expand the hash table ... > > I'll think about a way to fix this tomorrow. > I ended up reverting this. Unfortunately, the patch assumed the directory is pre-allocated and not expanding in more places. I wasn't sure how long would it take me to fix this, or how invasive the fix would be. It seems more appropriate to revert and then maybe apply a reworked patch (not going to happen for PG18). Thanks for the report, sorry for missing the issue in the first place. -- Tomas Vondra