pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Anton A. Melnikov <a.melnikov@postgrespro.ru>
To: John Naylor <johncnaylorls@gmail.com>
Cc: Jeff Davis <pgsql@j-davis.com>
Cc: Ants Aasma <ants.aasma@cybertec.at>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Junwang Zhao <zhjwpku@gmail.com>
Cc: jian he <jian.universality@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Gurjeet Singh <gurjeet@singh.im>
Cc: pgsql-hackers@postgresql.org
Subject: Re: Change GUC hashtable to use simplehash?
Date: Thu, 16 Jan 2025 04:15:31 +0300
Message-ID: <0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru> (raw)
In-Reply-To: <CANWCAZZjUtfq148s=55L1LKHu+imeKn=iFH5UvgtxRZcCK9fbg@mail.gmail.com>
References: <c95e1821b6a69ec0c40eb0252e037b68a62cdae3.camel@j-davis.com>
	<09924cd6c49935d5e9bba5cd40bec28c605d7c2e.camel@j-davis.com>
	<CANWCAZZY+kZpMQh4OCJ1jrQigh_oCDWrbzWWOPTmJKj+0enR3A@mail.gmail.com>
	<48e8f8bbe0be9c789f98776c7438244ab7a7cc63.camel@j-davis.com>
	<CANwKhkP7pCiW_5fAswLhs71-JKGEz1c1+PC0a_w1fwY4iGMqUA@mail.gmail.com>
	<CANWCAZbXooNxa1oX4+N-QVTknRiiUBs17ai8rcWYihs_g=ShEQ@mail.gmail.com>
	<CANWCAZbg_XeSeY0a_PqWmWqeRATvzTzUNYRLeT+bzs+YQdC92g@mail.gmail.com>
	<CANWCAZbwvp7oUEkbw-xP4L0_S_WNKq-J-ucP4RCNDPJnrakUPw@mail.gmail.com>
	<458350a908d9607f7fc2a15407f4405cc454c970.camel@j-davis.com>
	<CANWCAZYxrJJ4EDw=o5vu_gAs7dS_PK6ry0rqkVu9opGpAJjoQQ@mail.gmail.com>
	<2b0df3af97fac73a40aba16a58837e2cee594b1f.camel@j-davis.com>
	<CANWCAZYLvWOm-1XLT8wGoXGgNBEV_NPMWJY4gM6cXa7LHVDjtw@mail.gmail.com>
	<a3a959f6-14b8-4819-ac04-eaf2aa2e868d@postgrespro.ru>
	<CANWCAZZ0ptKxEyO504OjZOr3Co=WaSEQG5eUU-TFmqD4twhe_w@mail.gmail.com>
	<CANWCAZZjUtfq148s=55L1LKHu+imeKn=iFH5UvgtxRZcCK9fbg@mail.gmail.com>

Hi, John!

