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 1rhxoK-00EJyn-FP for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Mar 2024 20:24:20 +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 1rhxoH-00DwIY-NT for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Mar 2024 20:24:18 +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 1rhxoH-00DwIQ-Aq for pgsql-bugs@lists.postgresql.org; Wed, 06 Mar 2024 20:24:17 +0000 Received: from mail-yb1-xb34.google.com ([2607:f8b0:4864:20::b34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhxoE-003CCi-1a for pgsql-bugs@lists.postgresql.org; Wed, 06 Mar 2024 20:24:16 +0000 Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-dcbcea9c261so83235276.3 for ; Wed, 06 Mar 2024 12:24:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709756654; x=1710361454; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PweJQWJoqG7rEPemvJmvPBeL2QXECqKHQcTnZm1Q/NI=; b=FwtmIOBkowWTLYTdI4JKSuWajgU1HtOWzZgXmVGM8lNbkNMvUik5gfhU3rU4iMDtB3 zo8o35ZraU9/ahjldg58hWQCWRujQLVsHG3ZG2OB3Sd6yC3wsBLsTGeChghJd+kdNtxR kaBzcWg+D676IXqZghbsxf3Q0ICozhfr74Y5qUP+aDVCV1GKyhWRaZiKvJguj38VdREo s6mX8J7Sji1EfVnoyb0TdR1FN3fsFR9tqDnoTn2gRpEkQPx6SdtNv0Re1wBN3R+5Py7o vGFBEm1F2YUTiQkmmANzOv3FdLdCqRUqPHK+1rhqTK+h5N20MH213ptBa0TbiEbka7+8 1Nvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709756654; x=1710361454; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PweJQWJoqG7rEPemvJmvPBeL2QXECqKHQcTnZm1Q/NI=; b=K3e70+WQkW7hJZkOaEQBB69mz/+YZM4WgtqXHhOTnghbqF5EVVTbCG7n4yNEOZzheg gYryqagiOFh1ImUCE2xMPBmUtEmtjLK+QqCc77DD8gFije5L6kjyGeXPTe4fOjMFQnUV DJUyO20cmyHzJ3WqZBPXXQEekGoTGq5DGC3mYtvRRB6bgqqzKeRIv+0sSiqDhxht/0Az 0hc/1Ino3ZevytX8MNky7ChpIyPo99gh49cWSL3LuRSXiNUWwxZ8MB+FGOJzZur26xWE 5ZA4Ji3uljgoqbsx3eYoDCj7i7lvI3IaZq4Ek8HFwKafVTutSBRD49/AH7xiFGGdpMEv t4Bg== X-Forwarded-Encrypted: i=1; AJvYcCVl/mEJlD0mH0JSaXsBgJKZgKQHf2KmyC+R/jfPxCk6IVhrU9CEv6dcbUXcdVIr1Z+lr6+/RcvXlxabxHYNo7iXuBhKJdcIx358+lXGjXDG X-Gm-Message-State: AOJu0Yw0pwaBecFF8UtIxWTkl7DyRMeZG7p0sW0c8lipB5sfGnVTdq9d KH+zAUnS9C8dmZgQLQ0pYOCszdTsySNq4GA08CY2eYNPv/Z6MvjztzQO8Nu0INcAgvbnyqsJpCG lCBBQa165gSskQslydSsePbSveC8= X-Google-Smtp-Source: AGHT+IERTJPV1yxrzcKhSaOmVmAO/0U2Mgdjvx+rTvuldtdYF/ksurZd6eHI0jSQR5oB+fiHOnr/dKH97EPXGP9WnmM= X-Received: by 2002:a25:aa8b:0:b0:dcf:b5b7:c72 with SMTP id t11-20020a25aa8b000000b00dcfb5b70c72mr13006708ybi.0.1709756654337; Wed, 06 Mar 2024 12:24:14 -0800 (PST) MIME-Version: 1.0 References: <18374-ebb8113ce4d02f0d@postgresql.org> <3120721.1709395887@sss.pgh.pa.us> <3140126.1709405398@sss.pgh.pa.us> <3148162.1709409519@sss.pgh.pa.us> <3399097.1709501969@sss.pgh.pa.us> In-Reply-To: <3399097.1709501969@sss.pgh.pa.us> From: Alexander Korotkov Date: Wed, 6 Mar 2024 22:24:03 +0200 Message-ID: Subject: Re: BUG #18374: Printing memory contexts on OOM condition might lead to segmentation fault To: Tom Lane Cc: Alexander Lakhin , pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Mar 3, 2024 at 11:39=E2=80=AFPM Tom Lane wrote: >> I do think it's probably worth reducing MemoryContextDelete's stack > usage to O(1), just to ensure we can't get into stack trouble during > transaction abort. That's not hard at all, as attached. > > I tried to make MemoryContextResetChildren work similarly, but that > doesn't work because if we're not removing child contexts then we > need extra state to tell which ones we've done already. For the > same reason my idea for bounding the stack space needed by > MemoryContextStats doesn't seem to work. We could possibly make it > work if we were willing to add a temporary-use pointer field to all > MemoryContext headers, but I'm unconvinced that'd be a good tradeoff. For removing recursion from memory context processing, please check the patch by Heikki [1], and my slightly revised version [2]. Links. 1. https://www.postgresql.org/message-id/6b48c746-9704-46dc-b9be-01fe4137c8= 24%40iki.fi 2. https://www.postgresql.org/message-id/CAPpHfdtQVzkKgrxqKZE9yESnu7cAATVQb= GktVOSXPNWG7GOkhA%40mail.gmail.com ------ Regards, Alexander Korotkov