Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSsY1-0003zK-Km for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Feb 2023 04:40:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSsXz-0000C9-Fe for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Feb 2023 04:40:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSsXz-0000Bv-2n for pgsql-hackers@lists.postgresql.org; Fri, 17 Feb 2023 04:40:35 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pSsXv-0000xe-T8 for pgsql-hackers@lists.postgresql.org; Fri, 17 Feb 2023 04:40:34 +0000 Received: by mail-pf1-x433.google.com with SMTP id bt14so2760681pfb.13 for ; Thu, 16 Feb 2023 20:40:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1676608829; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MY/mHPAzPd/gtEZRrULomk3fYCglCUTSbXG9Mt6bpR0=; b=dvP9JxvDDBeIfxym6b+X167r00HWtJf1zITPDTfJRrVpMNZfhGyistLSkts4Ithg+/ QqGmYS/WVW7gj95oD9jrlc42Iw6aVoefiRHaq8SihZOdy4rYMzivG0kGJzL6ttx9dt6S GZLttU1nrlqk0Tt/UbMLIKuB2A8cotChRcsFTLZdbWHFhgixuC0iRPTCUFOwQ4qKJOoc RpH/4bvD7O6mQMnyVX0ymgpcf5Nko1B8+WwsDEr3DJnYXqfOC5UeapxWkf20FGV4ngq9 xZ48WSSncwy5NMFHqWvXCpZwsl/WupoBwTJh9xw9NXcBrpgAr98IEU1/HRn9eRsQXrg/ af1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676608829; h=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=MY/mHPAzPd/gtEZRrULomk3fYCglCUTSbXG9Mt6bpR0=; b=YCI9pP26iz4vae7xtIk/lMJNegxF5xoQiZ4Xkd4jaDqfIjygoh3GQdSioqdLaC+CDE R25nCrCgcZUmdBZlTGFN+jKc+j6aRi5qigEeZI9caAYKHHR4hgygzQ2SL8hHW/j3i2t4 4piheE0/ufmRQ1FU7/OPpuimytvjdxS49EYWGymi8QR0Q2z0S35/LdtTdNFHo/0gUN3u tyOXKxehq8nOoJqSWJXCGUJiJfr0vWhLCIjy+1Naqj47p2nOx5KRQoUJSrGnov1GFuCF EOxZaAK6IALstRawBmhbnDwX1/c8+Q0tCXV+dAsXwvhnCJwQmntrpRPOfYV74FN+oxrJ ZxTA== X-Gm-Message-State: AO0yUKWaH/wDqaMyCQmDCZR2NGe6z9gZlyYfhs/LQl3jkk89RPgxPwPR PSgY5vVrvuLZZIsL610cM5sqGhGGbTLgBj9KAS8= X-Google-Smtp-Source: AK7set8WCUkTvbEf6c2THU/kN5HDCahEa6Ilp/HIqpVeXL8sssFgSa6yfsrrk2/qD4StPj8d7238tO5e+BQyWey4ee4= X-Received: by 2002:a62:87cf:0:b0:5a9:c4fc:e3d7 with SMTP id i198-20020a6287cf000000b005a9c4fce3d7mr358166pfe.17.1676608829364; Thu, 16 Feb 2023 20:40:29 -0800 (PST) MIME-Version: 1.0 References: <20230217003204.cx5zu2aocjbwz5ns@awork3.anarazel.de> <20230217034000.ddcklsr6hfdifyqk@awork3.anarazel.de> In-Reply-To: From: "Jonah H. Harris" Date: Thu, 16 Feb 2023 23:40:18 -0500 Message-ID: Subject: Re: Reducing System Allocator Thrashing of ExecutorState to Alleviate FDW-related Performance Degradations To: David Rowley Cc: Andres Freund , PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000b39d8105f4dde9ca" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b39d8105f4dde9ca Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 16, 2023 at 11:26 PM David Rowley wrote: > I didn't hear it mentioned explicitly here, but I suspect it's faster > when increasing the initial size due to the memory context caching > code that reuses aset MemoryContexts (see context_freelists[] in > aset.c). Since we reset the context before caching it, then it'll > remain fast when we can reuse a context, provided we don't need to do > a malloc for an additional block beyond the initial block that's kept > in the cache. This is what we were seeing. The larger initial size reduces/eliminates the multiple smaller blocks that are malloced and freed in each per-query execution. Maybe we should think of a more general-purpose way of doing this > caching which just keeps a global-to-the-process dclist of blocks > laying around. We could see if we have any free blocks both when > creating the context and also when we need to allocate another block. > I see no reason why this couldn't be shared among the other context > types rather than keeping this cache stuff specific to aset.c. slab.c > might need to be pickier if the size isn't exactly what it needs, but > generation.c should be able to make use of it the same as aset.c > could. I'm unsure what'd we'd need in the way of size classing for > this, but I suspect we'd need to pay attention to that rather than do > things like hand over 16MBs of memory to some context that only wants > a 1KB initial block. Yeah. There=E2=80=99s definitely a smarter and more reusable approach than = I was proposing. A lot of that code is fairly mature and I figured more people wouldn=E2=80=99t want to alter it in such ways - but I=E2=80=99m up for it = if an approach like this is the direction we=E2=80=99d want to go in. --=20 Jonah H. Harris --000000000000b39d8105f4dde9ca Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Feb 16, 2023 at 11:26 PM David Rowley <dgrowleyml@gmail.com> wrote:
I didn't hear it me= ntioned explicitly here, but I suspect it's faster
when increasing the initial size due to the memory context caching
code that reuses aset MemoryContexts (see context_freelists[] in
aset.c). Since we reset the context before caching it, then it'll
remain fast when we can reuse a context, provided we don't need to do a malloc for an additional block beyond the initial block that's kept in the cache.

Thi= s is what we were seeing. The larger initial size reduces/eliminates the mu= ltiple smaller blocks that are malloced and freed in each per-query executi= on.

Maybe we= should think of a more general-purpose way of doing this
caching which just keeps a global-to-the-process dclist of blocks
laying around.=C2=A0 We could see if we have any free blocks both when
creating the context and also when we need to allocate another block.
I see no reason why this couldn't be shared among the other context
types rather than keeping this cache stuff specific to aset.c.=C2=A0 slab.c=
might need to be pickier if the size isn't exactly what it needs, but generation.c should be able to make use of it the same as aset.c
could.=C2=A0 I'm unsure what'd we'd need in the way of size cla= ssing for
this, but I suspect we'd need to pay attention to that rather than do things like hand over 16MBs of memory to some context that only wants
a 1KB initial block.

Yeah. There=E2=80=99s definitely a smarter and more reusable approach t= han I was proposing. A lot of that code is fairly mature and I figured more= people wouldn=E2=80=99t want to alter it in such ways - but I=E2=80=99m up= for it if an approach like this is the direction we=E2=80=99d want to go i= n.



--
Jonah H. Harri= s

--000000000000b39d8105f4dde9ca--