Re: pg_stat_io_histogram - Mailing list pgsql-hackers

From Jakub Wartak
Subject Re: pg_stat_io_histogram
Date
Msg-id CAKZiRmws9w2-sunYM7eq30FF-t=LjQBy7WBQOh94Lxmn4zX21w@mail.gmail.com
Whole thread
In response to Re: pg_stat_io_histogram  (Jakub Wartak <jakub.wartak@enterprisedb.com>)
List pgsql-hackers
On Thu, Feb 5, 2026 at 1:13 PM Jakub Wartak
<jakub.wartak@enterprisedb.com> wrote:
>
> On Fri, Jan 30, 2026 at 2:43 PM Jakub Wartak
> <jakub.wartak@enterprisedb.com> wrote:
> [..]
> > I'm attaching v3 which has now default switched to __builtin_clzl() which
> > works ok for uint64 (not sure if I need to care about __builtin_clzll
> > on Windows?).
>
> Here comes the v4:
>
> 1. Rebased just in case.
> 2. Earlier appears to the uncomplete patch without local changes (comment
>    mentioned use of __builtin_clzl,  but actually code called
>    __builtin_clz -- 32-bit one not long one), fixed that with the new
>    version.
> 3. I've added discovery of __builtin_clzl into autoconf/meson as it was
>    missing (although comment there says "We assume that we needn't test
>    all widths of these explicitly:", but isn't it safer we test explicitly
>    what we use?
> 4. And then I've spotted that pg_leftmost_one_pos64() in pg_binutils.h uses on
>    master the __builtin_clzl already, so I've tweaked it to use check
>    HAVE__BUILTIN_CLZL (not CLZ) too once we have that now.
>
> Open questions:
> 0. Should I pursue more benchmarking or the above results are enough?
> 1. Should I add per-PID backend stats too or skip that to avoid causing
>    potential further overhead? (probably yet another memcpy...)
> 2. Shouldn't we fix that mdsyncfiletag() mentioned earlier we seem to have
>    pgstat_count_io_op_time() *after* potential FileClose() (as per my
>    earlier question)

Hi all,

I would be grateful for any feedback. Here comes v5 attached with:
1. finish documentation for I/O operation types (io_type column) and s/hit?/hit/
2. fix documentation typos, references, copy paste errors..
3. fix code comments typos
4. added missing return for pg_leading_zero_bits64() in case of lack
of HAVE__BUILTIN_CLZL
    (discovered thanks to clang's -Wreturn-type)

There are still two implementations inside for get_bucket_index()
I think we should stick to the clz one as it appears to be faster.
Above questions since v4 remain.

-J.

Attachment

pgsql-hackers by date:

Previous
From: Aditya Kamath
Date:
Subject: RE: Decoupling our alignment assumptions about int64 and double
Next
From: Bertrand Drouvot
Date:
Subject: Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)