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 1ttN4k-00BZZ3-Ob for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Mar 2025 08:40:58 +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 1ttN4g-009erV-U1 for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Mar 2025 08:40:54 +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 1ttN4g-009eoA-H6 for pgsql-hackers@lists.postgresql.org; Sat, 15 Mar 2025 08:40:54 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ttN4c-002z1H-3D for pgsql-hackers@postgresql.org; Sat, 15 Mar 2025 08:40:54 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5e60cfef9cfso4146448a12.2 for ; Sat, 15 Mar 2025 01:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742028050; x=1742632850; darn=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=AFVo9CwhgXJzAAvuiVf7uyP87623rhyDiIcI6TgI0iw=; b=hoVCmH/0OwxJuuGsCZ1zy6IjziRZNrgd9nJxNOKtjQJy0bQjgpkuLKCmLFa1HLHhH6 tfw5MPH0fJQkuxa1xKS1t24SUfvwvdaM3tNri1Hh/h+mVLR6THd3ueq21erO1FjNo5hC onjjuN4korY5OzmmbgWtTMGfgO9GwehHvBhehvqYYbfoQE9/BmC8zq/cvm+LAqyMArK1 YJZlWh8bSZsr3ifxWTFb0upAG6Vxy6+YtwMlSfH6QCi2RotFt5cCy7D0pe8d2KGjfokd RUXQX0VVZhMN627+2wFbf/KKjE4AaGQeOXOrp2PqHixMZ9N5CYlKs83znvTKKfl0eCnx mtnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742028050; x=1742632850; 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=AFVo9CwhgXJzAAvuiVf7uyP87623rhyDiIcI6TgI0iw=; b=ho5Betz5X2Q99Jsy4knX1QcLdEuYL/AMjegNWsUumslqR3sLjVMeMMJNwy14CHOohP vC6rWlGdX0kjJce3M1YASBJhpOr0qPm2D3fppgd4PB4PQN8pn8eYLSUm7SDoAMWPWekZ hrSWIyPcupOTOhQXUy0BgARBSi9z2VrsARVS4dx+cGwQiB0Wuk61duE+DJZanx3rBkOi lkfdXn85/LfzPJS2qhX2cOW/HsUVuXQbjT8NHM8i0r4WR9BIFLpgqeTMA2vLLnX+1dnt iFw9zO4sufqP37iMU76TASIFKD5c/xEuzuIM6E7lY3Y38H0S0TIJT+Sv1W7IzdUQe6kL xLwg== X-Forwarded-Encrypted: i=1; AJvYcCVXnODDdauz9dzZFn3D9wIg5xAlEryWCWBc/T9zHfQGlk75zrzkqV32Z4Ez9YyFy66HxdDwcbAyhlkMIfgK@postgresql.org X-Gm-Message-State: AOJu0YwhWuSqrs3cF/bZm0oW9OOfPFm7zpok4zt4RoVc8TPrGKG3TyUe hDg+PQvqTXRb0YOFypkXwo7KO/GOZDTd97T8aWY8avQ+N450AeodmE+5P+RZsRSpWx331XQ5kc1 3/fRJyvk26xEHmZNIGVfUVzTV4HM= X-Gm-Gg: ASbGncsnebBsG9jKSgEkP+hEPZGZ//6gZYQ8W++wQhLB8Uaaakn6gCkABZx+4lARKJI WMbwSml/L0sjNfqkohwGNRWM9y+hG9+PNl/0Syqp0JXxWIvLJCKhmbx5+MkDTCK5gCxJgAmCgxK p0swA8yhKVIPPV0M+Xtb3B9xzGCw== X-Google-Smtp-Source: AGHT+IEPeJapUPfL0HamjZTcc3RwNLBuuUbcr6R9l8+44ZzsLdO5tpmGW7cDO+q4eZsqzkUp6QahmzRvwhEblLJntUo= X-Received: by 2002:aa7:c38b:0:b0:5e8:bced:9ee5 with SMTP id 4fb4d7f45d1cf-5e8bcedb072mr3608540a12.18.1742028050059; Sat, 15 Mar 2025 01:40:50 -0700 (PDT) MIME-Version: 1.0 References: <7d4db5cf-8d72-4ee1-8f2e-f88ef9615f27@vondra.me> <637b3ae3-b9eb-4d83-a942-5f7483911ea4@vondra.me> <29ced66e28ec696d1ac29747bd901df2@oss.nttdata.com> <5a899047-65fc-47c5-9c35-1035f44956c6@vondra.me> <70146bd0-da0f-48ee-bece-1e35536189e0@oss.nttdata.com> <2eb8fd76-89f0-42e8-bc79-152d50c63016@vondra.me> <81607c8c04a21b5cac87b21e46566074@oss.nttdata.com> <4c2b5401-41ad-43b9-9215-c7b2d901f8ed@vondra.me> <84996B31-C278-4373-8F56-C5A38A4530BA@yesql.se> In-Reply-To: From: Alexander Korotkov Date: Sat, 15 Mar 2025 10:40:39 +0200 X-Gm-Features: AQ5f1JriCXBgVGykYQL3yWt8cpDV60URgkD03Dzs9APyiX7zX2lOTV-LB-A6lHc Message-ID: Subject: Re: Enhancing Memory Context Statistics Reporting To: Rahila Syed Cc: Daniel Gustafsson , Tomas Vondra , PostgreSQL Hackers 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 Hi, Rahila! On Thu, Mar 13, 2025 at 3:57=E2=80=AFPM Rahila Syed wrote: > > Please find attached updated and rebased patches. It has the following ch= anges > > 1. To prevent memory leaks, ensure that the latest statistics published b= y a process > are freed before it exits. This can be achieved by calling dsa_free in th= e > before_shmem_exit callback. > 2. Add a level column to maintain consistency with the output of > pg_backend_memory_contexts. Thank you for your work on this subject. v17-0001-Preparatory-changes-for-reporting-memory-context-sta.patch It looks like we're increasing *num_contexts twice per child memory context. First, it gets increased with a recursive MemoryContextStatsInternal() call, then by adding an ichild. I might be wrong, but I think these calculations at least deserve more comments. v17-0002-Function-to-report-memory-context-statistics.patch + if (procNumber =3D=3D MyProcNumber) + { + ereport(WARNING, + errmsg("cannot return statistics for local backend"), + errhint("Use pg_backend_memory_contexts view instead.")); + PG_RETURN_NULL(); + } Is it worth it to keep this restriction? Can we fetch info about local memory context for the sake of generality? I know there have been discussions in the thread before, but the mechanism of publishing memory context stats via DSA looks quite complicated. Also, the user probably intends to inspect memory contexts when there is not a huge amount of free memory. So, failure is probable on DSA allocation. Could we do simpler? For instance, allocate some amount of static shared memory and use it as a message queue between processes. As a heavy load is not supposed to be here, I think one queue would be enough. ------ Regards, Alexander Korotkov Supabase