On 19.12.2024 12:48, John Naylor wrote:
> That would actually be a maintenance headache because the function is
> inlined, but here's a better idea: We already have a fallback path for
> when the string is not suitably aligned, or in 32-bit builds. We could
> just use that under Valgrind:
> 
>   static inline size_t
>   fasthash_accum_cstring(fasthash_state *hs, const char *str)
>   {
> -#if SIZEOF_VOID_P >= 8
> +#if SIZEOF_VOID_P >= 8 && !defined(USE_VALGRIND)
> 
> Any objections?

This variant doesn't produce error and helped me to move
further beyond initdb in the some tests under valgrind
and fix a number of bugs.
Thank you very much!

Seems it is possible to exclude much less code from checking
under valgrind and get the same result by replacing the only
function call pg_rightmost_one_pos64() with a valgrind-safe
code. See the attached patch, please.

The pg_rightmost_one_pos64() itself can also be valgrind-safe
in some cases when the last version of its code works.
But i'm not sure if it's worth writing extra preprocessor instructions
to make this small piece of code also checkable under valgrind.
So in the patch i made a simple variant without it.

With the best wishes,

-- 
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

v1-0001-Add-valgrind-safe-code-to-find-rightmost-bytes.patch (text/x-patch, 1.3K) download From 7af05703e59fb8f1e51ec1d667ddc150c40756f0 Mon Sep 17 00:00:00 2001 From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru> Date: Thu, 16 Jan 2025 02:56:52 +0300 Subject: [PATCH] Add valgrind-safe code to find a number of rightmost zero bytes. --- src/include/common/hashfn_unstable.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h index a09c0b7d5ce..7674c39b1ca 100644 --- a/src/include/common/hashfn_unstable.h +++ b/src/include/common/hashfn_unstable.h @@ -302,13 +302,22 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str) size_t remainder; uint64 mask; +#if !defined(USE_VALGRIND) /* * The byte corresponding to the NUL will be 0x80, so the rightmost * bit position will be in the range 15, 23, ..., 63. Turn this into * byte position by dividing by 8. */ remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE; - +#else + /* valgrind-safe variant */ + remainder = 0; + while ((zero_byte_low & 0xFF) == 0) + { + zero_byte_low >>= 8; + ++remainder; + } +#endif /* * Create a mask for the remaining bytes so we can combine them into * the hash. This must have the same result as mixing the remaining -- 2.48.1

view thread (103+ messages)  latest in thread

Message-ID: <0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru>
Permalink:  ../0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru/
Also on:    postgresql.org/message-id/0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru

 ·  · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: a.melnikov@postgrespro.ru, johncnaylorls@gmail.com, pgsql@j-davis.com, ants.aasma@cybertec.at, hlinnaka@iki.fi, zhjwpku@gmail.com, jian.universality@gmail.com, andres@anarazel.de, tgl@sss.pgh.pa.us, gurjeet@singh.im
  Subject: Re: Change GUC hashtable to use simplehash?
  In-Reply-To: <0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru>
  References: <c95e1821b6a69ec0c40eb0252e037b68a62cdae3.camel@j-davis.com> <CANWCAZZY+kZpMQh4OCJ1jrQigh_oCDWrbzWWOPTmJKj+0enR3A@mail.gmail.com> <48e8f8bbe0be9c789f98776c7438244ab7a7cc63.camel@j-davis.com> <CANwKhkP7pCiW_5fAswLhs71-JKGEz1c1+PC0a_w1fwY4iGMqUA@mail.gmail.com> <CANWCAZbXooNxa1oX4+N-QVTknRiiUBs17ai8rcWYihs_g=ShEQ@mail.gmail.com> <CANWCAZbg_XeSeY0a_PqWmWqeRATvzTzUNYRLeT+bzs+YQdC92g@mail.gmail.com> <CANWCAZbwvp7oUEkbw-xP4L0_S_WNKq-J-ucP4RCNDPJnrakUPw@mail.gmail.com> <458350a908d9607f7fc2a15407f4405cc454c970.camel@j-davis.com> <CANWCAZYxrJJ4EDw=o5vu_gAs7dS_PK6ry0rqkVu9opGpAJjoQQ@mail.gmail.com> <2b0df3af97fac73a40aba16a58837e2cee594b1f.camel@j-davis.com> <CANWCAZYLvWOm-1XLT8wGoXGgNBEV_NPMWJY4gM6cXa7LHVDjtw@mail.gmail.com> <a3a959f6-14b8-4819-ac04-eaf2aa2e868d@postgrespro.ru> <CANWCAZZ0ptKxEyO504OjZOr3Co=WaSEQG5eUU-TFmqD4twhe_w@mail.gmail.com> <CANWCAZZjUtfq148s=55L1LKHu+imeKn=iFH5UvgtxRZcCK9fbg@mail.gmail.com> <0647027b-9c9a-4f16-8f7c-3f9f3eb9451e@postgrespro.ru>

* 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