From: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> |
---|---|
To: | Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org> |
Cc: | Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Daniel Gustafsson <daniel(at)yesql(dot)se>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Support getrandom() for pg_strong_random() source |
Date: | 2025-08-14 22:11:28 |
Message-ID: | CAD21AoD1+6FwGb0d4W3YEwOVJi_McuyuvpnjUJE8B8Ejy21MMw@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Jul 29, 2025 at 9:38 AM Dagfinn Ilmari Mannsåker
<ilmari(at)ilmari(dot)org> wrote:
>
> Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com> writes:
>
> > On Mon, Jul 28, 2025 at 6:30 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> >
> >> Could getentropy() be more efficient at the end on most platforms,
> >> meaning that this could limit the meaning of having a GUC switch?
> >
> > I don't know. [2] implies that the performance comparison depends on
> > several factors, and falls in favor of OpenSSL when the number of
> > bytes per call is large
> [...]
> > [2] https://dotat.at/@/2024-10-01-getentropy.html
>
> Note that that test was done on an older Linux kernel without the vDSO
> implementation of getentropy(), so on newer kernel (>=6.11) and glibc
> (>= 2.41) versions the difference might be smaller or the other way
> around.
FYI I've benchmarked vDSO implementation of getrandom() with Fedora 42
(kernel 6.15, glibc 2.41). I've modified the test program linked by
the blog post[1] so that it measures vDSO implementation of
getrandom() and directly calling getrandom system call. I've attached
the test program. Here is the result:
$ ./bench
init openssl 1929533
len entropy openssl vgetrandom getrandom
16 353 400 39 235
64 373 401 125 368
256 675 420 432 664
1024 2651 494 1352 1792
The 'vgetrandom' column shows nanoseconds per function call of vDSO
implementation of getrandom() function whereas the 'getrandom' column
shows nanoseconds per getrandom system call.
For smaller bytes, vgetrandom (i.e., simply calling the getrandom()
function) is much faster than other methods. For larger bytes (such
1024), openssl had the best performance. This fact is very attractive
to me in terms of using it for UUID generation.
Regards,
[1] https://dotat.at/@/2024-10-01-getentropy.html
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
Attachment | Content-Type | Size |
---|---|---|
bench.c | application/octet-stream | 2.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Burd | 2025-08-14 22:12:08 | Re: [PATCH] bms_prev_member() can read beyond the end of the array of allocated words |
Previous Message | Peter Geoghegan | 2025-08-14 21:55:53 | Re: index prefetching |