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 1qtbpc-00DAkr-KG for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Oct 2023 22:49:32 +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 1qtbpa-008qE4-E8 for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Oct 2023 22:49:31 +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 1qtbpZ-008qCz-P3 for pgsql-hackers@lists.postgresql.org; Thu, 19 Oct 2023 22:49:30 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qtbpX-001KOS-6N for pgsql-hackers@lists.postgresql.org; Thu, 19 Oct 2023 22:49:29 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 3FAC45F7B7; Thu, 19 Oct 2023 18:49:21 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=snowman.net; s=dkim; t=1697755761; 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: in-reply-to:in-reply-to:references:references; bh=XpyEoWX/GRETDFMmyh8CirTmU6Aq5wl7FDb4ah7QtIA=; b=EpDFduaeriFowS7wkOZsmkxWNvQggOKec07IE9yEg9orUz5cIw6vP9F4lxTZSGdyYjWPn3 V/ecn6nplK8M43aQbRSUCZqWbPdLJBpwpSAj6O75EBrXYo2zOvEmNhSFgLStE9qeuR4N69 hOxv0VzYetNTjQMK2eeaC1o7re3JwNc= Date: Thu, 19 Oct 2023 18:49:21 -0400 From: Stephen Frost To: Andres Freund Cc: Andrei Lepikhov , reid.thompson@crunchydata.com, Arne Roland , "pgsql-hackers@lists.postgresql.org" , vignesh C , Justin Pryzby , Ibrar Ahmed Subject: Re: Add the ability to limit the amount of memory that can be allocated to backends. Message-ID: References: <94184680049d6bda0c85f1759af24d8127cfe895.camel@crunchydata.com> <7912c911af51d5cf28c611190bf3d463b9209343.camel@crunchydata.com> <4edafedc0f8acb12a2979088ac1317bd7dd42145.camel@crunchydata.com> <268e0ac7-8a81-4d65-8b40-b62c4b3f1bf9@postgrespro.ru> <48548d40-634b-4943-a737-3c9d95eacf06@postgrespro.ru> <20231019222251.4qg6udcbtrwglogw@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="FUkEYrCLnLL9itaa" Content-Disposition: inline In-Reply-To: <20231019222251.4qg6udcbtrwglogw@awork3.anarazel.de> User-Agent: Mutt/2.1.4 (2021-12-11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --FUkEYrCLnLL9itaa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Andres Freund (andres@anarazel.de) wrote: > On 2023-10-19 18:06:10 -0400, Stephen Frost wrote: > > Ignoring such would defeat much of the point of this effort- which is to > > get to a position where we can say with some confidence that we're not > > going to go over some limit that the user has set and therefore not > > allow ourselves to end up getting OOM killed. >=20 > I think that is a good medium to long term goal. I do however think that = we'd > be better off merging the visibility of memory allocations soon-ish and > implement the limiting later. There's a lot of hairy details to get right= for > the latter, and even just having visibility will be a huge improvement. I agree that having the visibility will be a great improvement and perhaps could go in separately, but I don't know that I agree that the limits are going to be that much of an issue. In any case, there's been work ongoing on this and that'll be posted soon. I was just trying to address the general comment raised in this sub-thread here. > I think even patch 1 is doing too much at once. I doubt the DSM stuff is > quite right. Getting DSM right has certainly been tricky, along with other things, but we've been working towards, and continue to work towards, getting everything to line up nicely between memory context allocations of various types and the amounts which are being seen as malloc'd/free'd. There's been parts of this also reworked to allow us to see per-backend reservations as well as total reserved and to get those numbers able to be matched up inside of a given transaction using the statistics system. > I'm unconvinced it's a good idea to split the different types of memory > contexts out. That just exposes too much implementation detail stuff with= out a > good reason. DSM needs to be independent anyway ... as for the others, perhaps we could combine them, though that's pretty easily done later and for now it's been useful to see them split out as we've been working on the patch. > I think the overhead even just the tracking implies right now is likely t= oo > high and needs to be optimized. It should be a single math operation, not > tracking things in multiple fields. I don't think pg_sub_u64_overflow() s= hould > be in the path either, that suddenly adds conditional branches. You real= ly > ought to look at the difference in assembly for the hot functions. This has been improved in the most recent work and we'll have that posted soon, probably best to hold off from larger review of this right now- as mentioned, I was just trying to address the specific question in this sub-thread since a new patch is coming soon. Thanks, Stephen --FUkEYrCLnLL9itaa Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEwf6gbxKhD863zrx/7WyKOINHZFUFAmUxsm4ACgkQ7WyKOINH ZFXP+A/9ERIKeM0ToQFXfSMjPDCdmVJJocuNSbpICEY8JYmhZMr9hHcZvV8Q+gws fVqPoD0S5IpuZ21TOipAFJatOtHVhDFpvlMpr//fmokIXyzJnGmxL6OVYkKsRrcS FriVwFvB207owm2hJLctFi8F3EshD4lmGfkmfTui0svPu2+cZ7HLLf7b6T2iZ0tM fNjPdENWM1qJUEp1ivpPYSoU3VOsuGIpvOo6C+njul3DQonX00KimwD7xI9Eirj7 Uc8CYRTLRmobykruWpZavyoK3T1gwMMxt04CB4k+7p8tbXYF9dhDx4KpjXivTF9o sjvV9oN+5BlfCQIKMpMRtG5eLmJyMAlYY2W9hcWCGnbJkBLoKFdtCc51Bvnj2SDk 4HxXTmGPAdoyNEnuL5FIByJ2PkO/ydHsB+mBB43IKhHEKeyb68jzQH/QViGjqM6G OyZk0mu+gcRLbsHmSpOGjt8RrtmF+HGz2BJLJPfxCLPMohcbjkxj3t04pN9yjfz+ YS+BuscjpmgInKdwgLmbOv6VGtqtoqRucirEraG7UWIdALgb6LjGNc4PGfFeDB2u 6MaCZAbPQNRtTY4iXpJnmRGuSB18uliVcLCU5NtScr3j4r/jfHu8p4+yitrQoWgV pSAUvskN+PIY65N+rfrklR/LexO6I8oMHejheVgWwBjUPd4GscI= =5jjw -----END PGP SIGNATURE----- --FUkEYrCLnLL9itaa--