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 1oTQOd-0000jI-Fj for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Aug 2022 16:16:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oTQOc-0003NX-7S for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Aug 2022 16:16:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTQLZ-0006wp-97 for pgsql-hackers@lists.postgresql.org; Wed, 31 Aug 2022 16:13:45 +0000 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oTQLS-0006iy-Mo for pgsql-hackers@lists.postgresql.org; Wed, 31 Aug 2022 16:13:44 +0000 Received: by mail-qk1-x72b.google.com with SMTP id f4so11175571qkl.7 for ; Wed, 31 Aug 2022 09:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crunchydata.com; s=google; h=user-agent:mime-version:date:organization:cc:to:reply-to:from :subject:message-id:from:to:cc; bh=p5CDvd659qEdw8yFN0JOGDO1N5ulakrRlgeTRalQ+4A=; b=HcgtJV3nXf3/KOzehlif5nQ0mrUK3Aq2+uUSnCawn8JtRERJuq5Eo/rhi7Sy5awqoY 9btqZR7TwkOFqC6YNcZA9c7kEuSK+VGyVkuYEFAi94K0zKs9ee9Aph/C1BS8zTrgkrUX 2oUOVv3gaWHL4mHpHvBSNB4jW4MexJ6hQ6/EQjJThTmfk+6A0EMHiZNy0EHGWkz1MwfR NQlizKRZjth/kMX6JAuuOwBUUqHpQkM8p3jdoX3kOZhK4rAjBxiz9rLQdX9O61A3K1r5 gPs5/KNvaDqXQUYJ5nnLnTE7uYMifkUqFJwxuVDs4OFHbAHw/W/C7wRd0axdK2MT+Jwp 5i7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:mime-version:date:organization:cc:to:reply-to:from :subject:message-id:x-gm-message-state:from:to:cc; bh=p5CDvd659qEdw8yFN0JOGDO1N5ulakrRlgeTRalQ+4A=; b=t9sdWKZJXugd5tdm9nwlRQBIFMwAxaM9vZGduPPdth70Dt7JxITVZF4kRIvm+fbXNl 3HaZTkKBfud8Cyw11eVd8MU09+Katg64vkGk58b3JznZ1iCPw7MWvfgKZCuRpLa+bnlm 7/wjSYoZaz3tm0uqcs3UNWIotweC0N2YM4UKE7dUwlb1hliD585Qc6fcBTmuUBNm7xdW GhmtACvI1DI9uMv5haXBD7BVXXabVUQc27A4NljbJoDf9kqQ4+4TRGN0QMzW4zshl3vf wO9h5uBWHZh3RxIpDEqXdjyYgmUnMXQs7nBuOJZGCagR0O6UK6AJzcK5hro6agukWSKL LLMA== X-Gm-Message-State: ACgBeo3T2GEPxBRPSUmolEIJSWRc4ED/+m+ZrFXdCbdz747FQ8LkD2Up VK5ogzkJkbWTF0EzEUOdx9MGJ7NWU5hQ0Q== X-Google-Smtp-Source: AA6agR7yee8IbASYpFIeHuCmolcmewcOsPKB14E9DEMz622V2t6mr7p2BVlxuat6qYYt15Z/xnyr5g== X-Received: by 2002:a05:620a:4147:b0:6bb:86e5:e4e5 with SMTP id k7-20020a05620a414700b006bb86e5e4e5mr16281068qko.334.1661962417406; Wed, 31 Aug 2022 09:13:37 -0700 (PDT) Received: from raker.lan ([98.97.181.172]) by smtp.gmail.com with ESMTPSA id z129-20020a37b087000000b006b9b7879964sm9706154qke.28.2022.08.31.09.13.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 09:13:37 -0700 (PDT) Message-ID: <972a4e12b68b0f96db514777a150ceef7dcd2e0f.camel@crunchydata.com> Subject: Bug fix. autovacuum.c do_worker_start() associates memory allocations with TopMemoryContext rather than 'Autovacuum start worker (tmp)' From: Reid Thompson Reply-To: reid.thompson@crunchydata.com To: pgsql-hackers Cc: reid.thompson@crunchydata.com Organization: Crunchy Data Content-Type: multipart/mixed; boundary="=-HnR0nty7RQVHZi+LJz3l" Date: Wed, 31 Aug 2022 12:10:26 -0400 MIME-Version: 1.0 User-Agent: Evolution 3.45.1 Compiled: 2022-06-07 10:22:05 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-HnR0nty7RQVHZi+LJz3l Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Hackers, This patch ensures get_database_list() switches back to the memory context in use upon entry rather than returning with TopMemoryContext as the context. This will address memory allocations in autovacuum.c being associated with TopMemoryContext when they should not be. autovacuum.c do_start_worker() with current context 'Autovacuum start worker (tmp)' invokes get_database_list(). Upon return, the current context has been changed to TopMemoryContext by AtCommit_Memory() as part of an internal transaction. Further down in the do_start_worker(), pgstat_fetch_stat_dbentry() is invoked. Previously this didn't pose a issue, however recent changes altered how pgstat_fetch_stat_dbentry() is implemented. The new implementation has a branch utilizing palloc. The patch ensures these allocations are associated with the 'Autovacuum start worker (tmp)' context rather than the TopMemoryContext. Prior to the change, leaving an idle laptop PG instance running just shy of 3 days saw the autovacuum launcher process grow to 42MB with most of that growth in TopMemoryContext due to the palloc allocations issued with autovacuum worker startup. --=20 Reid Thompson Senior Software Engineer Crunchy Data, Inc. reid.thompson@crunchydata.com www.crunchydata.com --=20 Reid Thompson Senior Software Engineer Crunchy Data, Inc. reid.thompson@crunchydata.com www.crunchydata.com --=-HnR0nty7RQVHZi+LJz3l Content-Disposition: attachment; filename="001-dev-get-dblist-memorycontext.patch" Content-Type: text/x-patch; name="001-dev-get-dblist-memorycontext.patch"; charset="UTF-8" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3Bvc3RtYXN0ZXIvYXV0b3ZhY3V1bS5jIGIvc3JjL2Jh Y2tlbmQvcG9zdG1hc3Rlci9hdXRvdmFjdXVtLmMKaW5kZXggYjNiMWFmYmE4Ni4uOTJiMWVmNDVj MSAxMDA2NDQKLS0tIGEvc3JjL2JhY2tlbmQvcG9zdG1hc3Rlci9hdXRvdmFjdXVtLmMKKysrIGIv c3JjL2JhY2tlbmQvcG9zdG1hc3Rlci9hdXRvdmFjdXVtLmMKQEAgLTE5NDEsNiArMTk0MSwxMyBA QCBnZXRfZGF0YWJhc2VfbGlzdCh2b2lkKQogCiAJQ29tbWl0VHJhbnNhY3Rpb25Db21tYW5kKCk7 CiAKKwkvKgorCSAqIENvbW1pdFRyYW5zYWN0aW9uQ29tbWFuZCByZXR1cm5zIHdpdGggQ3VycmVu dE1lbW9yeUNvbnRleHQgc2V0CisJICogdG8gVG9wTWVtb3J5Q29udGV4dC4gU3dpdGNoIGJhY2sg dG8gdGhlIGNvbnRleHQgdGhhdCB3ZSBlbnRlcmVkCisJICogd2l0aC4KKwkgKi8KKwlNZW1vcnlD b250ZXh0U3dpdGNoVG8ocmVzdWx0Y3h0KTsKKwogCXJldHVybiBkYmxpc3Q7CiB9CiAK --=-HnR0nty7RQVHZi+LJz3l--