public inbox for [email protected]  
help / color / mirror / Atom feed
From: Sami Imseih <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: Return DSA area for hash table from GetNamedDSHash()
Date: Mon, 6 Apr 2026 17:56:21 -0500
Message-ID: <CAA5RZ0tKfCVqFnMZtavM42H63ha2Haf_C4mbJNWqkaW30cPW1w@mail.gmail.com> (raw)

Hi,

While working on extending tests for dshash.c [1], I realized that a
user that creates a hash table with GetNamedDSHash() has no way
to cap the size of the dsa area underpinning the table by using
dsa_set_size_limit(). This is because the dsa_area created using
this API is not exposed to the user.

This is a gap for users of the GetNamedDSHash() API,
because it's very likely that the callers don't want runaway growth of
these hash tables.

Attached is a new API, dshash_get_dsa_area() that takes in a dshash_table
and returns the area. The caller can then use dsa_set_size_limit() to limit
the size.

We could change the GetNamedDSHash() API to take in a size, but that
will not be ideal since a caller may want to change the size dynamically after
the hash table is created.

I don't have a patch for this yet, but I also think it will make sense for
pg_dsm_registry_allocations to also show the max_size

postgres=# select * from pg_dsm_registry_allocations;
          name          |  type   |  size
------------------------+---------+---------
 test_dsm_registry_dsa  | area    | 1048576
 test_dsm_registry_hash | hash    | 1048576
 test_dsm_registry_dsm  | segment |      20
(3 rows)

Thoughts?


[1] [https://www.postgresql.org/message-id/acXCJODjsCytdpwT%40paquier.xyz]

--
Sami Imseih
Amazon Web Services (AWS)


Attachments:

  [application/octet-stream] v1-0001-Add-function-to-return-DSA-area-for-a-dshash-tabl.patch (1.6K, 2-v1-0001-Add-function-to-return-DSA-area-for-a-dshash-tabl.patch)
  download | inline diff:
From b2f69377435fe170b1321e55d0c3141ebe8a2efc Mon Sep 17 00:00:00 2001
From: Sami Imseih <[email protected]>
Date: Mon, 6 Apr 2026 21:50:24 +0000
Subject: [PATCH v1 1/1] Add function to return DSA area for a dshash table

A caller using GetNamedDSHash() to retrieve a dshash table may also
want to limit its size. Add dshash_get_dsa_area(), which returns the
dsa_area for a given dshash_table, allowing callers to pass it to
dsa_set_size_limit().
---
 src/backend/lib/dshash.c | 11 +++++++++++
 src/include/lib/dshash.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/src/backend/lib/dshash.c b/src/backend/lib/dshash.c
index 1999989c14f..62ac68d4add 100644
--- a/src/backend/lib/dshash.c
+++ b/src/backend/lib/dshash.c
@@ -363,6 +363,17 @@ dshash_destroy(dshash_table *hash_table)
 	pfree(hash_table);
 }
 
+/*
+ * Get the DSA area used by this hash table.
+ */
+dsa_area *
+dshash_get_dsa_area(dshash_table *hash_table)
+{
+	Assert(hash_table->control->magic == DSHASH_MAGIC);
+
+	return hash_table->area;
+}
+
 /*
  * Get a handle that can be used by other processes to attach to this hash
  * table.
diff --git a/src/include/lib/dshash.h b/src/include/lib/dshash.h
index 64b758b381b..b868084df04 100644
--- a/src/include/lib/dshash.h
+++ b/src/include/lib/dshash.h
@@ -89,6 +89,7 @@ extern dshash_table *dshash_attach(dsa_area *area,
 								   dshash_table_handle handle,
 								   void *arg);
 extern void dshash_detach(dshash_table *hash_table);
+extern dsa_area *dshash_get_dsa_area(dshash_table *hash_table);
 extern dshash_table_handle dshash_get_hash_table_handle(dshash_table *hash_table);
 extern void dshash_destroy(dshash_table *hash_table);
 
-- 
2.50.1



view thread (4+ messages)  latest in thread

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: [email protected]
  Cc: [email protected]
  Subject: Re: Return DSA area for hash table from GetNamedDSHash()
  In-Reply-To: <CAA5RZ0tKfCVqFnMZtavM42H63ha2Haf_C4mbJNWqkaW30cPW1w@mail.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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox