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 1u7ci5-002fkw-4x for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Apr 2025 16:12:29 +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 1u7ci2-007g6u-TO for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Apr 2025 16:12:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u7ci2-007g6m-JW for pgsql-hackers@lists.postgresql.org; Wed, 23 Apr 2025 16:12:27 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u7ci0-001coZ-0C for pgsql-hackers@lists.postgresql.org; Wed, 23 Apr 2025 16:12:27 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5e677f59438so9597649a12.2 for ; Wed, 23 Apr 2025 09:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745424744; x=1746029544; 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=X6Z2w9WbpeQq3J+pyvqf7XlQVrVzak1501eMfSBt+68=; b=R1WA1kUWjjMqlwm8bvL7vBBtNXfaTU7WjBauRfhphz/MfhT+8hSZUThXMcF8Oo5t8M x2w+J+YSHW1chO0uoiJG/slfoX2KgBwUwLcY0d6R+EfqZk78XuRb5I971cq685LxKYE7 j0KWo1g1DQ+dxOW9zrz9JT13bzOIj1evxmSnD6tK/5ZNpt32CRj6qbHQLVI9w8vJYVRd 7W99tGfnPh4ofl7zSTRrWTM3i3Nr6QKA/RsLm6OfSVbphNGtR7vdUOpj2OeNb2Cv4/HL tJ90DUA5DfioZkyUWrEopjzAJd4EWDK+YDnbJttfULcYBfvYYLUFsDIIWYvDGCuSzWUq eWrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745424744; x=1746029544; 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=X6Z2w9WbpeQq3J+pyvqf7XlQVrVzak1501eMfSBt+68=; b=vXuxllAUZH7dFqP6g7EiGue5KtGTph6YjQX+YiA8ewM/5xVlAjlTr+bUFQCcOaUHzr OyZ7JIld0AWleK9cNaN3dOef53qbKRoQBexPyQlu7EFR58Lt+wL7ZJvvgXRxJkqOjzDG w4M1iyQ/BsQK3ornYpex0il5Z1HoG1y/f/dOm7FnO6IEjGLNwBwfR9ZyQywEqIeZW44M Vi8Y3Fx6zFYL8zXdsxQzJ6smyXTWiF9FBD5bODi0ZyZ4gPJk4VhUwoidLkY5RA1tvMQE fOZKi6BGz+ly8YaVZWlBK6MJumqCc7VH7CA+67DHLDHtABQtFEXi2caGLjMicTmdpUgm ZAjw== X-Forwarded-Encrypted: i=1; AJvYcCVGfQ0rGJ9Wsn7dMEnoo+S9fvI31PmJzg4r8iYwrYgEBNnJ6g/acAsFlmGEfWaateVpFO1ya4HFDrIqYv2T@lists.postgresql.org X-Gm-Message-State: AOJu0YxRBGJufltble1vHHWZVHageR7A2bDaa36Ii8jqJETy0fA7t5OI /MkduP7xdmkxaeUcdl08sw20DBlls7HnZP46KGFWp/oJjAxxgsFZjd1c+y+y4W4AfWqocTeg4It pVxg5rKRdIKepKB/sciAPo4XbipKsYkm8 X-Gm-Gg: ASbGncvjin1vzWOSoeGGfjUkk0mxB/rMO1IKJjgMfRaoBRq3Szqc+LIxXd1VngeBWta bVW2TwS9i4aaK/fM7ZoMy3ZrGRqTW2crc9eHSwtZJuGAGHh7ZgAmELUzat7qME7sRpfaEATESxX ImtI9jReywzFblgS+8oS5z4Q== X-Google-Smtp-Source: AGHT+IFCz5bXzhZ/uxcvBS9jfQKaRUet/VZF5Iiw0qrw1cpf0/RxVu5b8o/BOYlieVVHcD3n2acsr5/Jm16IEWlSDcs= X-Received: by 2002:a17:906:7949:b0:ac7:edfb:5210 with SMTP id a640c23a62f3a-acb74b0d084mr1919764266b.20.1745424743527; Wed, 23 Apr 2025 09:12:23 -0700 (PDT) MIME-Version: 1.0 References: <8EBFBFBC-DAC2-4521-AE16-069F7FD8EFBC@postgresql.org> In-Reply-To: <8EBFBFBC-DAC2-4521-AE16-069F7FD8EFBC@postgresql.org> From: Robert Haas Date: Wed, 23 Apr 2025 12:12:11 -0400 X-Gm-Features: ATxdqUEP6HURatG8sCb2Y_kaNzfvaXs6IQxSvc0hzrWPxycqZD2C0j69YHN4PLA Message-ID: Subject: Re: pgsql: Add function to get memory context stats for processes To: Daniel Gustafsson Cc: Andres Freund , PostgreSQL Hackers , Rahila Syed 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 Tue, Apr 22, 2025 at 4:12=E2=80=AFAM Daniel Gustafsson wrote: > Do you mean that an interrupt handler will make DSA allocations? I don't= think > that would be something we'd want to allow regardless of this patch. Or = did I > misunderstand the above? My primary concern about the patch is that ProcessGetMemoryContextInterrupt() can be called from any CHECK_FOR_INTERRUPTS() and calls lots of DSA functions, including dsa_create() and, via PublishMemoryContext(), dsa_allocate0(). I'm shocked to hear that you and Andres think that's safe to do at any current or future CHECK_FOR_INTERRUPTS() anywhere in the code; but Andres seems very confident that it's fine, so perhaps I should just stop worrying and be happy that we have the feature. I thought that the issues here would be similar to https://commitfest.postgresql.org/patch/5473/ and https://commitfest.postgresql.org/patch/5330/ where it seems we need to go to fairly extraordinary lengths to try to make the operation safe -- the proposal there is essentially to have a CFI handler run around the executor state tree and replace every ExecProcNode pointer with a pointer to some new wrapper function which in turn does the actual query-plan printing. Even that requires some tricky footwork to get right, but the core idea is that you can't imagine that CHECK_FOR_INTERRUPTS() is a safe place to do arbitrary stuff, so you have to use it to trigger the actual work at some later point where it will be safe to do the stuff that you want to do. I suppose the difference in this case is that memory-allocation is a lower-level subsystem than query execution and therefore there are presumably fewer places where it's not safe to assume that you can do memory-allocation type operations. But I at least feel like DSA is a pretty high-level system that I wouldn't want to count on being able to access from a fairly-arbitrary point in the code, which is why I'm quite astonished to hear Andres basically saying "don't worry, it's all fine!". But my astonishment does not mean that he is wrong. --=20 Robert Haas EDB: http://www.enterprisedb.com