pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chao Li <li.evan.chao@gmail.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Rahila Syed <rahilasyed90@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: show size of DSAs and dshash tables in pg_dsm_registry_allocations
Date: Tue, 2 Dec 2025 05:35:34 +0800
Message-ID: <E4CEC5F7-BCCE-47D7-B206-48FD31F06F3C@gmail.com> (raw)
In-Reply-To: <aS20Z42rPHecTljS@nathan>
References: <aSeEDeznAsHR1_YF@nathan>
	<CAH2L28tr5q965MbD2TroyTc-Ey+b-z3=3kpWAuGg6w7qQwwChA@mail.gmail.com>
	<aS20Z42rPHecTljS@nathan>

Hi Nathan,

V2 overall looks good to me. I just got a question and a few nit comments.

> On Dec 1, 2025, at 23:29, Nathan Bossart <nathandbossart@gmail.com> wrote:
> 
> -- 
> nathan
> <v2-0001-rework-DSM-registry-view.patch>

1 - dsa.c
```
+size_t
+dsa_get_total_size_from_handle(dsa_handle handle)
+{
+	size_t		size;
+	bool		already_attached;
+	dsm_segment *segment;
+	dsa_area_control *control;
+
+	already_attached = dsa_is_attached(handle);
+	if (already_attached)
+		segment = dsm_find_mapping(handle);
+	else
+		segment = dsm_attach(handle);
+
+	if (segment == NULL)
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("could not attach to dynamic shared area")));
```

Why do you error out instead of reporting 0/NULL usage here? When users call this function as shown in the test script:
```
CREATE VIEW pg_dsm_registry_allocations AS
SELECT * FROM pg_get_dsm_registry_allocations();
```

User doesn’t pass in a handle, if the DSA has been released, it should treat a missing mapping as “no size available” and maybe return NULL. 


2
```
+		else if (entry->type == DSMR_ENTRY_TYPE_DSH &&
+				 entry->dsh.dsa_handle !=DSA_HANDLE_INVALID)
```

Missing a white space after !=.

3
```
-       Size of the allocation in bytes.  NULL for entries of type
-       <literal>area</literal> and <literal>hash</literal>.
+       Size of the allocation in bytes.  NULL for entries that failed
+       initialization.
```

“Failed initialization”, I guess “to” is needed after “failed”.

4
```
-SELECT name, type, size IS DISTINCT FROM 0 AS size
+SELECT name, type, size > 0 AS size
```

As you changed the third column from “size” to “size > 0”, now it’s a bool column, so maybe rename the column alias from “size” to something indicating a bool type, such as “size_ok”, “has_size”, etc.


Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









view thread (9+ messages)  latest in thread

Message-ID: <E4CEC5F7-BCCE-47D7-B206-48FD31F06F3C@gmail.com>
Permalink:  ../E4CEC5F7-BCCE-47D7-B206-48FD31F06F3C@gmail.com/
Also on:    postgresql.org/message-id/E4CEC5F7-BCCE-47D7-B206-48FD31F06F3C@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: li.evan.chao@gmail.com, nathandbossart@gmail.com, rahilasyed90@gmail.com, robertmhaas@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: show size of DSAs and dshash tables in pg_dsm_registry_allocations
  In-Reply-To: <E4CEC5F7-BCCE-47D7-B206-48FD31F06F3C@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox